Stop your USB serial device from changing from /dev/ttyACM0 to /dev/ttyACM1 every time you unplug it!
udevadm info -a -n /dev/ttyACM0Replace ttyACM0 with your actual device
Look for these 3 things in the output:
idVendor(example:"0483")idProduct(example:"374e")serial(example:"0053002F3432511330343838")
sudo nano /etc/udev/rules.d/99-usb-serial.rulesCopy this template and change the values:
SUBSYSTEM=="tty", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374e", ATTRS{serial}=="0053002F3432511330343838", SYMLINK+="my_device"
Change these:
0483→ your idVendor374e→ your idProduct0053002F3432511330343838→ your serialmy_device→ whatever name you want
sudo udevadm control --reload
sudo udevadm triggerls -la /dev/my_deviceYou should see your device! Now use /dev/my_device instead of /dev/ttyACM0
Arduino:
SUBSYSTEM=="tty", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0043", SYMLINK+="arduino"
ESP32:
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="esp32"
STM32:
SUBSYSTEM=="tty", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", SYMLINK+="stm32"
Use the serial number to tell them apart:
# Device 1
SUBSYSTEM=="tty", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374e", ATTRS{serial}=="123456", SYMLINK+="device1"
# Device 2
SUBSYSTEM=="tty", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374e", ATTRS{serial}=="789012", SYMLINK+="device2"
Just use vendor/product ID:
SUBSYSTEM=="tty", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374e", SYMLINK+="my_device"
Device not found?
lsusb # See if device is connected
ls /dev/tty* # See available portsRule not working?
- Check for typos (spaces around
==will break it) - Unplug and replug device
- Check:
journalctl -fthen replug device
Permission issues?
sudo usermod -a -G dialout $USERThen log out and back in.
That's it! Your device will always be /dev/my_device now.