yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ESP32 Core Board📖
1. ESP32 Introduction
  • 1. ESP32S3 Overview
  • 2. Environment Setup Introduction
  • 3. Dev Board Introduction
2. ESP-IDF Development Tutorial
1. Before Development
  • 1. Environment Setup (Windows)
  • 2. Environment Setup (Linux)
  • 3. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. DMA
  • 8. ADC
  • 9. PWM Breathing LED
  • 10. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. PSRAM External Memory Experiment
  • 5. Flash Read and Write Experiment
  • 6. USB Emulated Mass Storage Experiment
4. FreeRTOS operating system
  • 1.FreeRTOS Core Concepts Theory
  • 2.Task Creation and Management
  • 3.Queue
  • 4.Binary Semaphore
  • 5.Mutex
  • 6.Event Groups
  • 7.Software Timer
  • 8.Task Scheduler
  • 9.Low Power Mode
  • 10.Deadlock
  • 11.Priority Inversion
5. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. Socket Programming Basics
  • 9. HTTP Client Experiment
  • 10. HTTP Server Experiment
  • 11. MQTT IoT Communication Protocol
  • 12. WIFI OTA Upgrade
  • 13. Bluetooth Fundamentals
  • 14. Bluetooth Slave Mode
  • 15. Bluetooth Master Mode
6. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
7. Xiaozhi AI Voice
  • 1. Burn Xiaozhi Firmware
  • 2. Network and Configuration
  • 3. AI Agent Settings
  • 4. Program Analysis
  • 5. Free Chat
3. Arduino Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. ADC
  • 8. PWM Breathing LED
  • 9. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication
  • 2. I2C OLED Display
  • 3. SPI Bus Communication
  • 4. Flash Read and Write
  • 5. USB Emulated Mass Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Server Experiment
  • 5. UDP Client Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT IoT Communication Protocol
  • 11. WIFI OTA Upgrade
  • 12. Bluetooth Fundamentals
  • 13. Bluetooth Slave Mode
  • 14. Bluetooth Master Mode
5. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
4. MicroPython Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
  • 3. Thonny IDE
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. TIMER_IT
  • 5. Watchdog Timer
  • 6. ADC
  • 7. PWM Breathing LED
  • 8. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. Flash Read and Write Experiment
  • 5. Print Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT
  • 11. Bluetooth Fundamentals
  • 12. Bluetooth Slave Mode
  • 13. Bluetooth Master Mode
5. Audio Applications
  • 1. I2S Audio Playback Experiment
  • 2. Repeater Experiment
Download
  • Code
  • Hardware_Info
  • 3D_Model_File
  • Software_Tools
  • VMware
  • VM_File
Download ZIP

Welcome to ESP32 Core Board repository

1. Serial UART Communication

Serial UART Communication Experiment


Serial UART Communication Experiment1. Serial UART Communication Overview2. Core Concepts2.1 UART Frame Format2.2 ESP32 Hardware UART2.3 Key APIs2.4 RX Pin Pull-up Timing Trap3. Hardware Dependencies4. Project Architecture and Flow5. Source Code5.1 Macro Definitions and Global Variables5.2 setup() — Initialize Dual Serial Ports5.3 loop() — Transmit and Receive Loopback6. Operation Flow6.1 Compile and Flash6.2 Normal Phenomena6.3 Verification Methods7. Common Issues


1. Serial UART Communication Overview

UART is the most commonly used inter-board communication interface, requiring only TX/RX two wires for full-duplex transmission and reception. This experiment uses ESP32's hardware UART2 (Serial2), with TX (GPIO14) and RX (GPIO5) connected with Dupont wires to form a loopback. A string is sent every 2 seconds and the data sent by itself is received, demonstrating the complete usage of Serial2.begin, write, and readBytes.

Typical Application Scenarios:

Application TypeExamples
Debug OutputSerial monitor, log printing
Module CommunicationGPS module, 4G module, fingerprint module, Bluetooth AT commands
Industrial BusRS-232, RS-485 (with transceiver chip)
Inter-board CommunicationPoint-to-point data exchange between two MCUs

