| « Bcfg2 1.2.1 for Fedora | Dimming a LED with pyFirmata » |
Analog input example for pyFirmata
Using pyFirmata to read from analog inputs is an easy task. pyFirmate provides a helper function (aka iterator) to simplify the reading. Below is a simple script.
import pyfirmata # Definition of the analog pin PINS = (0, 1, 2, 3) # Creates a new board board = pyfirmata.Arduino(/dev/ttyACM0) 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: print "Pin %i : %s" % (pin, board.analog[pin].read()) board.pass_time(1) board.exit()
Checkout the complete script at this location.

