Assigning Static Device Names for USB Serial Devices (Including Arduinos)

I posted this on G+, but figured I’d post here as well with a little more depth.
I was working on a processing sketch that needs to communicate with several USB Serial devices (mostly Arduinos).  To make my life easier I wanted to find a way to make sure I could identify each one every time by the location of the port in the filesystem, which meant a static name for each.  This setup will give you the same name for the device in /dev every time you connect it.  This is particularly helpful if you have lots of devices to manage or want to hard-code a path to the port into a script or application (but only one that will only be running on your local machine).
This information is courtesy of this post on persistent names for usb serial devices.
While I highly recommend the post linked above, I’ll boil down the information in the hopes that it’s a little more straightforward.

Step 1:

Find the device id, vendor id, and product id.  The easiest way to do this is to connect the device, then immediately run ‘dmesg’ on the command line.

Near the end of the output will be the events corresponding to the connection of your device.  There should be a lines that look something like these, not necessarily next to each other:

usb 2-4: SerialNumber: A6008isP

usb 2-4: New USB device found, idVendor=0403, idProduct=6001

The format of the serial number will vary with the device, it may be long or short, may be purely numeric, hex, or alphanumeric, and could include dashes or other characters.

Step 2:

Create a new file: /etc/udev/rules.d/99-usb-serial.rules

The name of the file can be changed if you like, but it must start with a two digit number (higher is better so it takes a lower priority than other rules) and must end with ‘.rules’.

Put the following line into the file for each device (on a single line:

SUBSYSTEM==”tty”, ATTRS{idVendor}==”0403″, ATTRS{idProduct}==”6001″, ATTRS{serial}==”A6008isP”, SYMLINK+=”arduino”

Replace 0403 with your vendor ID and 6001 with your product id if different from above.  You will always need to replace the serial number, substituting yours for A6008isP shown above.

The last part, the value given to SYMLINK is the name that will be given to the device.  This will show up in /dev.  You can also specify a directory to put the link in, such as “arduinos/blinky” which would create the link to the device at /dev/arduinos/blinky .

Once this file is saved, unplug and replug your device and it should show up as a link where you specified in the udev rules file.  HAZAA!

Leave a Reply