MS4525DO Airspeed Sensor Driver
A platform-agnostic Rust driver for the MS4525DO differential pressure sensor, commonly used for airspeed measurement in drones, aircraft, and UAVs.
Features
- 🚀 Dual API: Both blocking and async implementations
- 🔌 Platform agnostic: Works on any platform with I2C support (
embedded-hal/embedded-hal-async) - 📦
no_stdcompatible: Perfect for embedded systems - 🧮 Zero dynamic allocation: All operations use stack memory
- ✅ Validated readings: Double-read validation ensures data freshness
- 📊 Built-in airspeed calculation: Convert pressure to airspeed
- 🔍 Flexible logging: Optional
defmtorlogsupport - 🛡️ Safe:
#![forbid(unsafe_code)]
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Feature Flags
async(default): Enable async API with embassy-timeblocking: Enable blocking/synchronous APIstd: Enable std support (for desktop/server environments)defmt: Enable defmt logging for embedded debugginglog: Enable log facade for flexible logging
Examples:
# Async only (default)
= "0.1.0"
# Blocking only
= { = "0.1.0", = false, = ["blocking"] }
# Both async and blocking
= { = "0.1.0", = ["blocking"] }
# With defmt logging
= { = "0.1.0", = ["defmt"] }
Quick Start
Blocking API
use Ms4525do;
use DelayNs;
// Create sensor instance
let mut sensor = new;
let mut delay = /* your delay implementation */;
// Read sensor data
match sensor.read_data
Async API (Embassy)
use Ms4525do;
use ;
// Create sensor instance
let mut sensor = new;
// Read sensor data
match sensor.read_data.await
Hardware Setup
Connections
The MS4525DO uses I2C communication:
| MS4525DO Pin | Connection |
|---|---|
| VCC | 3.3V or 5V |
| GND | Ground |
| SDA | I2C Data |
| SCL | I2C Clock |
Default I2C Address: 0x28
Recommended I2C Speed
- Standard mode: 100 kHz
- Fast mode: 400 kHz (recommended)
Sensor Specifications
- Measurement range: ±1 PSI (differential pressure)
- Pressure resolution: 14-bit
- Temperature resolution: 11-bit
- Operating temperature: -50°C to +150°C
- Update rate: Up to 50 Hz
- Interface: I2C (7-bit address: 0x28)
Examples
See the examples/ directory for complete examples:
std_mock_example.rs- Runnable on your computer! Mock I2C example with stdblocking_example.rs- Embedded blocking usage templateasync_embassy_example.rs- Embedded async with Embassy runtime
Try It Now!
Run the mock example on your computer (no hardware needed):
This demonstrates the full sensor workflow with simulated I2C data.
Reading at 50 Hz
use ;
loop
How It Works
Double-Read Validation
The driver implements a robust double-read validation strategy:
- Sends measurement request command
- Waits 2ms for fresh data (per datasheet)
- Reads two consecutive 4-byte packets
- Validates status progression:
NormalOperation→StaleData - Ensures pressure and temperature consistency between reads
This approach ensures you always get fresh, validated data from the sensor.
Airspeed Calculation
The calculate_airspeed() function uses the Bernoulli equation:
v = √(2 × ΔP / ρ)
Where:
v= airspeed (m/s)ΔP= differential pressure (Pa)ρ= air density (calculated from temperature)
Error Handling
The driver provides detailed error types:
Platform Examples
use I2c;
use Ms4525do;
let i2c = new;
let mut sensor = new;
use I2c;
use Ms4525do;
let i2c = new;
let mut sensor = new;
use I2C;
use Ms4525do;
let i2c = I2Ci2c0;
let mut sensor = new;
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
- Based on the PX4 airspeed driver implementation
- Datasheet: MS4525DO Digital Pressure Sensor