Closed stantond closed 4 years ago
Hi Daniel , You can find examples how of to use it in test.py test_passive.py and test_passive_sleep.py.
This uses active mode. In this case the PM sensors sends data over the serial port whenever it has a reading available and the code just has to listen to receive it.
This uses passive mode, which means that the device only sends readings when explicitly asked. So the method called does the following to take a reading
self.serial.flush() # Make sure tx buffer is completely sent
ret = self.read(False)
Is the same as test_passive.py but also demonstrates how to turn the fan of the sensor off to reduce power consumption
No the SET and RESET pins are not required. At the time of posting an English version of the datasheet for the A003 can be found at http://m.eleparts.co.kr/data/goods_old/data/PMSA003.pdf.
Hope that helps.
@pjb304 so does pulling low on the SET pin to "sleep" do the same thing as the "sleep" command used in test_passive_sleep.py
? I've read it's important to sleep the device when it doesn't need to be reading to significantly lengthen the lifespan of the sensor, but I'm not sure if both of these "sleep" functions really to the same thing. The use I have in mind (monitoring air quality when 3D printing) really requires very infrequent readings (maybe once every 15 minutes or so for several days in very long prints).
I'm afraid I don't know. We use active mode 24/7 in our sensors some of which have been running continuously for 2 years.
The passive mode and sleep code has been contributed by others, while we've tested it works briefly I do not know all the details of how it works, and our sensors are just connected using TX, RX and GND. Reading the datasheet I would assume that the sleep mode is the same if you enter it using the s/w or the SET line, but I have not tested this.
Hi,
Further to Phil comments, we already had a discussion about the sleep mode earlier in this pull request: https://github.com/FEEprojects/plantower/pull/3#pullrequestreview-345829048 But as Phil said, we only use the active mode. The performance of the sensor did not degrade over a year long period and we have been running the sensors for more than two years (but we have not yet checked whether the performances degrade on the second year).
I hope that helps.
Something isn't quite right in the usage examples..
I followed test_passive.py
, and got nonsensical results. Changing to active mode immediately gave more realistic-looking results.
>>> PLANTOWER = plantower.Plantower(port="COM3")
>>> PLANTOWER.mode_change(plantower.PMS_PASSIVE_MODE) #change into passive mode
>>> PLANTOWER.set_to_wakeup() #spin up the fan
>>> time.sleep(30)
>>> RESULT = PLANTOWER.read_in_passive()
>>> print(RESULT)
2020-05-02 17:03:22,0,0,0,0,0,0,135,42,3,0,0,0,
>>> RESULT = PLANTOWER.read_in_passive()
>>> print(RESULT)
2020-05-02 17:04:42,0,0,0,0,0,0,102,34,3,0,0,0,
>>> RESULT = PLANTOWER.read_in_passive()
>>> print(RESULT)
2020-05-02 17:07:35,0,0,0,0,0,0,63,21,0,0,0,0,
>>> RESULT = PLANTOWER.read_in_passive()
>>> print(RESULT)
2020-05-02 17:07:46,0,0,0,0,0,0,129,37,0,0,0,0,
>>> RESULT = PLANTOWER.read_in_passive()
>>> print(RESULT)
2020-05-02 17:08:52,0,0,0,0,0,0,99,30,0,0,0,0,
>>> RESULT = PLANTOWER.read_in_passive()
>>> print(RESULT)
2020-05-02 17:10:29,0,0,0,0,0,0,159,47,3,0,0,0,
>>> PLANTOWER.mode_change(plantower.PMS_ACTIVE_MODE)
>>> PLANTOWER.set_to_wakeup()
>>> print(PLANTOWER.read())
2020-05-02 17:12:17,1,1,10,10,14,14,0,0,0,0,0,0,
>>> print(PLANTOWER.read())
2020-05-02 17:12:22,1,1,11,11,16,16,423,141,43,33,3,3,
>>> print(PLANTOWER.read())
2020-05-02 17:12:29,1,1,11,11,12,12,387,129,36,30,0,0,
>>> print(PLANTOWER.read())
2020-05-02 17:12:34,1,1,10,10,11,11,282,94,24,21,0,0,
>>> print(PLANTOWER.read())
2020-05-02 17:12:36,1,1,10,10,11,11,294,98,27,18,0,0,
>>> print(PLANTOWER.read())
2020-05-02 17:12:41,1,1,8,8,10,10,243,81,18,9,0,0,
Have I done something wrong here?
I'm afraid I'm not sure what's going on there. I have just run the same commands as you in an interactive shell and it is working for me. As I can't repeat the issue I'm afraid I can't offer any fixes.
pi@puffin:~/plantower $ ipython3
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
Type "copyright", "credits" or "license" for more information.
IPython 5.8.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import plantower, time
In [2]: PLANTOWER = plantower.Plantower("/dev/ttyUSB0")
In [3]: PLANTOWER.mode_change(plantower.PMS_PASSIVE_MODE)
In [4]: PLANTOWER.set_to_wakeup()
In [5]: time.sleep(30)
In [6]: print(PLANTOWER.read_in_passive())
2020-05-04 13:49:33,7,7,9,9,11,11,1326,367,58,4,2,2,
In [7]: print(PLANTOWER.read_in_passive())
2020-05-04 13:50:08,7,7,10,10,10,10,1386,385,56,4,0,0,
In [8]: print(PLANTOWER.read_in_passive())
2020-05-04 13:50:13,8,8,11,11,11,11,1404,390,60,6,0,0,
In [9]: print(PLANTOWER.read_in_passive())
2020-05-04 13:50:15,8,8,11,11,11,11,1386,380,58,6,0,0,
It also works when called using the script:
pi@puffin:~/plantower $ ./test_passive.py /dev/ttyUSB0
Setting sensor into passive mode. Please wait.
2020-05-04 13:57:01,6,6,9,9,9,9,1266,356,52,2,0,0,
@pjb304 so does pulling low on the SET pin to "sleep" do the same thing as the "sleep" command used in
test_passive_sleep.py
? I've read it's important to sleep the device when it doesn't need to be reading to significantly lengthen the lifespan of the sensor, but I'm not sure if both of these "sleep" functions really to the same thing. The use I have in mind (monitoring air quality when 3D printing) really requires very infrequent readings (maybe once every 15 minutes or so for several days in very long prints).
From my PMS7003 power consumption test on my board, "pulling low on the SET pin to "sleep" do the same thing as the "sleep" command". It had the same power consumption. My reading was 4.81mA @ VCC 5.6V It was quite higher than the datasheet value(0.2mA @5V), but still very lower than active current though. I could do something wrong on my measurement, but on my environment SET pin and sleep command was same.
Thanks for the update, it's good to know that set low and the sleep command seem to do the same thing.
Hi
Would you be able to add some examples of how to use this?
Also, what's the difference between Active and Passive mode, and are the SET and RESET pins required? Hard to find out as the datasheet for the A003 is only in Chinese!
Thanks