Finding Serial Ports on a Linux Device

Content:

Serial ports on Linux are widely used to interface with hardware devices such as FTDI USB-to-serial adaptors, Arduino boards, and other peripherals. Identifying these ports and their associated mount points is important to ensure you are targeting the correct device.

While fairly straightforward, you need to know where to look to find them. This guide will take you through the steps to identify your serial device.

Serial Port Naming in Linux

In Linux, serial ports are typically represented as device files under /dev. Here’s how they are named:

  • Built-in serial ports are named /dev/ttyS[0-9].
  • USB-to-serial devices are named /dev/ttyUSB[0-9] or /dev/ttyACM[0-9].

For example, a serial port built-in to your motherboard may appear as /dev/ttyS0. Meanwhile, a USB-to-serial device (like FTDI or CP210x) may appear as /dev/ttyUSB0. The differing naming scheme makes it easier to find the device you’re looking for.

Detecting the Serial Hardware

If you’re using a USB-to-serial device, it should be listed under the lsusb command. This command lists USB devices connected to the system.

Bus 001 Device 004: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC

In this example, the USB-to-serial device is an FTDI FT232, which the system has detected. If your USB device does not show here, try plugging it in to another port. You will also need to check that any drivers, if required, are installed.

The dmesg command shows kernel messages, which include details about connected hardware. This will show where the device is connected.

dmesg | grep -i tty

Look for lines that mention ttyUSB or ttyACM. For example:

[ 1234.567890] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0

This indicates that the USB-to-serial device is mounted at /dev/ttyUSB0.

Testing the Serial Port

This optional step will test that you are able to connect to the serial port successfully. If you are trying to connect with other software, then feel free to skip this step.

To test the serial port, use a terminal program like screen or minicom. For example:

screen /dev/ttyUSB0 9600

Replace 9600 with the baud rate required by your device.

Permissions Issues

It’s likely that you will receive a permissions error when trying to access your serial device. If this occurs, it is possible to change the device permissions using chmod. For example:

chmod 777 /dev/ttyUSB0

This gives fully open access to the serial device mounted at /dev/ttyUSB0. This may seem a little unsafe, but will only last for as long as the system remains up, and the device remains connected.

Conclusion

With these steps, you can quickly identify and access serial ports for USB-to-serial devices on Linux. Tools like dmesg and lsusb make it straightforward to locate the device and its mount point. This knowledge is invaluable for debugging hardware connections and interfacing with devices on Linux systems.