Skip to content

Instantly share code, notes, and snippets.

@bart02
Created October 13, 2019 13:10
Show Gist options
  • Select an option

  • Save bart02/e3949d2b3498c31a72d475b8f2290f7d to your computer and use it in GitHub Desktop.

Select an option

Save bart02/e3949d2b3498c31a72d475b8f2290f7d to your computer and use it in GitHub Desktop.
Function for searching the arduino port
import serial
def search():
found = False
for j in range(3):
for i in range(64):
try:
if j == 0:
port = "/dev/ttyACM" + str(i)
elif j == 1:
port = "/dev/ttyUSB" + str(i)
elif j == 2:
port = "COM" + str(i)
ser = serial.Serial(port)
ser.close()
found = True
break
except serial.serialutil.SerialException:
pass
if found:
return port
break
if not found:
raise NameError("Ports not found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment