0

The code I'm trying to run looks something like this:

import RPi.GPIO as GPIO
sensor=4

def cb(r):#r is just accept the argument passed by add_event_detect
    c=GPIO.wait_for_edge(sensor,GPIO.RISING,timeout=300)
    if c!=sensor:
        print "do something if timeout happens before next signal"

GPIO.add_event_detect(sensor,GPIO.RISING,callback=cb)

When I run this I get RuntimeError: Conflicting edge detection events already. I've found this website https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=88951 which solves the case where two competing wait_for_edge cases are run simultaneously but:

I wasn't sure if this was would work for an event_detect and a wait_for_edge

I also wasn't sure if this would work with my specific hard/software specs. I'm running a Pi zero version 1.3 with what I assume is the latest version of Jesse that I downloaded last week from https://www.raspberrypi.org/downloads/raspbian/.

And furthermore I'm not the best at linux and don't want to damage my new PI.

0

I ended up side stepping this issue by using a thread and a class. Like so:

import time
import timeit.default_timer as tm
import threading.thread as TH
import RPi.GPIO as GPIO
sensor=4

class wd(object):
    def __init__(self):
        self.t=timeit.default_timer()
    def cb(self):
        ct==tm() #see import
        self.t=ct
        TH(self.waiter,args=(ct,)).start() #see import
    def waiter(self,ct):
        time.sleep(.3)
        if self.t==ct:
            print "do something if timeout happens before next signal"
w=wd()
GPIO.add_event_detect(sensor,GPIO.RISING,callback=w.cb)

The because this is threaded, the class has a chance to update self.t before it compares ct to self.t

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.