pmsx003-rs
A no_std Rust driver for Plantower PMS X003 series air quality sensors, including PMS5003, PMS7003, and other compatible models.
Features
no_stdcompatible - Perfect for embedded systems- embedded-hal v1.0.0 - Uses the latest embedded HAL traits
- Zero dependencies - No external parsing libraries, uses built-in Rust byte manipulation
- Flexible serial interface - Supports both combined and separate TX/RX serial interfaces
- Comprehensive sensor control - Active/passive modes, sleep/wake, and data reading
- Robust parsing - Built-in checksum validation and error handling
- Multiple sensor support - Works with PMS5003, PMS7003, and other PMS X003 series sensors
Supported Sensors
This driver supports the Plantower PMS X003 series of air quality sensors:
- PMS5003 - Measures PM1.0, PM2.5, PM10 with particle counting
- PMS7003 - Similar to PMS5003 with additional features
- PMS3003 - Basic PM2.5 and PM10 measurements
- Other compatible PMS X003 series sensors
Usage
Add this to your Cargo.toml:
[]
= "1.0.0"
= "1.0.0"
= "1.0.0"
= "1.0.0"
Basic Example
use ;
use ;
// Create sensor with a combined serial interface
let mut sensor = new;
// Read air quality data
match sensor.read
Separate TX/RX Interface
// Create sensor with separate TX and RX interfaces
let mut sensor = new_tx_rx;
// Same usage as above
let frame = sensor.read?;
Sensor Control
// Put sensor in passive mode (request data manually)
sensor.passive?;
sensor.request?;
let frame = sensor.read?;
// Put sensor in active mode (continuous data)
sensor.active?;
loop
// Power management
sensor.sleep?; // Put sensor to sleep
sensor.wake?; // Wake up sensor
Data Structure
The OutputFrame struct contains all sensor measurements:
Error Handling
The driver provides comprehensive error handling:
use Error;
match sensor.read
Platform Examples
ESP32 with esp-hal
use ;
use PmsX003Sensor;
let io = new;
let uart = new_with_config?;
let mut sensor = new;
let frame = sensor.read?;
STM32 with stm32-hal
use ;
use PmsX003Sensor;
let dp = take.unwrap;
let gpioa = dp.GPIOA.split;
let rcc = dp.RCC.constrain;
let clocks = rcc.cfgr.freeze;
let tx = gpioa.pa2.into_alternate;
let rx = gpioa.pa3.into_alternate;
let serial = new?;
let mut sensor = new;
let frame = sensor.read?;
Wiring
Connect your PMS X003 sensor to your microcontroller:
| PMS X003 Pin | Function | MCU Pin |
|---|---|---|
| VCC | Power | 5V |
| GND | Ground | GND |
| TXD | Data out | RX |
| RXD | Data in | TX |
| SET | Sleep | GPIO (optional) |
| RESET | Reset | GPIO (optional) |
Note: The sensor's TXD connects to your MCU's RX, and sensor's RXD connects to your MCU's TX.
Communication Protocol
The driver handles the PMS X003 communication protocol automatically:
- Baud rate: 9600 bps
- Data format: 8N1 (8 data bits, no parity, 1 stop bit)
- Frame format: 32-byte data frames with checksum validation
- Commands: Sleep/wake, active/passive mode control
Migration from v0.x
If you're upgrading from an older version:
- Struct name changed:
Pms7003Sensor→PmsX003Sensor - embedded-hal version: Now requires embedded-hal v1.0.0
- Dependencies:
scrolldependency removed (zero external deps)
// Old (v0.x)
use Pms7003Sensor;
let sensor = new;
// New (v1.x)
use PmsX003Sensor;
let sensor = new;
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Plantower for creating the PMS X003 series sensors
- The embedded Rust community for the excellent embedded-hal ecosystem