2

(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?

scruss
  • 9,068
  • 1
  • 24
  • 35
hoothoot
  • 41
  • 1
  • 2
  • 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

1 Answers1

2

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.

tlhIngan
  • 3,372
  • 5
  • 19
  • 33
  • 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. –  Jan 13 '17 at 17:25