This PlatformIO project tests the round trip serial communication speed between a host computer and an ESP32 microcontroller.
- ESP32 Firmware: Responds to ping commands with precise timing measurements
- Python Test Script: Measures round trip times from the host computer
- Statistics Tracking: Both ESP32 and host-side performance metrics
- Configurable Parameters: Baud rate, payload size, test count
- Real-time Monitoring: Built-in LED indicates activity
- ESP32 development board (ESP32-DevKit, NodeMCU-32S, etc.)
- USB cable for programming and serial communication
- Computer with Python 3.6+ installed
- PlatformIO (VS Code extension or CLI)
- Python 3.6 or higher
pyseriallibrary (see requirements.txt)
# Clone or download this project
cd test-esp-serial-round-trip
# Build and upload firmware using PlatformIO
pio run --target upload
# Optional: Monitor serial output
pio device monitor# Install required Python packages
pip install -r requirements.txt# List available serial ports
python test_serial_speed.py --list-ports# Run 100 tests with default settings
python test_serial_speed.py --port /dev/ttyUSB0
# On Windows
python test_serial_speed.py --port COM3# Custom test parameters
python test_serial_speed.py \
--port /dev/ttyUSB0 \
--baud 115200 \
--tests 1000 \
--size 50 \
--delay 0.005
# Test different baud rates
python test_serial_speed.py --port /dev/ttyUSB0 --baud 921600--port, -p: Serial port device (required)--baud, -b: Baud rate (default: 115200)--tests, -n: Number of tests to run (default: 100)--size, -s: Data payload size in characters (default: 10)--delay, -d: Delay between tests in seconds (default: 0.01)--list-ports, -l: List available serial ports
The ESP32 firmware supports several commands via serial terminal:
PING <data>- Echo back data with timing informationSTATS- Show performance statisticsRESET- Reset statistics countersSPEED <baud>- Change baud rate dynamically
ESP32 Serial Round Trip Speed Test
===================================
Commands:
PING <data> - Echo back the data with timing
STATS - Show performance statistics
RESET - Reset statistics
SPEED <baud> - Change baud rate
Ready for commands...
PING hello
PONG hello TIME:45 us
STATS
=== Performance Statistics ===
Total messages: 150
Average time: 42 us
Min time: 38 us
Max time: 67 us
Current baud rate: 115200
Typical performance on ESP32 at 115200 baud:
- Round trip time: 2-10ms (depends on payload size and host system)
- ESP32 processing time: 40-100 microseconds
- Throughput: 100-500 messages/second
- Effective data rate: 8-40 kbps (much lower than baud rate due to protocol overhead)
- Baud Rate: Higher rates reduce transmission time
- Payload Size: Larger payloads increase transmission time linearly
- Host System: USB latency varies between systems
- USB-to-Serial Converter: Different chips have different latencies
- Operating System: Serial port drivers affect performance
-
Permission Denied (Linux/macOS)
sudo usermod -a -G dialout $USER # Log out and back in
-
Port Not Found
- Check cable connection
- Verify ESP32 is powered on
- Use
--list-portsto find correct port
-
Upload Failed
- Hold BOOT button while uploading
- Check that no serial monitor is open
- Try different USB cable/port
-
Poor Performance
- Try higher baud rates (230400, 460800, 921600)
- Reduce delay between tests
- Check for USB hub latency
- Host → ESP32 transmission: Depends on baud rate and payload size
- ESP32 processing: Usually 40-100 microseconds
- ESP32 → Host transmission: Same as step 1
- Host USB latency: 1-16ms depending on system
- Use higher baud rates (921600 works well on ESP32)
- Minimize payload size for latency testing
- Use dedicated USB-to-Serial converters instead of built-in ones
- Test on different host systems to compare USB stack performance
test-esp-serial-round-trip/
├── platformio.ini # PlatformIO configuration
├── src/
│ └── main.cpp # ESP32 firmware
├── test_serial_speed.py # Python test script
├── requirements.txt # Python dependencies
└── README.md # This file
This project is open source and available under the MIT License.