Home

Awesome

pms5003_micropython

Driver for pms5003 air quality sensor for micropython

Description and features

This driver for the pms5003 air quality sensor is specifically made for micropython. It should be usable on all ports that have a uart with configurable baudrate. It is completely based on uasyncio.

The driver covers all features of the device:

The library is built to be reslient, so if a reset pin is given, it will reset the device after a few tries if commands are not answered or no new data is received within 60s in active mode. If a reset fails (even because no reset pin is given) it will stop the device.

Reset and Set pin are completely optional though. The reset pin could make sense to have, the Set pin for sleep/wakeUp seems unnecessary as it's functionality is covered by uart commands.

Dependencies

How to use

import pms5003
import machine
import uasyncio as asyncio

uart = machine.UART(1, tx=25, rx=26, baudrate=9600)
pm = pms5003.PMS5003(uart)
pm.registerCallback(pm.print)

loop=asyncio.get_event_loop()
loop.run_forever()

An output of pm.print() looks like this:

---------------------------------------------
Measurement 12ms ago at 2018-06-24 22:28:21
---------------------------------------------
Concentration Units (standard)
---------------------------------------------
PM 1.0: 1       PM2.5: 2        PM10: 2
Concentration Units (environmental)
---------------------------------------------
PM 1.0: 1       PM2.5: 2        PM10: 2
---------------------------------------------
Particles > 0.3um / 0.1L air: 528
Particles > 0.5um / 0.1L air: 151
Particles > 1.0um / 0.1L air: 18
Particles > 2.5um / 0.1L air: 0
Particles > 5.0um / 0.1L air: 0
Particles > 10 um / 0.1L air: 0
---------------------------------------------

After the creation of the pms5003 object, which is configurable in the constructor, the library takes care of everything and you just have to register your callbacks or events. Of course you can change everything later as you see fit and change the reading mode, the eco mode or the polling interval in passive mode.

Methods explained

The last read values (or None if the sensor is not active) can be accessed as properties:

Useful tips:

Possible problems: