Home/Support/Support Forum/Test for UART data, XBEE3 and Micropython (kbhit)

Test for UART data, XBEE3 and Micropython (kbhit)

0 votes
Is it possible to test for data available from the UART?
This commonly implemented with kbhit(), or nonblocking, modes.

I can wait for one character with this:
> key = stdin.buffer.read(1)
This doesn't return until a key received (wait forever)
I would like a way to know if a key is available before reading it.

I see some related documentation for pyserial, but haven't found a way to create a serial object in micropython.

asked Dec 17, 2019 in RF Solutions and XBee by aadgi New to the Community (3 points)

Please log in or register to answer this question.

2 Answers

0 votes
Yes you can. It does not use Pins 2 and 3 as that is your Micro Python REBL interface. Instead it uses some of the other DIO lines for that which you have to enable.
If I recall it is the import XBee.uart. But this is also dependent on which XBee 3 module you are working with and what firmware version.
answered Dec 18, 2019 by mvut Veteran of the Digi Community (15,323 points)
0 votes
Thanks for the response. I am using ZigBee version of Xbee 3. I didn't find a 2nd UART for that, but did for the cellular version. The example for the Cellular led to this, which appears to be working for ZigBee version:

> key = stdin.buffer.read(-1)

It either returns a pressed key, or None if no key was pending.
answered Dec 23, 2019 by aadgi New to the Community (3 points)