PMS5003 air quality sensor library

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: PMS5003 air quality sensor library

Post by IHOXOHI » Fri Jul 03, 2020 4:10 pm

Yep,

I tried a classical pms "main" wich contain the pmeregister.callback() command that is on your github'srepository:

Code: Select all

import machine
# import pms5003
import uasyncio as asyncio
#from . import pms5003
from pms.pms5003 import PMS5003
import pms.pms5003

_DEFAULT_MS = 20

class Lock:
    def __init__(self):
        self._locked = False

    async def __aenter__(self):
        while True:
            if self._locked:
                await asyncio.sleep_ms(_DEFAULT_MS)
            else:
                self._locked = True
                break

    async def __aexit__(self, *args):
        self._locked = False
        await asyncio.sleep_ms(_DEFAULT_MS)

    def locked(self):
        return self._locked

    def release(self):
        self._locked = False
        
lock = Lock()
uart = machine.UART(4, baudrate=9600)
pm = PMS5003(uart, lock) 
pm.registerCallback(pm.print)

loop=asyncio.get_event_loop()
loop.run_forever()
I have jst add the "default_ms"

And it works fine! Everything. That's perfect.

So, for sum up, I have had just to change the flush command in the module and import the module like in my example, and pms5003 works on pyboard too.

I will try your other file and post if necessary.

All the best.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: PMS5003 air quality sensor library

Post by kevinkk525 » Sat Jul 04, 2020 5:28 am

I now created a new branch for uasyncio v3 that should also support all ports: https://github.com/kevinkk525/pms5003_m ... uasyncioV3

If anyone is using uasyncio version 3 (included in daily builds) please give it a try. The changes are small and I guess even the old pms5003 code sohuld work fine on uasyncio v3.
I can't test it at the moment and I only have an esp32 and no pyboard (or other micropython board except esp8266) so I'd be happy if someone could try it on their board.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: PMS5003 air quality sensor library

Post by IHOXOHI » Wed Sep 09, 2020 6:22 pm

Yep,

I tried with the new firmware 1.13 which contain uasyncio3...

My return:
"File "uasyncio/__init__.py", line 1, in __getattr__
AttributeError: Stream"

I will try other "things"... and post results

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: PMS5003 air quality sensor library

Post by IHOXOHI » Wed Sep 09, 2020 8:43 pm

Yip,

The old version of PMS Kevin's library works yet with uasyncio3.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: PMS5003 air quality sensor library

Post by kevinkk525 » Wed Sep 09, 2020 9:13 pm

IHOXOHI wrote:
Wed Sep 09, 2020 6:22 pm
I tried with the new firmware 1.13 which contain uasyncio3...

My return:
"File "uasyncio/__init__.py", line 1, in __getattr__
AttributeError: Stream"
That's weird.
Looks like firmware 1.13 doesn't include uasyncio version 3 on the esp8266: https://github.com/micropython/micropython/issues/6410
That would be the only explanation for missing "Stream" as the old uasyncio didn't have that.

Can you check what this prints to confirm that you have uasyncio version 3?

Code: Select all

import uasyncio
print(uasyncio.__version__)
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: PMS5003 air quality sensor library

Post by IHOXOHI » Wed Sep 09, 2020 9:59 pm

(3, 0, 0)

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: PMS5003 air quality sensor library

Post by kevinkk525 » Thu Sep 10, 2020 7:25 am

oh I found the problem.. I thought Stream would be exposed in uasyncio but only StreamReader and StreamWriter are (which are all the same actually)..
Fixed it now, thanks for reporting!
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: PMS5003 air quality sensor library

Post by IHOXOHI » Thu Sep 10, 2020 9:57 am

Yup,

Nice!

And now, I have seen that it's not necessary to change the flush command which is included in a def of the new lib.

Otherwise, maybe it could be good to indicate that for a pyboard (or similar board like esp32, or pyb-d) use, the lib must be in a pms folder with the init file, and the call of the library is done in 2 times like :"
from pms.pms5003 import PMS5003
import pms.pms5003
"

I haven't re-tested the new lib with asyncio3 yet, but for me only a main.py file with a lock part and a callback worked until yesterday...

Thanks for your good job.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: PMS5003 air quality sensor library

Post by IHOXOHI » Thu Sep 10, 2020 4:59 pm

That's allright!

No need to have a main with a lock function.

It left just to import it in 2 times.

Thanks a lot for everything.
All the best.

Primesty
Posts: 49
Joined: Sun Jun 28, 2020 11:06 pm

Re: PMS5003 air quality sensor library

Post by Primesty » Mon Mar 22, 2021 9:52 pm

Hi @kevinkk525,

I'm trying to set up the PMS5003 example on an ESP32 (with MicroPython 1.14) from your github but seem to be getting

Code: Select all

 No response to wakeup command 
errors. Weirdly enough, when I run

Code: Select all

 pm.isActive() 
it returns True.

Code: Select all

>>> pm.isActive()
True
This is my UART sertting:

Code: Select all


uart = UART(1, baudrate = 9600, tx = 25, rx = 26)
uart.init(bits = 8, parity = None, stop = 1)

What could be the problem here? Any help would be greatly appreciated.

Post Reply