Ubuntu lists USB devices by default under /dev/ as ttyUSBx where x is a number starting 0. Issue with this is if USB devices are swapped to a different port, it’s not clear with ttyUSBx device relates to which physical USB device.
There are a few ways to change settings to point to the correct USB Device. I’ll list to 2 most common ways. The below is an examples for an RFXTrx433 USB Transceiver, but the process works the same for any other USB device.
Option A
- Point the app to the device’s serial id. Run this in a terminal:
ls /dev/serial/by-id/
- This will list all serial USB devices. Pick the one that you need to communicate with and set its address in your app, e.g.
/dev/serial/by-id/usb-RFXCOM_RFXtrx433_A1XETWB5-if00-port0
Option B
-
- Run this in a terminal:
udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0)
(if necessary replace ttyUSB0 with ttyUSB1)
- You need to locate the block where it gives you the correct value for your device,
ATTRS{manufacturer}
and/orATTRS{product}
and take note of theATTRS{idVendor}
ATTRS{idProduct}
andATTRS{serial}
:
- Edit the following file with your preferred editor:
/etc/udev/rules.d/99-usb-serial.rules
and add this line:ACTION=="add", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A1XETWB5", SYMLINK+="RFXTrx433"
- Replace the values in
ATTRS{idVendor}
ATTRS{idProduct}
andATTRS{serial}
with the ones you found in previous step, replaceRFXTrx433
with a name that makes sense to you. Save and Exit - Run this in a terminal:
sudo udevadm control --reload
&& sudoudevadm trigger
- You should then have a new device listed in /dev matching the name you provided after SYMLINK. To confirm, run this in terminal:
ls /dev/RFX*
(replace
RFX
with the name you provided after SYMLINK) - Enter the device’s “new” address in your app, e.g.
/dev/RFXTrx433
- Run this in a terminal:
Now it does not matter which USB port your device is connected to, it will always be found.