This post has to objective to be able to rename a Zolertia device on a UNIX system this allows to manage multiple devices easily. After the configuration, each time we connect a specific device, it we appear with the same name and not change following the order of discovery. To rename USB devices we need to have some information about each of them. The command “udevadm” allows to get theses informations.
udevadm info -a /dev/ttyUSB0 udevadm info -a /dev/ttyUSB0 | grep "ATTRS{serial}==\"Z"
The second command filter the result to get only the line starting by "ATTRS{serial}==\"Z"
(Our devices are from Zolertia).
Next we will use the command udev
to create rules that rename the USB device. These rules will be placed in the file /etc/udev/rules.d/10-local.rules
on Debian or /etc/udev/rules.d/10-usb-serial.rules
on Raspberry pi.
The following command could help to create/edit/remove the files.
sudo rm /etc/udev/rules.d/10-usb-serial.rules sudo touch /etc/udev/rules.d/10-usb-serial.rules sudo vi /etc/udev/rules.d/10-usb-serial.rules
Vim is not easy to use for the first time. Escape follow by :w
will save the file and Escape follow by:q
will escape vim. If you have forgotten to lunch vim with the root access you can type :qa!
to exit the program.
Finally, the command to rename the USB port is like this
SUBSYSTEM=="tty", ATTRS{product}=="Zolertia Firefly platform", ATTRS{serial}=="ZOL-B001-A200002005", SYMLINK+="anchor1", GROUP="dialout", MODE="0666"
SUBSYSTEM=="tty", ATTRS{product}=="Zolertia Firefly platform", ATTRS{serial}=="ZOL-B001-A200002005"
are used to identify a specific USB device.SYMLINK+="anchor1"
add a symbolic links which act as alternative names for the device node.GROUP="dialout", MODE="0666"
add the device the dialout group with 666 access.
If your user is not in the dialout group you can add this user to it using the useradd -G dialout username
command.
If you have some problems, you can take a look at the journal of the Raspberry pi to check for errors sudo journalctl -xe
. For Example, in our case we have connected to much USB devices to the raspberry pi and we have encounter theses errors:
Jan 28 12:17:56 raspberrypi kernel: xhci_hcd 0000:01:00.0: Error while assigning device slot ID Jan 28 12:17:56 raspberrypi kernel: xhci_hcd 0000:01:00.0: Max number of devices this xHCI host supports is 32. Jan 28 12:17:56 raspberrypi kernel: usb 1-1.3.6.4.1-port4: couldn't allocate usb_device
If you restart our Raspberry pi, may be you will have some problems for example our device redirect bus/usb/001/020
in place of ttyUSB1
.
ls -l /dev/anchor* lrwxrwxrwx 1 root root 7 Jan 28 12:30 /dev/anchor1 -> ttyUSB0 lrwxrwxrwx 1 root root 15 Jan 28 12:30 /dev/anchor10 -> bus/usb/001/032 lrwxrwxrwx 1 root root 15 Jan 28 12:30 /dev/anchor11 -> bus/usb/001/031 lrwxrwxrwx 1 root root 15 Jan 28 12:30 /dev/anchor12 -> bus/usb/001/029 lrwxrwxrwx 1 root root 7 Jan 28 12:30 /dev/anchor2 -> ttyUSB3 lrwxrwxrwx 1 root root 7 Jan 28 12:30 /dev/anchor3 -> ttyUSB2 lrwxrwxrwx 1 root root 7 Jan 28 12:30 /dev/anchor4 -> ttyUSB1 lrwxrwxrwx 1 root root 15 Jan 28 12:30 /dev/anchor5 -> bus/usb/001/020 lrwxrwxrwx 1 root root 15 Jan 28 12:30 /dev/anchor6 -> bus/usb/001/024 lrwxrwxrwx 1 root root 15 Jan 28 12:30 /dev/anchor7 -> bus/usb/001/022 lrwxrwxrwx 1 root root 15 Jan 28 12:30 /dev/anchor8 -> bus/usb/001/027 lrwxrwxrwx 1 root root 15 Jan 28 12:30 /dev/anchor9 -> bus/usb/001/026
To correct this problem, you need to recharge the rules with the command sudo udevadm trigger
. Here is the result:
ls -l /dev/anchor* lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor1 -> ttyUSB0 lrwxrwxrwx 1 root root 8 Jan 28 13:48 /dev/anchor10 -> ttyUSB11 lrwxrwxrwx 1 root root 8 Jan 28 13:48 /dev/anchor11 -> ttyUSB10 lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor12 -> ttyUSB9 lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor2 -> ttyUSB3 lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor3 -> ttyUSB2 lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor4 -> ttyUSB1 lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor5 -> ttyUSB4 lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor6 -> ttyUSB6 lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor7 -> ttyUSB5 lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor8 -> ttyUSB8 lrwxrwxrwx 1 root root 7 Jan 28 13:48 /dev/anchor9 -> ttyUSB7
Sources: