[Metalab] RPIO: An extension of RPi.GPIO with easy interrupt handling for the Raspberry Pi

Chris Hager chris at linuxuser.at
Tue Feb 19 12:46:50 CET 2013


Hi guys!

I wanted to show you RPIO <https://pypi.python.org/pypi/RPIO>, an extension
of RPi.GPIO <http://pypi.python.org/pypi/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: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()Besides the new interrupt methods, you can use
RPIO just as RPi.GPIO. Note that RPIO uses the BCM gpio numbering scheme by
default.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()The source
code<https://github.com/metachris/raspberrypi-utils/blob/master/RPIO/RPIO.py>
is
quite compact and works with Python 2.x and 3.x. Easiest way to get RPIO is
with pip or easy_install:sudo pip install RPIOThe source code is published
under the MIT license.

Any feedback is appreciated!
- Chris


   - https://pypi.python.org/pypi/RPIO
   - https://github.com/metachris/raspberrypi-utils
   - http://pypi.python.org/pypi/RPi.GPIO
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.metalab.at/pipermail/metalab/attachments/20130219/e6c5c9f4/attachment.html>


More information about the Metalab mailing list