Read the Plantower Particulate Matter (PM1, PM2.5, PM10) sensor with Python, source code is this repository: https://github.com/printfinn/PMSX003
- PMSA003
Should also work with other Plantower Particulate Matter like PMS5003, PMS7003 etc.
This project depends on pyserial.
from pmsx003 import PMSX003
import time
>>> sensor = PMSX003("/dev/ttyAMA0")
>>> sensor.go_wakeup() # Turn on fan and diode
>>> sensor.read_pm()
PM1: 2, PM2.5: 14, PM10: 14.
(2, 14, 14)
>>> sensor.go_passive() # Stop measuring PM
>>> time.sleep(10) # Allow time for sensor to measure data properly
>>> sensor.read_pm()
PM1: 4, PM2.5: 16, PM10: 16.
(4, 16, 16)
>>> sensor.go_active() # Keep measuring PM
>>> sensor.read_pm()
PM1: 3, PM2.5: 10, PM10: 12.
(3, 10, 12)
>>> sensor.go_sleep() # Turn off fan and diode
python3 pmsx003.py /dev/ttyAMA0 # use you own serial port here
# Waking up, going passive...
# Sleeping for 30 seconds to measure...
# PM1: 4, PM2.5: 10, PM10: 12.
# Going to sleep.
How the sensor works:
- On boot, the sensor wakes up and is in active mode, fan is running and keeps reporting data.
- When in sleep status, the fan stops running and the sensor doesn't report any data.
- You need to wake up the sensor to get data no matter in active or passive mode.
- In active mode, it can be swapped to passive mode or vice versa.
- In passive mode, the fan is running, but sensor doesn't report any data.
- In passive mode, a query_once_in_passive is required to generate one sensor data report.
- When turning into active mode, a 42 4D 00 04 E1 01 01 75 should be returned from the sensor.
- When turning into passive mode, a 42 4D 00 04 E1 00 01 74 should be returned from the sensor.
- When turning into sleep status, a 42 4D 00 04 E4 00 01 77 should be returned from the sensor.
- When turning into wake up status, nothing returns from sensor, it only keeps reporting 32 bytes data.
- [IMPORTANT] If there are sensor buffer that haven't been exausted before swapping to passive from active, you need to exaust the buffer first (read multiple times) to get the response (8 bytes) generated by turning mode. This only happens when the sensor is in active mode. Usually 3~5 reads can exaust the buffer (N x 32 bytes).
- I suggest using this sensor in passive mode.
In general, wake up the sensor first, then you can keep reading data and don't worry about other things.
But if you don't want the fan to rotate indefinitely, you should:
- Wake up.
- Go passive, get a success response (8 bytes).
- Wait 30 seconds, let the fan rotate, and wait PM data to stablize.
- Query once.
- Read once -> this is the data we want.
- Go sleep, get a success response (8 bytes).
MIT