Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running with Raspberry Pi Pico #8

Open
dominic-ks opened this issue Jan 30, 2022 · 0 comments
Open

Running with Raspberry Pi Pico #8

dominic-ks opened this issue Jan 30, 2022 · 0 comments

Comments

@dominic-ks
Copy link

dominic-ks commented Jan 30, 2022

Hello,

First of all, thank you for publishing this driver, I'm not used to working with code that provides such raw values like I get from the pms5003!

Just a note here, not necessarily an issue...

I want to use my pms5003 with a Raspberry Pi Pico, I assumed that your sample code was focussed on a Raspberry Pi based on the fact that you had referenced pins 25 and 26 for TX / RX which don't match the Pico pinout. Though, side note here is that for these values to be accepted on the Pico I had to reference the pins, like this:

uart = machine.UART(1, tx=machine.Pin(4), rx=machine.Pin(5), baudrate=9600)

Although as it happens, I can omit these values altogether:

uart = machine.UART(1, baudrate=9600)

I'm assuming that the Pico already knows the relevant pins for UART0 and UART1 and so doesn't need them spelling out. Just a guess though.

I was having an issue, however, getting a reading from the driver even after I'd seen the byte values coming in when simply reading the values from the UART like so:

from machine import UART

uart = UART( 1 , 9600 )

while True:
    reading = uart.readline()
    print( reading )

It was consistently timing out wen attempting to wake up the device. I managed to track this down to line 252 of pms5003.py:

if self._uart.any() >= frame_len:

uart.any(), on the Pico it seems, only ever seems to return 0 when no bytes are available and 1 when there are.

I updated this line to if self._uart.any() >= 1: and from then on I reliably get readings from the sensor.

Thought I'd post this here since a) it might be interesting, b) it might help anyone else with this issue trying to use a Pico and c) in case you had any comment on whether this was or was not a good idea or if there is in fact some difference with the Pico that means it only returns 1 here, as is suggested can happen in the mictopython docs:

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant