You set up the system, uploaded the code, but only meaningless characters are flowing in the terminal... Or worse, nothing at all. Don't worry, 90% of UART problems stem from the 3 causes listed below.
In this chapter, we will learn how to make invisible signals visible.
If you see meaningless symbols like `` or RW¥å in the terminal, it means communication exists but there is no agreement.
- Baud Rate Mismatch (Most Common):
- If the transmitter sends at 9600 and the receiver listens at 115200, the data becomes garbage.
- Solution: Check the device datasheet or measure the speed with a Logic Analyzer (See: 4.3).
- Missing GND (Ground):
- If the grounds of the two devices are not connected, voltage levels "float". It becomes unclear whether a signal is 0 or 1.
- Solution: Immediately connect the GND pins of both devices with a jumper wire.
- Faulty Crystal:
- Cheap Arduino clones may have low-quality crystals, causing a frequency drift of more than 2%.
If nothing is flowing on the screen, the situation is more serious. There might be a hardware disconnection.
- TX-RX Not Crossed:
- Connecting TX -> TX and RX -> RX is the classic mistake. If two people talk at the same time, no one listens.
- Solution: Reverse the cables and try again.
- Voltage Level Error (RS232 vs TTL):
- If the sensor is RS232 (±12V) and you connected it directly to the ESP32 (3.3V), the ESP32 pin might be burnt.
- Bad Soldering / Contact:
- Jumper wires on the breadboard can sometimes be broken internally. Perform a "Short Circuit Test" (Buzzer) with a multimeter.
You have a "black box" device with no documentation. Only 3 wires come out (TX, RX, GND). What is its speed? What is the protocol? To find this out, a $5 Logic Analyzer (Saleae Clone) is a lifesaver.
- Connection: Connect the device's TX pin to CH1 of the Logic Analyzer, and GND to GND.
- Sampling: Open the Logic software (PulseView) and start recording at a high speed (e.g., 24 MHz).
- Measurement: Power cycle the device to force it to send data. You will see digital waves on the screen.
-
Analysis:
- Find the NARROWEST (shortest) pulse width. This is the duration of a single bit (
$T_{bit}$ ). - Formula:
$\text{Baud Rate} = \frac{1}{T_{bit}}$
- Find the NARROWEST (shortest) pulse width. This is the duration of a single bit (
Example: You measured the shortest pulse as 8.68 µs.
$1 / 0.00000868 = 115,207$ Congratulations! The device speed is 115200 Baud.
graph TD
subgraph SIGNAL [Signal Analysis]
P1[Pulse Width: 104 µs] --> R1[1 / 0.000104 = 9615] --> C1{Result: 9600 Baud}
P2[Pulse Width: 8.68 µs] --> R2[1 / 0.00000868 = 115207] --> C2{Result: 115200 Baud}
end
style C1 fill:#c8e6c9,stroke:#2e7d32
style C2 fill:#c8e6c9,stroke:#2e7d32
The colorful USB converters (CP2102, CH340, FTDI) we use to connect from PC to ESP32 can sometimes be fake.
- Fake FTDI Chips: Can become "bricked" (unusable) with a Windows update.
- 3.3V / 5V Jumper: Some converters have a tiny jumper for voltage selection. Ensure this is in the 3.3V position for ESP32. If you supply 5V, you might burn the module.
You are now a UART master. Here is your final checklist before going into the field:
- Is GND Connected? (The most critical item)
- Is TX -> RX connected? (Cross connection)
- Are Voltage Levels Equal? (3.3V <-> 3.3V)
- Is Baud Rate the Same? (9600, 115200...)
- Is Cable Distance Appropriate? (Max 50cm for TTL, 1km for RS485)