This project implements a transparent bridge between a hardware Serial (UART) port on an ESP32 and a TCP socket over WiFi. It includes a desktop Python script to discover the bridge and map the network connection to a local Virtual Serial Port (e.g., using com0com on Windows).
- Automatic Discovery: The desktop script finds ESP32 bridges on the local network via UDP broadcast.
- Transparent Bridging: Bidirectional data transfer between ESP32 UART and a TCP client.
- Configurable: WiFi, UART settings, and Port configuration via text files on the ESP32.
- Robust: Handles reconnections and errors gracefully.
mpy/: MicroPython firmware and configuration files for the ESP32.desktop/: Python script to run on your PC to interface with the bridge.
- ESP32 development board.
- MicroPython firmware flashed to the specific device.
- A tool to upload files to ESP32 (e.g., Thonny,
ampy, orrshell).
Create the following files in the mpy/ folder (or edit the provided samples) and upload them to the root of your ESP32.
-
wifi.config(WiFi Credentials)- Create a text file with two lines:
YOUR_WIFI_SSID YOUR_WIFI_PASSWORD -
uart.config(Hardware Configuration)- Key-value pairs for UART and TCP settings:
UART_ID=2 UART_BAUD=115200 UART_TX=17 UART_RX=16 TCP_PORT=8888 NEOPIXEL_PIN=48
- Adjust
UART_TX,UART_RX, andNEOPIXEL_PINaccording to your board's pinout.
-
webrepl_cfg.py(Optional Remote Access)- To enable WebREPL:
PASS = 'your_webrepl_password'
- Upload
boot.py,main.py,wifi.config,uart.config, andwebrepl_cfg.pyto the ESP32. - Reset the board. The LED (if configured) will indicate connection status.
- ESP32 S3 or similar board which runs micropython.
- (Optional, see connection details below) 12V to 5V DC Voltage convertor.
We need to connect the ESP32 to the controller SOC device (Arduino Nano) we want to control via UART. The ESP32 will act as a bridge between the device and the WiFi network. The onboard UART-USB chip will not work and the direct serial link WILL work fine.
If you want to use only a 12V voltage source, we can use a DC2DC Voltage convertor module as the one in the picture to provide 5V voltage to both the controller SOC and the ESP32.
The circuits we need are shown in the picture below.
Basicly, we need the following connections:
- Arduino Nano D1 TX to ESP32 RX (PIN17)
- Arduino Nano D0 RX to ESP32 TX (PIN16)
- 12V Power+ to DC2DC Voltage convertor module IN+
- GND to DC2DC Voltage convertor module IN-(GND), from Arduino Nano GND
- DC2DC Voltage convertor module OUT 5V+ to Arduino Nano 5Vin
- DC2DC Voltage convertor module OUT 5V+ to ESP32 5Vin
- DC2DC Voltage convertor module OUT-(GND) to ESP32 GND
Use only 12V power supply for the whole system, you don't want 2 USB power supplies in the same system. But as the ESP32 has diodes on USB Type-C connectors, it may be safe to plug in a USB 5V Power to ESP32 even when the 12V power supply is connected.
If you don't have a 12V to 5V DC converter, simply omit connections 3~7, but link 5V+ of Arduino Nano to 5V+ of ESP32, and GND of Arduino Nano to GND of ESP32. Plug in a USB 5V Power to any one of them to run the system.
Final wiring example:
- Python 3.x installed.
- Virtual Serial Port Driver (Windows):
- Download and install com0com.
- This allows you to create a pair of virtual COM ports (e.g.,
COM20<->CNCB0).
- Navigate to the
desktop/directory. - Install dependencies:
(Note:
pip install -r requirements.txt
pyserialis the main requirement)
If you don't know the IP address of your ESP32, run the script without arguments:
python desktop/bridge.pyOutput:
No serial port provided. Performing discovery only...
Searching for ESP32 Bridge (AppID: *)...
Found Bridge at 192.168.1.50: Port=8888, Magic=default
Discovery Successful:
Target: 192.168.1.50:8888
Target IP: 192.168.1.50
Target Port: 8888
- Go to settings of the APP
- Find Connection mode and set to TCP/telnet
- Use the discovered IP and Port to connect
-
Setup com0com:
- Open
Setup Command Promptfor com0com. - Create a pair:
install PortName=COM4 PortName=COM5 - Close the setup.
COM4is for this bridge script.COM5is for your target application (e.g., Serial Monitor, flashing tool).
- If you can't find/error out at the virtual COMs in the following steps, please refer to the trouble shooting section.
- Open
-
Run the Bridge: Replace
COM4with your chosen virtual port:python desktop/bridge.py COM4
The script will automatically discover the ESP32 and start bridging.
Configuration Options:
- Specify Baud Rate:
python desktop/bridge.py COM4 --baud 115200 - Specify Target IP (skip discovery):
python desktop/bridge.py COM4 --target-ip 192.168.1.50 - Verbose Logging:
python desktop/bridge.py COM4 -v
- Specify Baud Rate:
-
Connect your Application:
- Open your target application (e.g., PuTTY, Arduino IDE).
- Connect to the other end of the virtual pair (e.g.,
COM5if you usedCOM4for the bridge). For the above example, connect to COM5 in your app such as LaserGRBL.
- The data will now flow:
`App <-> COM5 <-> COM4 <-> bridge.py <-> WiFi <-> ESP32 <-> UART Device`
- No Bridge Found: Ensure ESP32 is powered on and connected to the same WiFi network. Check
mpy/uart.configfor the correctTCP_PORT. - Serial Errors: Check if
com0comdrivers are signed (or use the signed version). Verify baud rates match your device. If com0com doesn't work right in your Windows 10/11, try to disable Secure Boot in your UEFI/BIOS and reboot. Or, try other virtual serial solutions with proper signature for secure boot support. - Connection Drops: The ESP32 server handles one client at a time. Ensure no other script is connected.
The ESP32 onboard NeoPixel LED (if configured) provides visual feedback:
- Blue Blinking: Initialization / Connecting to WiFi.
- Red Blinking: Error state (e.g., WiFi connection failed).
- Orange Flash (Briefly every 5s): Ready, waiting for connection.
- Green Flash (Briefly every 5s): Client Connected.





