I have a problem automagically detecting my Arduino's serial port in Python, using Mac/Linux.
I know a working shell command to find the port; because Arduino serial ports almost always begin with tty.usbmodem
, you can find the serial port with ls /dev | grep tty.usbmodem
which should return something like tty.usbmodem262141
.
However, I'm confused on how to call this shell command from my Python code. I've tried this:
p = "/dev/" + str(subprocess.Popen('ls /dev | grep tty.usbmodem', shell=True).stdout)
Which should make p
become /dev/tty.usbmodem262141
.
However, at the moment I get /dev/None
.
How can I modify my shell script call to return the right string? I've tried to use several commands to call shell scripts, but none have worked.