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.
Linux Serial Port Terminal Programs
-
tiois a nice terminal program that works properly. You can install it using your package manager. - VSCode has a number of serial port extensions, such as Serial Monitor.
- PyCharm has a Serial Port Monitor plugin.
Connect with tio
Now that you know the name your board is using, you're ready connect to the serial console. Install tio using your package manager..
ype the following command, replacing ttyACMx with the name you found your board is using:
tio /dev/ttyACMx
This will connect to the serial port and display a header like this:
$ tio /dev/ttyACM0 [11:07:00.578] tio v2.7 [11:07:00.578] Press ctrl-t q to quit
Permissions on Linux
If you try to run tio and it doesn't work, then you may be running into an issue with permissions. Your Linux distribution may not allow access to serial ports by defaut. You may see something like this; note the "permission denied".
[11:13:42.754] tio v2.7 [11:13:42.754] Press ctrl-t q to quit [11:13:42.754] Warning: Could not open tty device (Permission denied) [11:13:42.754] Waiting for tty device..
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.
$ sudo tio /dev/ttyACM0 [sudo] password for smith:
Once you enter your password, you should be in:
The second way is to add yourself to the user 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.
On Debian-based distributions, such as,Ubuntu the group will be dialout, not adm.
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:
Page last edited June 21, 2024
Text editor powered by tinymce.