Halting on empty uart buffer
Posted: Tue Feb 16, 2021 10:00 pm
I have been considering switching from PyBoard to Raspberry Pi Pico and I thought I should do some tests. But I almost instantly ran into a problem that I cant solve.
I am reading from two serial ports and combine the two data streams into a third, so I want to read the two uarts on the Pico. The problem is that as long as the uarts is receiving data continuously everything works fine. But when one of the sources stops feeding data the Pico is waiting to get data. It will simply not continue exacting the next line of code.
Executing the (almost) same code on my PyBoard it works flawlessly. Any suggestions?
I am reading from two serial ports and combine the two data streams into a third, so I want to read the two uarts on the Pico. The problem is that as long as the uarts is receiving data continuously everything works fine. But when one of the sources stops feeding data the Pico is waiting to get data. It will simply not continue exacting the next line of code.
Executing the (almost) same code on my PyBoard it works flawlessly. Any suggestions?
Code: Select all
from machine import UART
import time
u0 = UART(0, baudrate=38400) #Pi Pico
#u0 = UART(2, 38400) #PyBoard 1.1
#u0.init(38400, bits=8, parity=None, stop=1, rxbuf=512) #PyBoard 1.1
u1 = UART(1, baudrate=38400) #Pi Pico
#u1 = UART(4, 38400) #PyBoard 1.1
#u1.init(38400, bits=8, parity=None, stop=1, rxbuf=512) #PyBoard 1.1
while True:
if u0.any() > 0:
x = u0.readline()
print(x)
if u1.any() > 0:
y = u1.readline()
print(y)