import pyfirmata
import time
PORT = '/dev/ttyUSB0'
# Definition of the analog pin
PINS = (0, 1, 2, 3, 4, 5)
# Creates a new board
board = pyfirmata.Arduino(PORT)
print "Setting up the connection to the board ..."
it = pyfirmata.util.Iterator(board)
it.start()
# Start reporting for defined pins
for pin in PINS:
board.analog[pin].enable_reporting()
# Loop for reading the input. Duration approx. 10 s
for i in range(1, 11):
print "\nValues after %i second(s)" % i
for pin in PINS:
str=board.analog[pin].read()
if str is None:
val=0
else:
val=float(str)*5.0
print
"A%i:%.4f[V]" % (pin, val),
# time.sleep(1)
board.pass_time(1)
board.exit() |