#!/usr/bin/python3
# ===================================================================
# Arduino/Python Demo
# -------------------------------------------------------------------
# turn pin 13 on and off with a one second delay (blink builtin led)
# From: realpython.com/arduino-python/
# -------------------------------------------------------------------
# To work with the Firmata protocol in Python, you will need the
# pyFirmata package, which you can install with pip:
#     c:\Python36\Scripts\pip3 -V
#     c:\Python36\Scripts\pip3 install pyfirmata
# -------------------------------------------------------------------
# In Linus you must allow RW access to the USB port. For example
#    sudo ls -al     /dev/ttyUSB0
#    sudo chmod a+rw /dev/ttyUSB0
#    sudo ls -al     /dev/ttyUSB0
# Note: It appears you must do this every time a USB devide in
#       plugged into a USB port. (I am sure there are better
#       ways to do this.)
# ===================================================================

import pyfirmata
import time

board = pyfirmata.Arduino('/dev/ttyUSB0')     # Linux

##board = pyfirmata.Arduino('COM7')           # Windows

while True:

    board.digital[13].write(1)

    time.sleep(1)

    board.digital[13].write(0)

    time.sleep(1)
