Sub topic 14
Fixing garbled text, missing ports, and silent monitors
This chapter assumes you can upload a sketch, call Serial.begin(), and open the Serial Monitor in the Arduino IDE. It also assumes you have read the earlier chapters on baud rates, print/println, and serial buffers. Here you will learn to sort serial problems into three groups, and to find the cause of each one in a fixed order.
Sort the symptom first
Almost every serial problem falls into one of three groups. Each group points to a different part of the chain from your sketch to your screen.
| Symptom | Where the fault usually is |
|---|---|
| Garbled characters such as `ÿ□□x` | A mismatch between the two ends of the link (baud rate, board clock, line settings) |
| No port listed, or upload fails | The USB path: cable, driver, board, or another program holding the port |
| Port is available but the monitor is empty | The sketch (no `Serial.begin`, wrong pins, crashed or blocked code) or the monitor settings |
Sorting first saves time. Changing the baud rate will not bring back a port that is missing, and reinstalling a driver will not fix a sketch that never prints.
Garbled text
Garbled text means bytes arrive, but the receiver reads them with the wrong timing. That is a good sign. The wiring and driver work, and only the settings are off.
Baud rate mismatch
The most common cause is a different speed on each side. The sketch sets one rate and the monitor listens at another. Take this sketch:
void setup() {
Serial.begin(115200);
Serial.println(F("Hello, serial"));
}
void loop() {
Serial.println(millis());
delay(1000);
}If the monitor's baud menu (bottom right) says 9600, you will see random symbols. Change the menu to 115200. You do not need to re-upload, because the monitor only changes how it reads the incoming bits. Some boards reset when the monitor reopens at a new rate, and that is normal.
Two habits prevent most mismatches:
- Keep the number in
Serial.begin()and the monitor menu equal every time you change either one. - Pick one default rate (for example 115200) for your projects, and write it in a comment near
Serial.begin().
Wrong clock on the board
If the rates match and the text is still garbled, the board's timing may be off. UART timing comes from the board's clock. An AVR board running on its internal oscillator, or with the wrong clock setting in the board menu, produces bit times that do not match. This shows up with:
- A bare ATmega chip or a clone using a different crystal than the selected board assumes.
- A 3.3 V / 8 MHz board (such as a Pro Mini) uploaded as a 5 V / 16 MHz board. Everything runs at half speed and the text is garbled.
The fix is to select the board variant that matches the real hardware under Tools > Board (and the processor or clock options if shown). A quick test is to lower the rate to 9600. Lower rates tolerate timing error better, so readable text at 9600 and garbage at 115200 suggests a clock problem.
Other causes of broken text
- Another device on pins 0 and 1. On an Uno,
Serialshares the pins labeled RX and TX with the USB chip. A shield or wire on those pins can corrupt the data. Disconnect it and try again. - Binary data in a text monitor.
Serial.write(200)sends the raw byte 200, which the monitor shows as a symbol. UseSerial.print(200)to send the digits. - Text interleaved with other output. If two parts of your code print at once (for example, from an interrupt), lines mix. Print from one place only.
- Boot messages. Some boards print their own start-up text at a different rate, for example ESP8266 boards at 74880 baud. A burst of garbage right after reset, followed by clean text, is expected. You can ignore it.
Line ending confusion
A related problem looks like broken output but comes from the line-ending menu next to the baud menu. It matters when you send data to the board:
- No line ending: only your typed characters are sent.
- Newline: adds
\n. - Carriage return: adds
\r. - Both NL & CR: adds
\r\n.
If a command such as 1 is read as an unknown command, the extra \n or \r is probably reaching your code. The command sketch from the earlier chapter ignores both characters for this reason. When you parse longer input, decide which ending you expect and handle the others.
Missing ports
If Tools > Port is greyed out, empty, or does not show your board, the computer is not seeing the USB device. Work from the cable toward the software.
- Use a data cable. Many cables only carry power. If a cable charges a phone but your board never appears, swap it for another before doing anything else.
- Connect directly. Try a different USB port on the computer and skip hubs.
- Check the board. The power LED should be lit. If it is not, the board is not powered or is damaged.
- Unplug and replug. Look at the port list while you do so. A new entry should appear when the board connects. If nothing changes, the computer is not detecting it.
- Install the driver if needed. Genuine Uno boards work out of the box on current systems. Many clones use a CH340 or CP210x USB chip, which may need a driver on some systems. Check the chip printed on the board.
- Check permissions on Linux. The port (for example
/dev/ttyACM0) is owned by a group such asdialout. If your user is not in that group, the IDE cannot open it. Add yourself withsudo usermod -a -G dialout $USER, then log out and back in.
The port is there but busy
An error such as "port busy" or "access denied" means another program has the port open. Only one program can use a serial port at a time. Close any other Serial Monitor windows, a second IDE instance, a plotter, or a terminal program (see the chapter on other terminals). Then try again. The same problem blocks uploads, so if an upload fails with a port error while the monitor is open, close the monitor and retry.
Boards that vanish while the sketch runs
Boards with native USB (Leonardo, Micro, and many ARM boards) are different from the Uno. The USB connection is handled by the main chip. If your sketch crashes, resets, or puts the chip into a sleep mode, the port disappears and reappears, sometimes with a new name. Two practical consequences:
- After an upload, the port may change. Select it again if the monitor shows nothing.
while (!Serial);insetup()waits for the monitor to open. That is useful on native USB boards so you do not miss early messages. On a board that never opens the monitor, it blocks forever.
Silent monitors
Here the port exists and the monitor opens, but no text appears. Check these in order.
- Is the sketch uploaded? Look for "Done uploading" in the IDE. A failed upload leaves the old sketch running.
- Is
Serial.begin()called insetup()? Without it, nothing is sent. The compiler does not warn you. - Is the correct port selected? With several boards connected, the monitor may be attached to the wrong one.
- Is the monitor connected to the same port as the upload? Close and reopen it.
- Is the output scrolled or paused? Check that autoscroll is on.
- Did the board reset after the monitor opened? On most AVR boards, opening the monitor resets the board, so a message printed once in
setup()appears right when the window opens. If you open the monitor late on a native USB board, you may miss it. Print a status line inloop()while debugging. - Is the sketch stuck before it prints? A blocking call, such as a
whilethat waits for a sensor, stops everything after it. Add a print before and after the suspect line to find where it stops.
A minimal test sketch separates hardware problems from code problems:
void setup() {
Serial.begin(9600);
Serial.println(F("Setup complete"));
}
void loop() {
Serial.println(millis());
delay(1000);
}If this prints a number every second, the board, cable, driver, and monitor all work, and the fault is in your own sketch. If it does not, the problem is in the link or the board.
Silent because of sketch behaviour
If the minimal test works but your sketch is silent, look for these:
- Pins 0 and 1 used as I/O.
pinMode(1, OUTPUT)ordigitalWrite(0, ...)takes over the serial pins on an Uno. - Wrong serial object. On boards with several UARTs (Mega, many ARM and ESP32 boards),
Serialmay not be the one connected to USB. Boards with native USB may expose it asSerialUSB. Check the board's documentation. - Memory exhaustion. Many long string literals can use up the Uno's 2 KB of RAM, so the sketch misbehaves or restarts without printing. Wrap constant text in
F()as described earlier. - Output that is too large. Printing faster than the link can send blocks
Serial.printonce the buffer fills. Lower the print rate or raise the baud rate. - Resets in a loop. If you see the setup message repeating, the board is restarting. Causes include a power problem, a watchdog, or a crash. Printing a counter that you keep in
setup()can confirm it.
A checklist you can reuse
- Does the board appear in Tools > Port? If not, work on cable, driver, and permissions.
- Does the minimal test sketch print? If not, work on the board and upload.
- Do the sketch and monitor baud rates match? If the text is garbled, fix this first.
- Is the board variant correct? If 9600 works and 115200 does not, suspect the clock.
- Does your own sketch call
Serial.begin()and avoid pins 0 and 1? - Is anything else holding the port?
Exercise
Your sketch calls Serial.begin(115200). The Serial Monitor is set to 9600 and shows random symbols. You change the monitor to 115200 and the text is readable. Later, you move the same sketch to a Pro Mini that is set up as a 5 V / 16 MHz board in the IDE but is actually a 3.3 V / 8 MHz board. The text is garbled again, even with both rates at 115200. What is the likely cause, and what is the first thing you try?
Show answer
The board runs at 8 MHz but the sketch was compiled for 16 MHz, so every bit lasts twice as long as the code expects, and the baud rate does not match the real timing. Select the correct board variant (3.3 V / 8 MHz) under Tools > Board or Processor and upload again. As a quick check, a lower rate such as 9600 may also give readable text.
Exercise
The IDE shows "Done uploading", the port is selected, and the Serial Monitor is empty. List three things you check, in order, to find the cause.
Show answer
First, confirm that Serial.begin() is called in setup() and that the monitor baud rate matches it. Second, upload a minimal sketch that prints millis() every second. If it prints, the hardware is fine and the fault is in your sketch (for example, pins 0 and 1 used as I/O, or the code blocked before the first print). Third, if the minimal sketch is also silent, check the port selection and whether another program holds the port, then the cable and board.