Skip to content

UART — port initialization (uart_init)

What it does: Initializes the UART(1) hardware port with the selected speed, frame format and RX/TX pins.

uart_init

Inputs

  • Field baud: baud rate (typically 9600 to 115200).
  • Field bits: number of data bits (7, 8, 9).
  • Field parity: parity (None, even, odd).
  • Field stop_bit: number of stop bits (1 or 2).
  • rx_pin: RX pin number.
  • tx_pin: TX pin number.

Output

  • None (statement block).

When to use it

  • Before using all blocks uart_read_* and uart_write.
  • When communicating with sensors, modems, GPS or other MCU over a serial line.

Tips and pitfalls

  • UART parameters must match the other side (baud, parity, stop bits).
  • Verify wiring: TX device to RX ESP32 and vice versa.

Generated Python example

uart1 = UART(1, baudrate=115200, tx=17, rx=16, bits=8, parity=None, stop=1)