Search found 7 matches

by KUMO
Tue May 25, 2021 9:04 pm
Forum: Raspberry Pi microcontroller boards
Topic: Problem with UART reading (MH-Z19B sensor)
Replies: 13
Views: 8565

Re: Problem with UART reading (MH-Z19B sensor)

If I look at your screen copies, the garbage comes at the first read, causing an offset of 3 bytes. That offset continues through the following reads of 9 bytes each and results in bad results. Again: every time before sending out a command to the sensor you have to ensure that nothing is already i...
by KUMO
Mon May 24, 2021 6:54 pm
Forum: Raspberry Pi microcontroller boards
Topic: Problem with UART reading (MH-Z19B sensor)
Replies: 13
Views: 8565

Re: Problem with UART reading (MH-Z19B sensor)

Is this garbage only occuring during the first exchange or for every other ones? If it is only on the first one, it is surely a problem linked to the setup of the sensor. In that case, maybe you can add a few seconds delay before entering the flush loop I suggested. The delay shall be longer than t...
by KUMO
Sun May 23, 2021 9:01 pm
Forum: Raspberry Pi microcontroller boards
Topic: Problem with UART reading (MH-Z19B sensor)
Replies: 13
Views: 8565

Re: Problem with UART reading (MH-Z19B sensor)

Thats' strange. If you are always have three extra bytes upfront, you could try for read 12 byte and discard the first three. B.T.W.: Which version of the firmware do you use? Edit: I would move the clearing of the input buffer INTO the loop before you send a command. Then any remainder of a previo...
by KUMO
Sun May 23, 2021 7:21 pm
Forum: Raspberry Pi microcontroller boards
Topic: Problem with UART reading (MH-Z19B sensor)
Replies: 13
Views: 8565

Re: Problem with UART reading (MH-Z19B sensor)

Well, that not a secure way of coding. It is always possible that there is garbage sent on the line while the sensor is initializing itself. Maybe you can add a short piece of code in order to flush the RX buffer before talking to your sensor. Insert this before entering your infinite loop while (s...
by KUMO
Sun May 23, 2021 7:03 pm
Forum: Raspberry Pi microcontroller boards
Topic: Problem with UART reading (MH-Z19B sensor)
Replies: 13
Views: 8565

Re: Problem with UART reading (MH-Z19B sensor)

You have to add the read best immediately before you send the command to the sensor. There is no difference to the UART behavior between running code from the IDE or from Flash. If you say: Remove the first two bytes: did you still process the whole 9 bytes you expect from the sensor? Or was the me...
by KUMO
Sun May 23, 2021 11:40 am
Forum: Raspberry Pi microcontroller boards
Topic: Problem with UART reading (MH-Z19B sensor)
Replies: 13
Views: 8565

Re: Problem with UART reading (MH-Z19B sensor)

Dear Robert, thanks for your reply! I tried your suggestion and added sensor.read() in the beginning and print the result. It shows that it is always None at the very beginning once the board is connected to power. But after that the reading has the pattern b'\x00\x00F\...., no matter how long I wai...
by KUMO
Sat May 22, 2021 6:48 pm
Forum: Raspberry Pi microcontroller boards
Topic: Problem with UART reading (MH-Z19B sensor)
Replies: 13
Views: 8565

Problem with UART reading (MH-Z19B sensor)

Hello together, I am a totally new comer for MicroPython. Recently I connected successfully a MH-Z19B sensor to my PICO via UART. The CO2 level as result will then be displayed on a SSD1306 screen. The codes work fine. So I decided to save the it as main.py to have it running automatically once it i...