This project demonstrates UART2 loopback communication: the MCU sends a string via TX, RX receives the echoed data, achieving self-send and self-receive hardware verification.


2. Core Concepts

2.1 UART Frame Format

UART transmits data in frames (common 8N1 format = 8 data bits + no parity + 1 stop bit):

​x
IDLE  ┌──┐ ┌──┬──┬──┬──┬──┬──┬──┬──┐ ┌──┐
      │St│ │D0│D1│D2│D3│D4│D5│D6│D7│ │Sp│  IDLE
──────┘  │ │  │  │  │  │  │  │  │ │  ├──────
         └─┘  └──┴──┴──┴──┴──┴──┴──┴─┘  └──┘

      Start bit ←──── Data bits (LSB first) ────→ Stop bit
ParameterMeaningCommon Values
Baud RateSymbols per second9600, 115200, 921600
Data BitsData width5 / 6 / 7 / 8
ParityParity checkNone / Even / Odd
Stop BitsStop bit length1 / 1.5 / 2

On the same bus, the sender and receiver must have identical baud rate, data bits, parity, and stop bits, otherwise garbled characters will appear.

2.2 ESP32 Hardware UART

The ESP32-S3 has 3 hardware UART controllers, supporting GPIO matrix remapping, with any pin configurable as UART function.

Arduino ObjectESP32 HardwareDefault TX/RXDescription
SerialUART0GPIO43 / GPIO44Connected to on-board USB-UART bridge chip
Serial1UART1Any GPIOUser-defined mapping
Serial2UART2Any GPIOUsed in this experiment, mapped to GPIO14/5

2.3 Key APIs

  • Serial2.begin(115200, SERIAL_8N1, RXD_PIN, TXD_PIN) — Initialize UART2

  • Serial2.readBytes(buf, size) — Read bytes from RX FIFO, more reliable than readString()

  • Serial2.flush() — Wait for all data in TX FIFO to be sent

2.4 RX Pin Pull-up Timing Trap

pinMode(RXD_PIN, INPUT_PULLUP) must be set before Serial2.begin(). Once begin() is called, the RX pin is taken over by the hardware UART, and setting INPUT_PULLUP afterwards will be ineffective. When idle, a floating RX will cause noise data to be received.


3. Hardware Dependencies

PinPeripheralConfigurationDescription
GPIO14TXDUART2 TXSerial transmission
GPIO5RXDUART2 RX (INPUT_PULLUP)Serial reception, must be pulled up before begin

ESP32-S3 UART Hardware Features:

FeatureParameter
Number of UART controllers3 (UART0 / UART1 / UART2)
Maximum baud rate5 Mbps
FIFO depth128 bytes (independent TX/RX)
Data width5 / 6 / 7 / 8 bits
ParityNone / Even / Odd
Stop bits1 / 1.5 / 2 bits
Hardware flow controlSupports RTS/CTS
GPIO mappingAny GPIO can be configured as TX/RX/CTS/RTS via IO MUX

Connect GPIO14 and GPIO5 with a Dupont wire to form a "self-send and self-receive" loopback.

UART wiring diagram back

UART wiring diagram


4. Project Architecture and Flow

xxxxxxxxxx
setup()
  ├─ Serial.begin(115200)           // Monitor serial UART0
  ├─ pinMode(RXD_PIN, INPUT_PULLUP) // Must be before Serial2.begin
  ├─ Serial2.begin(115200, 8N1, RX, TX) // Initialize UART2
  └─ Print startup message

loop()
  ├─ Serial2.write("GOOD GOOD STUDY...\r\n")  // Send
  ├─ Serial2.flush()                          // Wait for FIFO to finish
  ├─ Serial2.setTimeout(200)
  ├─ len = Serial2.readBytes(rxBuf, 255)      // Receive loopback data
  ├─ Filter non-printable characters → Print RX content via serial
  └─ delay(2000)                              // 2 second interval

