Connecting to the serial console on Linux does not require installing any drivers, but you may need to install screen using your package manager. You'll use a terminal program to find your board, and screen to connect to it. There are a variety of terminal programs such as gnome-terminal (called Terminal) or Konsole on KDE.

The tio program works as well to connect to your board, and has the benefit of automatically reconnecting. You would need to install it using your package manager.

What's the Port?

First you'll want to find out which serial port your board is using. When you plug your board in to USB on your computer, it connects to a serial port. The port is like a door through which your board can communicate with your computer using USB.

The easiest way to determine which port the board is using is to first check without the board plugged in. Open your terminal program and type the following:

ls /dev/ttyACM*

Each serial connection shows up in the /dev/ directory. It has a name that starts with ttyACM. The command ls shows you a list of items in a directory. You can use * as a wildcard, to search for files that start with the same letters but end in something different. In this case, You're asking to see all of the listings in /dev/ that start with ttyACM and end in anything. This will show us the current serial connections.

In the example below, the error is indicating that are no current serial connections starting with ttyACM.

Now plug in your board. In your terminal program, type:

ls /dev/ttyACM*

This will show you the current serial connections, which will now include your board.

A new listing has appeared called /dev/ttyACM0. The ttyACM0 part of this listing is the name the example board is using. Yours will be called something similar.

Connect with screen

Now that you know the name your board is using, you're ready connect to the serial console. You'll use a command called screen. You may need to install it using the package manager.

To connect to the serial console, use your terminal program. Type the following command, replacing board_name with the name you found your board is using:

screen /dev/tty.board_name 115200

The first part of this establishes using the screen command. The second part tells screen the name of the board you're trying to use. The third part tells screen what baud rate to use for the serial connection. The baud rate is the speed in bits per second that data is sent over the serial connection. In this case, the speed required by the board is 115200 bits per second.

Press enter to run the command. It will open in the same window. If no code is running, the window will be blank. Otherwise, you'll see the output of your code.

Great job! You've connected to the serial console!

Permissions on Linux

If you try to run screen and it doesn't work, then you may be running into an issue with permissions. Linux keeps track of users and groups and what they are allowed to do and not do, like access the hardware associated with the serial connection for running screen. So if you see something like this:

then you may need to grant yourself access. There are generally two ways you can do this. The first is to just run screen using the sudo command, which temporarily gives you elevated privileges.

Once you enter your password, you should be in:

The second way is to add yourself to the group associated with the hardware. To figure out what that group is, use the command ls -l as shown below. The group name is circled in red.

Then use the command adduser to add yourself to that group. You need elevated privileges to do this, so you'll need to use sudo. In the example below, the group is adm and the user is ackbar.

After you add yourself to the group, you'll need to logout and log back in, or in some cases, reboot your machine. After you log in again, verify that you have been added to the group using the command groups. If you are still not in the group, reboot and check again.

And now you should be able to run screen without using sudo.

And you're in:

The examples above use screen, but you can also use other programs, such as putty or picocom, if you prefer.

This guide was first published on Dec 19, 2017. It was last updated on 2021-12-01 16:32:33 -0500.

This page (Advanced Serial Console on Linux) was last updated on Dec 09, 2021.

Text editor powered by tinymce.