I'm using a Raspberry Pi running Raspian to control some home automation hardware. One piece of hardware speaks over RS232, so it connects to my RPi using a USB-to-RS232 adapter. Another connects over USB, but emulates a serial port.

When I'm only using one piece of hardware, everything is fine: I just tell my software to use /dev/ttyUSB0 and it's all good.

The problem is when I connect both at the same time. One device shows up as ttyUSB0 and one as ttyUSB1, which is fine, but on every reboot it's essentially random which hardware device will get assigned to which device file, despite not even unplugging them from the RPi.

Every so often after a reboot, I find that the control software is confused because it's talking to the wrong device. Is there a way I can "hard-code" a device to a device file?

2 Answers 2


For serial devices you should find them named by topology under /dev/serial/by-path/, so if you use the same usb hubs and ports it should stay constant. Eg:

ls -l /dev/serial/by-path/pci-0000:04:00.0-usb-0:2.1.1:1.0-port0
... /dev/serial/by-path/pci-0000:04:00.0-usb-0:2.1.1:1.0-port0 -> ../../ttyUSB0

Similarly, you should find the devices by name, sometimes including the serial number, under /dev/serial/by-id/, eg:

 ls -l /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A5771WOA-if00-port0
 ... /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A5771WOA-if00-port0 -> ../../ttyUSB0

You can use udev rules for this. A udev rule can match a USB device by its serial number, and lets you create an alternative name for the device in /dev.

A udev rule like this should suffice to create a symlink in /dev pointing to the real device node:

SUBSYSTEM=="usb", ATTRS{serial}=="<serial number>", SYMLINK+="USBserial1"

See Writing udev rules by Daniel Drake for the details.

  • +1. note that some (many) manufacturers, esp. of cheap USB devices, dont put a unique serial number in each unit, so the serial attribute is just the device's name or the same number for each one.
    – cas
    Jul 31, 2017 at 10:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .