Skip to content

printfinn/PMSX003

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Read the Plantower PMSX003 Sensor

Read the Plantower Particulate Matter (PM1, PM2.5, PM10) sensor with Python, source code is this repository: https://github.com/printfinn/PMSX003

Tested Sensor

  • PMSA003

Should also work with other Plantower Particulate Matter like PMS5003, PMS7003 etc.

Dependency

This project depends on pyserial.

API

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

In Command Line

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.

A bit of this sensor

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:

  1. Wake up.
  2. Go passive, get a success response (8 bytes).
  3. Wait 30 seconds, let the fan rotate, and wait PM data to stablize.
  4. Query once.
  5. Read once -> this is the data we want.
  6. Go sleep, get a success response (8 bytes).

License

MIT

About

Read PM2.5 Data for Plantower PMSX003

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages