Skip to content

Instantly share code, notes, and snippets.

@pranav6670
Last active July 27, 2020 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pranav6670/f55115e4f3b9849c1848eec7278c0526 to your computer and use it in GitHub Desktop.
Save pranav6670/f55115e4f3b9849c1848eec7278c0526 to your computer and use it in GitHub Desktop.
Test Arduino autoDetect with blink example.
import pyfirmata
import time
import serial.tools.list_ports
ports = list(serial.tools.list_ports.comports())
Arduino_ports = []
for p in ports:
if 'Arduino' in p.description:
Arduino_ports.append(p)
if len(Arduino_ports) == 0:
print("no Arduino board detected")
if len(Arduino_ports) > 1:
print('Multiple Arduinos found - using the first')
else:
print("Arduino board detected")
print(Arduino_ports[0].device)
board = pyfirmata.Arduino(str(Arduino_ports[0].device))
it = pyfirmata.util.Iterator(board)
it.start()
board.digital[13].mode = pyfirmata.OUTPUT
while True:
board.digital[13].write(1)
time.sleep(2)
board.digital[13].write(0)
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment