I wanted to let you know about RPIO, an extension of RPi.GPIO with interrupt handling, which I've just uploaded to pypi. This is an example which handles events on 3 gpio pins, each with different edge detection:
Code: Select all
import RPIO
def do_something(gpio_id, value):
print("New value for GPIO %s: %s" % (gpio_id, value))
RPIO.add_interrupt_callback(17, do_something, edge='rising')
RPIO.add_interrupt_callback(18, do_something, edge='falling')
RPIO.add_interrupt_callback(19, do_something, edge='both', threaded_callback=True)
RPIO.wait_for_interrupts()
Code: Select all
import RPIO
# set up GPIO output channel
RPIO.setup(17, RPIO.OUT)
# set gpio 17 to high
RPIO.output(17, RPIO.HIGH)
# set up output channel with an initial state
RPIO.setup(18, RPIO.OUT, initial=RPIO.LOW)
# set up input channel with pull-up control
# (pull_up_down be PUD_OFF, PUD_UP or PUD_DOWN, default PUD_OFF)
RPIO.setup(19, RPIO.IN, pull_up_down=RPIO.PUD_UP)
# read input from gpio 19
input_value = RPIO.input(19)
# to change to BOARD GPIO numbering
RPIO.setmode(RPIO.BOARD)
# to reset every channel that has been set up by this program to INPUT with no pullup/pulldown and no event detection
RPIO.cleanup()
Code: Select all
sudo pip install RPIO