Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 33 lines (26 sloc) 0.96 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
# A simple loop that reads values from the analog inputs of an Arduino port.
# No Arduino code is necessary - just upload the standard-firmata sketch from the examples.

import pyfirmata
import signal
import sys

# Definition of the analog pins you want to monitor e.g. (1,2,4)
PINS = [0,1]

# Do a graceful shutdown, otherwise the program will hang if you kill it.
def signal_handler(signal, frame):
    board.exit()
    sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)

# Connect to the board
print "Setting up the connection to the board ..."
board = pyfirmata.Arduino('/dev/ttyACM0')

# Iterator thread is needed for correctly reading analog input
it = pyfirmata.util.Iterator(board)
it.start()
 
# Start reporting for defined pins
for pin in PINS:
    board.analog[pin].enable_reporting()
 
# Loop that keeps printing values
while 1:
    for pin in PINS:
        print "Pin %i : %s" % (pin, board.analog[pin].read())
    board.pass_time(1)
Something went wrong with that request. Please try again.