Skip to content

Add in_waiting property to busio.UART - #1104

Merged
makermelissa merged 1 commit into
adafruit:mainfrom
makermelissa-ai-assistant:add-uart-in-waiting
Apr 15, 2026
Merged

Add in_waiting property to busio.UART#1104
makermelissa merged 1 commit into
adafruit:mainfrom
makermelissa-ai-assistant:add-uart-in-waiting

Conversation

@makermelissa-ai-assistant

Copy link
Copy Markdown
Contributor

Summary

Adds the in_waiting property to busio.UART to match CircuitPython's API. Returns the number of bytes available in the input buffer.

This is needed by libraries like Adafruit_CircuitPython_GPS that rely on in_waiting to check for available data before reading.

Changes

File What changed
src/busio.py Added in_waiting property with fallback chain: custom in_waiting → MicroPython any()NotImplementedError
src/adafruit_blinka/microcontroller/rp2040/uart.py Added in_waiting property wrapping MicroPython's uart.any()

How it works

  • RP2040 (and future custom UART classes): Uses the in_waiting property on the underlying UART implementation
  • Generic MicroPython boards: Falls back to uart.any() which is MicroPython's equivalent
  • Unsupported platforms: Raises NotImplementedError with a clear message

Fixes #1046

Add the in_waiting property to match CircuitPython's busio.UART API.
Returns the number of bytes available in the input buffer.

- RP2040 UART: wraps MicroPython's uart.any()
- busio.UART wrapper: checks for in_waiting first, falls back to
  any(), raises NotImplementedError if neither is available

Fixes adafruit#1046

@makermelissa makermelissa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@makermelissa
makermelissa merged commit 7debd39 into adafruit:main Apr 15, 2026
1 check passed
@Fancy2209

Fancy2209 commented Apr 15, 2026

Copy link
Copy Markdown

When I tested it, return self._uart.any() wouldn't work on the GPS Lib
I had to do

result = self._uart.any()
return result if result == 0 else int(result / 8)

However not sure if the magic 8 is RPi Pico specific

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

in_waiting missing from board.UART

3 participants