In this blog post we will learn how to connect to a Raspberry PI via UART
(think serial terminal).
Before we begin we need to get a cheap
USB <-> UART converter.
Make sure that the converter supports 3.3V voltage.
Most of the converters support other voltages e.g. 5V and you
can select which voltage you want by moving a jumper.
If your converter has such a jumper make sure that it is in 3.3V position.
Although converters can have from four up to six pins, we will only need three: GND, RXD and TXD. We should connect RXD pin on the converter to TXD pin on the Raspberry PI and similarly TXD pin to the Raspberry’s RXD pin (crossover). We also need to connect the converter GND pin to Raspberry’s Ground pin. Do NOT connect VCC (or VCCIO) pin, we only need three wires. You can find the Raspberry PI pinout in the official docs: https://www.raspberrypi.org/documentation/usage/gpio/ - look at the five top left pins, the first two are +5V, then we have Ground, TXD and RXD pins.
Next thing that we need to do is to enable UART support in Raspbian, which for
security reasons is disabled by default.
We need to change
config.txt file on the
on the Raspberry PI SD card. We need to add
[pi4] section (or at the end of the file if the section is not present).
When we connect the converter to both Raspberry PI and the computer it should
be recognized by the system and a new device named
ttyUSBn (where n is a number e.g.
should appear under
As always with all things hardware
dmesg is your friend, so you can either
dmesg | tail -n 100 or
dmesg | grep tty to find out what exactly device was created and if there where any problems.
On my system I saw the following messages:
There are a lot of different programs on Linux that you can use to open a session.
We will concentrate on only two of them,
putty which is a GUI tool and
screen which is a pure command line utility.
Let’s start with
putty, first we need to configure it to read from
To avoid putting this info every time, when you want to connect we should save it as an profile (put a name and click Save button).
It is also worth checking other settings like the font, keyboard or the default terminal size:
OK its time to test our configuration. Open putty and load previously saved profile, click Open and restart Raspberry PI. You should be able to see boot messages. Try pressing Enter if the console appears to hang.
After we login it is easy to notice that there is no color support out of the box (at least on Raspbian Lite). This can be easily changed by selecting a different terminal type in the terminal session:
Another problem is that we are stuck with a fixed terminal size.
If your Raspberry PI has xterm package installed (not available on Lite version)
you can use
resize command after you resize putty’s window.
Otherwise you may use this script created by @pkh
Just copy and paste this code into the session and then enter
resize (use Ctrl+Shift+Insert to paste in
resize, commands like
htop should occupy the entire terminal window.
After resize becomes:
You may want to add both the
resize function and
TERM environment variable to
to avoid copy-pasting them every time.
If you don’t use GUI at all you may use
screen was designed to work with SSH sessions,
it helps you keep your programs running even after you end your SSH connection.
Most people these day use
tmux as a modern alternative, unfortunately
tmux does not
support serial communications so we are stuck with
screen (which TBH I am not very familiar with).
screen using the following command:
To exit screen (which is on the same level of difficultly as exiting Vim) press Ctrl+A followed by \ (yup backslash). A question will appear at the left bottom of the screen, answer y.
screens window appears blank, press enter to reprint the prompt.
For some reason programs like
htop tend to look worse under
(assuming that you set
TERM variable and did
resize). Probably I am missing some extra setup,
nevertheless they are usable.
Last but not least, for fans of ancient
if you want to connect via
remember to disable “Hardware Control Flow” option
(they use RTS and CTS lines present on some converters that we do not use).