This question already has an answer here:

(Using Raspberry Pi 3B, Raspbian Jessie)

I have a Python script that uses an Arduino with Pyserial.

I want to start this script on boot, but my problem is that sometimes the Arduino binds to /dev/ttyACM0, and sometimes to /dev/ttyACM1.

If it binds to the one that's not specified in the script, the script fails.

Is there a way to force one or the other? And if not, is there a way I can switch from one to the other in the script?

marked as duplicate by scruss, joan, Dmitry Grigoryev, goobering Mar 30 '17 at 10:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • this is more a question of port enumeration than about python, and it has been asked and answered before – scruss Mar 28 '17 at 17:55

What I would do is get your script to run the OS command ls /dev | ttyACM and redirect the output to a variable you will use in your script. That way, your script won't care where the Arduino connects.

  • I think you wanted ls /dev/ttyACM* or ls /dev | grep ttyACM. Also, you might want to show how to save the output in a variable. – David Cullen Jan 13 '17 at 17:25

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