5. Source Code

Source Code Location: Source code → Arduino → 2.Serial communication → 1.UART → 1.UART.ino

5.1 Macro Definitions and Global Variables

xxxxxxxxxx
#define TXD_PIN 14
#define RXD_PIN 5
#define BUF_SIZE 256

uint8_t rxBuf[BUF_SIZE];

5.2 setup() — Initialize Dual Serial Ports

Configure the monitor serial port first, then initialize UART2 for loopback communication.

xxxxxxxxxx
void setup() {
  Serial.begin(115200);

  // Important: Set RX pull-up before Serial2.begin()
  pinMode(RXD_PIN, INPUT_PULLUP);

  Serial2.begin(115200, SERIAL_8N1, RXD_PIN, TXD_PIN);
  Serial.printf("UART Started, TX=GPIO%d, RX=GPIO%d\n", TXD_PIN, RXD_PIN);
}

pinMode(RXD_PIN, INPUT_PULLUP) must be called before Serial2.begin(). When TX/RX are shorted with Dupont wires, pull-up can be omitted, but keeping it is good defensive programming practice.

5.3 loop() — Transmit and Receive Loopback

Send a string, then read it back from the same port. Filter non-printable characters to keep the monitor readable.

xxxxxxxxxx
void loop() {
  Serial2.write("GOOD GOOD STUDY,DAY DAY UP!!!!!!\r\n");
  Serial2.flush();  // Wait for FIFO to finish

  Serial2.setTimeout(200);
  int len = Serial2.readBytes(rxBuf, BUF_SIZE - 1);

  if (len > 4) {
    for (int i = 0; i < len; i++) {
      if (rxBuf[i] == '\r' || rxBuf[i] == '\n') continue;
      if (rxBuf[i] < 0x20 || rxBuf[i] > 0x7E) rxBuf[i] = '.';
    }
    rxBuf[len] = '\0';
    Serial.printf("[RX] %s\n", rxBuf);
  }

  delay(2000);
}

Filtering replaces non-printable characters with .. The len > 4 threshold filters out noise.


6. Operation Flow

6.1 Compile and Flash

Arduino Flash Process: See 1. Before Development → 2. Build and Flash.

  1. Short GPIO14 (TX) and GPIO5 (RX) with a Dupont wire

  2. Open 1.UART.ino

6.2 Normal Phenomena

Open the Serial Monitor (115200 bps), printing every 2 seconds:

xxxxxxxxxx
[UART] UART Started, TX=GPIO14, RX=GPIO5
[UART] [TX] GOOD GOOD STUDY,DAY DAY UP!!!!!!
[UART] [RX] GOOD GOOD STUDY,DAY DAY UP!!!!!!

[UART] [TX] GOOD GOOD STUDY,DAY DAY UP!!!!!!
[UART] [RX] GOOD GOOD STUDY,DAY DAY UP!!!!!!

[UART] [TX] GOOD GOOD STUDY,DAY DAY UP!!!!!!
[UART] [RX] GOOD GOOD STUDY,DAY DAY UP!!!!!!

[UART] [TX] GOOD GOOD STUDY,DAY DAY UP!!!!!!
[UART] [RX] GOOD GOOD STUDY,DAY DAY UP!!!!!!

UART serial print

After disconnecting or removing the Dupont wire, the print becomes:

No connection print

6.3 Verification Methods

OperationExpected Result
Power on after shorting TX/RXTX and RX content are identical
Remove Dupont wireRX has no output
Change delay(2000) to delay(200)Transmit/receive frequency significantly increases

7. Common Issues

PhenomenonCauseSolution
RX has no outputTX/RX not shorted or poor contactCheck Dupont wire, confirm GPIO14→GPIO5
RX is all garbled .Baud rate mismatch or floating noiseConfirm both are 115200, check INPUT_PULLUP
INPUT_PULLUP ineffectiveSet after begin()Move pinMode before begin()
RGB LED Effects
I2C OLED Display

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文