pimoroni / pms5003-circuitpython

CircuitPython library for the PMS5003 particulate sensor
MIT License
2 stars 5 forks source link

Add request based reads for polling (AKA passive mode) #5

Open kevinjwalters opened 3 years ago

kevinjwalters commented 3 years ago

Introduce a mode parameter to PMS5003 constructor using the Plantower terminology of "active" and "passive". The PMS5003 starts-up in active mode where it streams data frames after an unknown duration and with an interval between 200ms to 910ms (commonly observed) to 2.3 seconds. Passive mode is a polling mode where a read command elicits a data frame response.

Review and borrow approach from https://github.com/adafruit/Adafruit_CircuitPython_PM25/pull/13

Notes:

kevinjwalters commented 3 years ago

From 11b0c70e8fe63f92d9866fa91a4fd2f5d9d23eb4

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
MODE TESTS
Instatiating in the non-default passive mode...
passive   1 at 3.923431 took 0.041229 PM ug/m3 2.5=3 10=3
passive   2 at 5.315582 took 0.041260 PM ug/m3 2.5=3 10=3
passive   3 at 7.056732 took 0.041321 PM ug/m3 2.5=3 10=3
passive   4 at 7.948883 took 0.041260 PM ug/m3 2.5=4 10=4
passive   5 at 8.492065 took 0.041199 PM ug/m3 2.5=3 10=3
passive   6 at 8.834473 took 0.041290 PM ug/m3 2.5=3 10=3
passive   7 at 8.976685 took 0.041290 PM ug/m3 2.5=3 10=3
passive   8 at 9.109070 took 0.041260 PM ug/m3 2.5=3 10=3
passive   9 at 9.230804 took 0.041321 PM ug/m3 2.5=3 10=3
active   10 at 10.647156 took 0.767944 PM ug/m3 2.5=3 10=3
active   11 at 11.555359 took 0.907013 PM ug/m3 2.5=3 10=3
active   12 at 12.463776 took 0.907227 PM ug/m3 2.5=3 10=3
active   13 at 13.372163 took 0.907257 PM ug/m3 2.5=3 10=3
active   14 at 14.280609 took 0.907318 PM ug/m3 2.5=4 10=4
passive  15 at 16.137848 took 0.041290 PM ug/m3 2.5=4 10=4
passive  16 at 16.980225 took 0.041321 PM ug/m3 2.5=4 10=4
passive  17 at 17.422577 took 0.041290 PM ug/m3 2.5=4 10=4
passive  18 at 17.664276 took 0.041229 PM ug/m3 2.5=4 10=4
passive  19 at 17.906007 took 0.041260 PM ug/m3 2.5=4 10=4
passive  20 at 18.148011 took 0.041229 PM ug/m3 2.5=4 10=4

Press any key to enter the REPL. Use CTRL-D to reload.soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
RESET TESTS
Sleeping for a bit
Instatiating in active mode
Initialisation took 2.66611 seconds
active   1 at 2.668152 took 0.001343 PM ug/m3 2.5=4 10=4
active   2 at 3.670349 took 0.001312 PM ug/m3 2.5=3 10=9
active   3 at 4.673523 took 0.001312 PM ug/m3 2.5=2 10=6
Reset took 2.66373 seconds
active   4 at 7.340942 took 0.001984 PM ug/m3 2.5=2 10=2
active   5 at 8.343414 took 0.001312 PM ug/m3 2.5=1 10=1
active   6 at 9.346375 took 0.001312 PM ug/m3 2.5=2 10=2
Instatiating in passive mode
Initialisation took 2.88098 seconds
passive   1 at 2.922882 took 0.041229 PM ug/m3 2.5=0 10=0
passive   2 at 3.964935 took 0.041199 PM ug/m3 2.5=3 10=3
passive   3 at 5.007874 took 0.041260 PM ug/m3 2.5=3 10=3
Reset took 2.88211 seconds
passive   4 at 7.932983 took 0.041260 PM ug/m3 2.5=0 10=0
passive   5 at 8.975067 took 0.041290 PM ug/m3 2.5=0 10=4
passive   6 at 10.017029 took 0.041290 PM ug/m3 2.5=0 10=3
Instatiating in active mode
Initialisation took 2.66629 seconds
active   1 at 2.668274 took 0.001343 PM ug/m3 2.5=1 10=1
active   2 at 3.575195 took 0.405914 PM ug/m3 2.5=3 10=3
active   3 at 4.483337 took 0.406891 PM ug/m3 2.5=3 10=3
Reset took 2.66373 seconds
active   4 at 7.150787 took 0.001984 PM ug/m3 2.5=4 10=4
active   5 at 8.058807 took 0.406769 PM ug/m3 2.5=2 10=2
active   6 at 8.967041 took 0.407410 PM ug/m3 2.5=3 10=3

Press any key to enter the REPL. Use CTRL-D to reload.
kevinjwalters commented 3 years ago

Enviro+ FeatherWing oddity: Pimoroni Forums: Enviro+ FeatherWing fails to produce 5V until power-cycled.

kevinjwalters commented 3 years ago

Reminder: fix https://github.com/pimoroni/EnviroPlus-FeatherWing/blob/master/.gitmodules#L6 too

Done in https://github.com/pimoroni/EnviroPlus-FeatherWing/pull/21

kevinjwalters commented 3 years ago

Code from other world https://github.com/tijmenvandenbrink/enviroplus_exporter/blob/master/enviroplus_exporter.py currently does not expect exceptions from constructor but is looking for ReadTimeoutError on read().