Page 1 of 1

interrupt in raspberry pi gpio

Posted: Sat Jul 05, 2014 7:13 am
by iiitdavid
i am trying to learn rpi interrupt programming using two buttons but its showing error during execution.
can anyone please help me.
Here is my code:

import RPi.GPIO as GPIO
import os
GPIO.setmode(GPIO.BOARD)

GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def my_callback(channel):
print "falling edge detected on 23"
os.system("date")

GPIO.add_event_detect(23, GPIO.FALLING, callback=my_callback, bouncetime=300)

try:
print "Waiting for falling edge on port 24"
GPIO.wait_for_edge(24, GPIO.FALLING)
print "falling edge detected on port 24, end of program"
except KeyboardInterrupt:
GPIO.cleanup()
GPIO.cleanup()

if i remove the statement os.system("date") from the scipt everything works fine. but when insert the above code into the script it gives "RuntimeError: Error #5 waiting for edge"
anyone be able tp modify the code to working condition
thanks in advance

Re: interrupt in raspberry pi gpio

Posted: Sat Jul 05, 2014 1:11 pm
by ghp
Hello,

you already have the solution: just remove this line of code.
os.system is a quite high overhead to have just a date printed on screen. It starts a new process, invokes date. The datetime module might be more efficient.

Regards,
Gerhard