Currently the python program must know which port a device (Arduino) is on before Python can communicate the device.
Problem: Whenever the device is plugged out and back in, its COM port changes, so the correct serial port must be given to Python again for it to find the device.
How can Python (using pySerial
) automatically search for the correct serial port to use? Is it possible for python to correctly identify the device on a serial port as an Arduino?
Use the following code to see all the available serial ports:
This gives me the following:
To work out if it's an Arduino you could do something like:
Using
serial.tools.list_ports.comports
, we can find and connect to an arduino with:If you know you're looking for exactly the same arduino each time, you can filter on
p.serial_number
instead