I have multiple Arduinos that I want to control using Python. My problem is that when I plug my Arduinos into the computer, they get assigned the port /dev/ttyUSBx where x increments with each one I connect.

Is there any way to reserve a certain number for a certain Arduino so that I can hard code that into the Python script? If not, can I scan the port to figure out which Arduino it is?

  • Do they have unique serial numbers? Apr 28 '16 at 1:00
  • @IgnacioVazquez-Abrams What do you mean by serial number? Do you mean the baud rate?
    – Marcel
    Apr 28 '16 at 1:02
  • No. The serial number of the USB device. Apr 28 '16 at 1:02
  • @IgnacioVazquez-Abrams You mean the x in /dev/ttyUSBx?
    – Marcel
    Apr 28 '16 at 1:03
  • No. I mean the serial number when you run lsusb -v. Apr 28 '16 at 1:03

Yes. You need to create new unique names for them using udev rules.

By using the unique serial number, along with the VID and PID of the board you can use udev to create a symbolic link to a device name of your choice. Best to keep it to something that the Arduino IDE recognises if you want to access the link from within there for programming (otherwise you can choose what you like).

Rules are stored in /etc/udev/rules.d and take the form of .rules files with various instructions in. One example, that should do what you want, is:

SUBSYSTEMS=="usb", ATTRS{product}=="Arduino Uno", ATTRS{serial}=="6493832323135111C0A1", KERNEL=="ttyACM*", SYMLINK+="ttyACM50", MODE="0666", GROUP="plugdev"

Of course, tweak it to your personal requirements.

Once you have crafted your rules be sure to restart udev:

sudo systemctl restart udev


sudo /etc/init.d/udev restart

and plug your board in.

Genuine Arduino devices usually use /dev/ttyACM* not /dev/ttyUSB*. If you have /dev/ttyUSB* then you are either on a very old device (with an FT232 chip) or a cheap Chinese clone.

If the latter then your mileage may vary somewhat.

  • Yep Chinese clones. Thanks for your answer.
    – Marcel
    Apr 28 '16 at 1:06
  • Stepping on standard namespaces is probably not the best idea though. Naming the symlink something like "arduinoNN" might be a better idea. Apr 28 '16 at 1:09
  • Then the IDE won't see it. You notice I chose a name way up in the numbers - one not likely to be used under normal circumstances.
    – Majenko
    Apr 28 '16 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.