Creating persistent USB device names on a Raspberry Pi

If you use multiple USB devices that for example create device names like /dev/ttyUSB0, /dev/ttyUSB1 and so on, you probably want to assign device names that are more descriptive. On Linux (and thus on an Raspberry Pi) you can do this by writing an udev rule. Udev is a device event handler, so when you plugin your USB device it will be seen by udev and will create device names according the ruleset.

I have two devices that I like to have a device name that are persistent. A Xbee/Zigbee Xstick from digi.com and an USB FTDI serial cable. Normally on a Linux system, you use the command ‘udevadm info’ to get the information you need to specify in the config file, but on the RPi ‘udevadm info’ results in a kernel panic, so use the commands ‘lsusb -v’ and ‘usb-devices’ to get the information you need.

Create a file /etc/udev/rules.d/99-usbdevices.rules with the following content:

ATTRS{idVendor}==”0403″, ATTRS{idProduct}==”6001″, ATTRS{product}==”XStick”, SYMLINK+=”zigbee”
ATTRS{idVendor}==”0403″, ATTRS{idProduct}==”6001″, ATTRS{serial}==”A6WGT0NS”, SYMLINK+=”smartmeter”

And restart udev and trigger pulling the devices:

sudo /etc/init.d/udev reload
sudo udevadm trigger

After that you should have links with the names you specified pointing to the real devices

$ ls -l /dev/zigbee /dev/smartmeter
lrwxrwxrwx 1 root root 7 Jul 30 21:02 /dev/smartmeter -> ttyUSB0
lrwxrwxrwx 1 root root 7 Jul 30 21:02 /dev/zigbee -> ttyUSB1

From now you can reference /dev/smartmeter instead of /dev/ttyUSB0 or some other number.

Leave a Reply

Your email address will not be published. Required fields are marked *