How to create a symlink for ttyUSBx?
With a udev rule, a fixed alias name is assigned to the ttyUSB device.
Read USB device attributes (Vendor and Product ID)
udevadm info --name=/dev/ttyUSB0 --attribute-walk
The above command returns a long list of properties (attributes) of the connected USB device. In this output, we need to look for the values for **idVendor** and **idProduct**. These two values uniquely identify the exact hardware type of your USB stick (e.g., a Zigbee stick).
looking at parent device '/devices/platform/.../usb1/1-1/1-1.2':
KERNELS=="1-1.2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceClass}=="00"
ATTRS{bMaxPower}=="100mA"
ATTRS{idProduct}=="ea60"
ATTRS{idVendor}=="10c4"
ATTRS{manufacturer}=="Silicon Labs"
ATTRS{product}=="slae.sh cc2652rb stick - slaesh's iot stuff"
In our example, we find the values `ATTRS{idProduct}=="ea60"` and `ATTRS{idVendor}=="10c4"` in the list. We will note these for the next step.
Create udev rule
Now we create a new file for the udev rule in the following directory (e.g., using `sudo nano /etc/udev/rules.d/98-usb-device.rules`):
/etc/udev/rules.d/98-usb-device.rules
Insert the following content into the file, replacing **idVendor** and **idProduct** with your own values from the previous step. The attribute SYMLINK+="ttyZCOORD" specifies the fixed name under which the device will be accessible in the future (here: /dev/ttyZCOORD).
KERNEL=="ttyUSB?", SUBSYSTEMS=="usb", ATTRS{idProduct}=="ea60", ATTRS{idVendor}=="10c4", SYMLINK+="ttyZCOORD"
Apply udev rules
For the system to recognize the new rule, we reload the udev rules. A complete restart of the Raspberry Pi is not strictly necessary:
sudo udevadm trigger
If everything worked, you can check with `ls -l /dev/tty*` if the symlink was successfully created. It should now point as an alias to your current ttyUSB device:
lrwxrwxrwx 1 root root 7 28. Jun 00:17 /dev/ttyZCOORD -> ttyUSB0