machine.UART how to skip read?

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
ssfel
Posts: 3
Joined: Wed Mar 03, 2021 3:53 pm

machine.UART how to skip read?

Post by ssfel » Thu Apr 08, 2021 1:57 pm

Code: Select all

from machine import Pin, UART

uart = UART(1,115200)
ch = uart.read(1)

print("the code never reaches here without an input")
When I run the following code the the program runs until "uart.read(1)" and then stops and waits until it reads something.

I don't want this to be the case, I want to make it so that it gives up reading and continues with the rest of the program if it doesn't read anything. So I want to enable a timeout or a check that the value isn't 0 or something

How do I go about doing that? I've tried to look through the micropython documentation for machine.UART but I can't see anything

Thanks in advance

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

Re: machine.UART how to skip read?

Post by fdufnews » Thu Apr 08, 2021 5:06 pm

UART.any() will return how many bytes are waiting in the queue or 0 if nothing and it is non blocking

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: machine.UART how to skip read?

Post by Roberthh » Thu Apr 08, 2021 5:12 pm

Update the Firmware to the newest daily build. The read() is non-blocking.

Post Reply