views
Many beginners struggle when trying to use UART on ESP32 with ESP-IDF. Wrong pin setup, baud rate mismatch, or confusing code can make things harder than expected. This problem often wastes time and prevents projects from working. The good news is that with a simple guide and tested ESP-IDF UART example, you can get communication working in minutes. In this blog, we explain how to set up UART on ESP32, write code, and test it step by step.
What is UART on ESP32?
UART stands for Universal Asynchronous Receiver and Transmitter. It is a simple serial communication protocol used to send and receive data.
The ESP32 chip has three hardware UART controllers:
-
UART0 → Used for programming and debugging by default.
-
UART1 → Free for user applications.
-
UART2 → Free for user applications.
All three can work with baud rates up to 5 Mbps, though standard values like 9600 and 115200 are most common.
Why Learn ESP-IDF UART?
-
Official ESP-IDF gives low-level control of hardware.
-
More stable and faster than Arduino framework.
-
Allows custom pin mapping for TX and RX.
-
Needed when working with sensors, GPS, or GSM modules.
ESP32 UART Pin Configuration
Default pin mapping is:
-
UART0: TX0 (GPIO1), RX0 (GPIO3)
-
UART1: TX1 (GPIO10), RX1 (GPIO9)
-
UART2: TX2 (GPIO17), RX2 (GPIO16)
But ESP-IDF allows remapping. You can assign UART signals to most GPIO pins using the uart_set_pin()
function.
ESP-IDF UART Example Setup
Hardware Needed
-
ESP32 development board
-
USB cable
-
Jumper wires
-
Another UART device (Arduino, USB-to-TTL adapter, or another ESP32)
Software Needed
-
ESP-IDF installed on your system
-
Python (for ESP-IDF environment)
-
Serial terminal program like PuTTY or Arduino Serial Monitor
ESP-IDF UART Example: Sending Data
Here is a simple ESP-IDF example to send data over UART1:
This program configures UART1 with TX on GPIO17 and RX on GPIO16, then sends a message every second.
ESP-IDF UART Example: Receiving Data
Reading UART data is just as easy.
This snippet reads incoming UART data and sends it back, acting like a loopback test.
Common UART Issues on ESP32
-
Wrong baud rate causes unreadable characters.
-
TX of one device must connect to RX of the other.
-
If using UART0, make sure not to interrupt USB programming.
-
Level shifting is needed when connecting with 5V devices.
Practical Uses of ESP-IDF UART
-
Send debug messages without blocking USB interface.
-
Connect ESP32 to GPS modules for location data.
-
Communicate with GSM modules using AT commands.
-
Connect two ESP32 boards for direct communication.
-
Send sensor data to PC for logging.
Pros and Cons of ESP-IDF UART
Pros
-
Direct hardware access with ESP-IDF.
-
Flexible pin assignment.
-
Works at high baud rates.
Cons
-
More complex than Arduino UART.
-
UART0 shared with USB, limiting free UARTs.
Conclusion
Using ESP-IDF UART on ESP32 gives you more control and flexibility compared to Arduino. With correct pin mapping and baud rate, you can send and receive data easily. The examples shared here help beginners start quickly with ESP-IDF UART code. From simple text messages to GPS and GSM modules, the same setup applies.
Start with the simple ESP-IDF UART example, test communication, and expand your projects step by step. For more guides, check out other ESP32 tutorials on ControllersTech.
