UART – a bidirectional serial protocol

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

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

  • 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.
  • bits (int) – the number of bits per byte, 7, 8 or 9.
  • parity (Parity) – the parity used for error checking.
  • stop (int) – the number of stop bits, 1 or 2.
  • timeout (float) – the timeout in seconds to wait for the first character and between subsequent characters. Raises ValueError if timeout >100 seconds.
  • receiver_buffer_size (int) – the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.)

New in CircuitPython 4.0: timeout has incompatibly changed units from milliseconds to seconds. The new upper limit on timeout is meant to catch mistaken use of milliseconds.


Deinitialises the UART and releases any hardware resources for reuse.


No-op used by Context Managers.


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


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

Read bytes into the buf. Read at most len(buf) bytes.

Returns:number of bytes read and stored into buf
Return type:int or None (on a non-blocking error)

New in CircuitPython 4.0: No length parameter is permitted.


Read a line, ending in a newline character.

Returns:the line read
Return type:int or None

Write the buffer of bytes to the bus.

New in CircuitPython 4.0: buf must be bytes, not a string.

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

The current baudrate.


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


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.


Total number of ones should be odd.


Total number of ones should be even.