Comments (2)
Typically you'd add interrupts with RPIO.add_interrupt_callback(...)
(http://pythonhosted.org/RPIO/rpio_py.html#RPIO.add_interrupt_callback)
from rpio.
Chris,
My problem was that Python threw an exception when an interrupt occurred saying that the call back routine required 3 arguments when I used “def gpio_callback( gpio_id, val ):”. Changing the function to “def gpio_callback( newarg, gpio_id, val):” worked. The first argument was equivalent to “self” in the call back function.
The following is an abstract of the code that works. I have attached the actual code as testints.py
Class TestInts :
INT_PIN = 4
def setup( self ) :
self.StateDevice = MCP23008( address = 0x20 )
# other setup code to configure the MCP23008
# as StateDevice
RPIO.setup( self.INT_PIN, direction = RPIO.IN)
RPIO.add_interrupt_callback( self.INT_PIN \
, self.callBack \
, edge = 'rising' \
, threaded_callback = True \
, debounce_timeout_ms = 15 \
)
def callBack( me, pin, val ) :
st = me.StateDevice.getRegINTF() # Get pins that changed
me.StateDevice.clearInterrupt()
…
Sorry for any confusion my previous post may have caused. I am new to Python but have > 50 yrs programming so far. I do appreciate what you did as it saved me a LOT of work.
mailto:[email protected] [email protected]
Phone 510-530-8568 Home
Phone 510-338-0045 Cell
From: Chris Hager [mailto:[email protected]]
Sent: Saturday, July 06, 2013 2:56 AM
To: metachris/RPIO
Cc: jhburkhard
Subject: Re: [RPIO] Interrupt call_back arguments (#8)
Typically you'd add interrupts with RPIO.add_interrupt_callback(...) (http://pythonhosted.org/RPIO/rpio_py.html#RPIO.add_interrupt_callback)
—
Reply to this email directly or view it on GitHub #8 (comment) . https://github.com/notifications/beacon/6V04vPHLwa1iPOOylIwSlySFxeyw6uubf9M255055iUI4OtnKedcpXT2dDLSL_IO.gif
import RPIO
from MCP23008 import *
import time
import signal
import Queue
class TestInts :
INT_GPIO_PIN = 4
intQueue = Queue.Queue()
def setup( self ):
# Configure all 8 as input pulled high and inverted polarity
self.StateDevice = MCP23008( address = 0x20 ) # I2C device for state info
self.StateDevice.configAllDirection( MCP23008.INPUT ) # Set State device to all input
self.StateDevice.configAllInputPolarity( 0xFF ) # Set State inverted polarity
self.StateDevice.setIntActiveHigh() # Normal low on INT goes High
self.StateDevice.setIntOnChangeAll( True ) # All bits cause Int on any change
self.StateDevice.clearInterrupt() # Clear any pending
# Set the Pi's GPIO pin as input and no pullup or down
RPIO.setup( self.INT_GPIO_PIN, direction = RPIO.IN)
RPIO.add_interrupt_callback( self.INT_GPIO_PIN \
, self.callBack \
, edge = 'rising' \
, threaded_callback = True \
, debounce_timeout_ms = 15 \
)
def callBack( me, pin, val ) :
st = me.StateDevice.getRegINTF() # Get the pins that changed
me.StateDevice.intDisableAll() # disable ints on all MCP23008 pins
reg = me.StateDevice.clearInterrupt() # Clear the interrupt and return the status reg
print "Interrupt on " + str( pin ) + " INTF Reg " + str( st ) + " val " + str( val )
t = time.time()
me.intQueue.put_nowait( [st, reg, t - me.lastIntTime ] )
me.lastIntTime = t
me.StateDevice.intEnableAll() # ?? Will pending int be registered ??
def sig_handler( self, signal, frame ) :
print "Ctrl-C pressed: exiting."
RPIO.cleanup()
self.keepRunning = False
def runit( self ) :
signal.signal( signal.SIGINT, self.sig_handler )
self.keepRunning = True
self.setup()
self.lastIntTime = time.time()
RPIO.wait_for_interrupts( threaded = True )
while( self.keepRunning ) :
try :
x = self.intQueue.get( True, 5 )
print( 'Changed pins {0[0]:#04x}\tIO Pins {0[1]:#02x}\tTime {0[2]:f}'.format( x) )
except Queue.Empty :
print "Q is empty timeout"
RPIO.stop_waiting_for_interrupts()
RPIO.cleanup()
from rpio.
Related Issues (20)
- RPIO ver.2 HOT 1
- Input function doen't work
- System hangs during reboot with RPIO python script running in docker HOT 1
- SystemError: This module can only be run on a Raspberry Pi! HOT 4
- Raspberry CM3 module unsupported. HOT 1
- Debian buster need #include <sys/sysmacros.h> inside pwm.c
- After upgrading to buster branch v2 stops working HOT 1
- Uncaught Error: Cannot find 'rpio'
- RPI 4 Model HOT 1
- RuntimeError: This module can only be run on a Raspberry Pi! HOT 2
- SystemError: This module can only be run on a Raspberry Pi!
- _PWM.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: makedev HOT 4
- how disable debbug ?
- RPIO-0.10.0-py3.5-linux-armv7l.egg SystemError: This module can only be run on a Raspberry Pi! HOT 1
- Interrupted by signal 11: SIGSEGV
- mmap check
- System error
- Problem running RPIO on Raspberry Pi 4 HOT 2
- RPIO won't run on my Raspberry Pi 4, how to remove? HOT 1
- https://pythonhosted.org/RPIO/#installation seems outdated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rpio.