Page 4 of 4

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Sun Jan 19, 2014 8:12 pm
by Hove
You need to call RPIO.setmode() and RPIO.setup() before you can play with inputs outputs etc.

RPIO.setup is the call which sets your pin to an input or output, and sets whether you want pull-up / down resistors

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Sun Jan 19, 2014 10:44 pm
by michaelperakis
The error code received:

/home/pi$ sudo python test4.py
Traceback (most recent call last):
File "test4.py", line 8, in <module>
RPIO.add_interrupt_callback(19, do_something, edge='both', threaded_callback=True)
File "/usr/local/lib/python2.7/dist-packages/RPIO-0.10.0-py2.7-linux-armv6l.egg/RPIO/__init__.py", line 217, in add_interrupt_callback
threaded_callback, debounce_timeout_ms)
File "/usr/local/lib/python2.7/dist-packages/RPIO-0.10.0-py2.7-linux-armv6l.egg/RPIO/_RPIO.py", line 125, in add_interrupt_callback
gpio_id = _GPIO.channel_to_gpio(gpio_id)
RPIO.Exceptions.InvalidChannelException: The channel sent is invalid on a Raspberry Pi (not a valid gpio)



What do you mean by the "complete code?" -- This is the complete code...

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Sun Jan 19, 2014 11:15 pm
by michaelperakis
ok, got it.

Added the missing code and also threaded=True @ RPIO.wait_for_interrupts(), but now nothing is happening when I press the button...
I was expecting to have an output signaling the 'button pressed' change of state...

Please advice since obviously I am missing something...

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Mon Jan 20, 2014 7:55 am
by Hove
2 things:

if the button is connected to pin 18, the the RPIO.add_interrup_callback() needs to always refer to pin 18, not 17 or 19.


Also pin 18 is the BCM pin numbering scheme (pins on the chip) so actually the button needs to be connected to GPIO pin 12 (which is where BCM pin 18 is connected to.

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Mon Jan 20, 2014 9:37 pm
by michaelperakis
Yes, the modified code is the following:

Code: Select all

import RPIO
RPIO.setup(18, RPIO.IN)
RPIO.setmode(RPIO.BCM)
def do_something(gpio_id, value):
    print("New value for GPIO %s: %s" % (gpio_id, value))
RPIO.add_interrupt_callback(18, do_something, edge='rising',debounce_timeout_ms=100)
RPIO.wait_for_interrupts(threaded=True)

So, I would expect to see the message: New value for GPIO 18: 1, but the program simply runs and finishes without waiting for input. Should I include the code in a while loop? But if true, isn't this what we would like to avoid in the first place?

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Mon Jan 20, 2014 10:01 pm
by Hove
If you want to wait for interrupts, and for the code to wait until it happens, you need "threaded = False" I think.

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Mon Jan 20, 2014 11:06 pm
by michaelperakis
Hove wrote:If you want to wait for interrupts, and for the code to wait until it happens, you need "threaded = False" I think.
Changed to threaded = False but still the code isnt runing as expected since I get a sequence of messages:
New value for GPIO 18: 1 and when the button is pressed, the sequence just stops then when released, it starts again...
I would expect nothing to happen until the button was pressed. I thought that was the whole idea of interrupts...

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Tue Jan 21, 2014 7:36 am
by Hove
Please post your latest code - the code below will just exit when you press a button, but that is not what you are describing.

Thanks

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Thu Jan 23, 2014 9:22 pm
by michaelperakis
Sorry for not responding a few days now, I was busy with other issues.

I have fixed the code, which I am posting naked without any unnecessary rems:

Code: Select all

import RPi.GPIO as GPIO  
GPIO.setmode(GPIO.BCM)  
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  
print "Waiting for rising edge on port 18"
try:  
    	GPIO.wait_for_edge(18, GPIO.RISING)
    	print "\nRising edge detected. Now your program can continue with"  
    	print "whatever was waiting for a button press."  
except KeyboardInterrupt:  
    	GPIO.cleanup()       # clean up GPIO on CTRL+C exit  
GPIO.cleanup()           # clean up GPIO on normal exit 
But the issue is this line of code: GPIO.wait_for_edge(18, GPIO.RISING)
When this runs, the system hangs (pauses) and waits for the input (18) to happen.

What should I do to proceed to other code and when input 18, or other input happens, to run specific subs?

BR

Re: RPIO: An extension of RPi.GPIO with interrupts, PWM and

Posted: Fri Jan 24, 2014 8:29 am
by Hove
There's a few options here:

- run your other code in another thread
- use event_detected in your main thread instead of wait for edge
- move the code you have into a thread callback, and do your other stuff in the main thread

Details here:

http://sourceforge.net/p/raspberry-gpio ... ki/Inputs/