UART – a bidirectional serial protocol

class busio.UART(tx, rx, *, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, receiver_buffer_size=64)

A common bidirectional serial protocol that uses an an agreed upon speed rather than a shared clock line.

Parameters:
  • tx (Pin) – the pin to transmit with, or None if this UART is receive-only.
  • rx (Pin) – the pin to receive on, or None if this UART is transmit-only.
  • baudrate (int) – the transmit and receive speed.
deinit()

Deinitialises the UART and releases any hardware resources for reuse.

__enter__()

No-op used by Context Managers.

__exit__()

Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.

read(nbytes=None)

Read characters. If nbytes is specified then read at most that many bytes. Otherwise, read everything that arrives until the connection times out. Providing the number of bytes expected is highly recommended because it will be faster.

Returns:Data read
Return type:bytes or None
readinto(buf, nbytes=None)

Read bytes into the buf. If nbytes is specified then read at most that many bytes. Otherwise, read at most len(buf) bytes.

Returns:number of bytes read and stored into buf
Return type:bytes or None
readline()

Read a line, ending in a newline character.

Returns:the line read
Return type:int or None
write(buf)

Write the buffer of bytes to the bus.

Returns:the number of bytes written
Return type:int or None
baudrate

The current baudrate.

in_waiting

The number of bytes in the input buffer, available to be read

reset_input_buffer()

Discard any unread characters in the input buffer.

class busio.UART.Parity

Enum-like class to define the parity used to verify correct data transfer.

ODD

Total number of ones should be odd.

EVEN

Total number of ones should be even.