Udev rules file for Arduino boards

From Wirespeed

Jump to: navigation, search

After connecting the Franzis board, only root can access it. This article describes how to make the board board available to unprivileged users. Also, reconnecting more than one device may result in changing ttyUSBn identifiers. To solve this, I created a file: /etc/udev/rules.d/60-persistent-serial.rules which assigns uniquely named symlinks. For this to work I assigned each of my Arduino's a unique three digit number, always starting with '0'.

ACTION!="add", GOTO="persistent_serial_end"
SUBSYSTEM!="tty", GOTO="persistent_serial_end"
KERNEL!="ttyUSB[0-9]*", GOTO="persistent_serial_end"

# This is old 11.10 style: IMPORT="usb_id --export %p"
IMPORT{builtin}="path_id"
ENV{ID_SERIAL}=="04fc_RS232C_to_USB_Adapter"    , SYMLINK="multimeter"                                       , OWNER="jhendrix"
ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A800FERY" , SYMLINK="arduinoMega1280-001"       , SYMLINK+="ttyUSB001" , OWNER="jhendrix"
ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A900F4EF" , SYMLINK="arduinoMega1280-002"       , SYMLINK+="ttyUSB002" , OWNER="jhendrix"
ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A900f3Kr" , SYMLINK="arduinoDuemilanove168-003" , SYMLINK+="ttyUSB003" , OWNER="jhendrix"

LABEL="persistent_serial_end"
  • Where jhendrix must be replaced by your username;
  • The name for SYMLINK can be pretty much anything you like;
  • Where ID_SERIAL can be obtained through:
unbuffer udevadm monitor --environment | grep 'ID_SERIAL='

Activate the new rules file by issuing the following command:

sudo udevadm control --reload

After connecting, a device called /dev/ttyUSBn is created which has r/w privileges for user jhendrix and a symlink with a descriptive name to it.

The result when connecting more than one ttyUSB-type device:

lrwxrwxrwx 1 root     root         7 2012-04-06 14:38 /dev/arduinoDuemilanove168-003 -> ttyUSB0
lrwxrwxrwx 1 root     root         7 2012-04-06 14:44 /dev/arduinoMega1280-001 -> ttyUSB1
lrwxrwxrwx 1 root     root         7 2012-04-06 14:46 /dev/arduinoMega1280-002 -> ttyUSB2
lrwxrwxrwx 1 root     root         7 2012-04-06 14:47 /dev/multimeter -> ttyUSB3
lrwxrwxrwx 1 root     root         7 2012-04-06 14:38 ttyUSB001 -> ttyUSB1
lrwxrwxrwx 1 root     root         7 2012-04-06 14:46 ttyUSB002 -> ttyUSB2
lrwxrwxrwx 1 root     root         7 2012-04-06 14:46 ttyUSB003 -> ttyUSB0
crw-rw---- 1 jhendrix dialout 188, 0 2012-04-06 14:38 /dev/ttyUSB0
crw-rw---- 1 jhendrix dialout 188, 1 2012-04-06 14:44 /dev/ttyUSB1
crw-rw---- 1 jhendrix dialout 188, 2 2012-04-06 14:46 /dev/ttyUSB2
crw-rw---- 1 jhendrix dialout 188, 3 2012-04-06 14:47 /dev/ttyUSB3

Because ttyUSB device names in the form 0[0-9][0-9] (notice the leading 0) are never assigned by the kernel, it is safe create these as symlinks. The good thing is that the Arduino IDE / Processing accepts them as valid interfaces. Just remember to select the three digit ttyUSB0nn form in the IDE when programming Arduino.

Personal tools