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.
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.
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.