Menu

#147 GPIO.wait_for_edge misbehaving in a loop

New
None
Critical
Patch
2017-02-02
2017-02-01
Alan
No

I have square signal attached to the pin 23 and am running the following code to detect how long does the pulse width last:

import RPi.GPIO as GPIO
import time

SENSOR_PIN = 23

GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

while True:
    GPIO.wait_for_edge(SENSOR_PIN, GPIO.RISING)
    start_high = time.time()
    GPIO.wait_for_edge(SENSOR_PIN, GPIO.FALLING)
    end_high = time.time()
    high_width = end_high - start_high
    print(high_width)

The code is blocks on GPIO.wait_for_edge(SENSOR_PIN, GPIO.RISING).

The part that gets me confused is it works normally if it's run without the for loop. The code below exits normally for a same physically setup:

i~~~
mport RPi.GPIO as GPIO
import time

SENSOR_PIN = 23

GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.wait_for_edge(SENSOR_PIN, GPIO.RISING)
~~~

Are there some known peculiarities regarding the GPIO.wait_for_edge?

http://raspberrypi.stackexchange.com/questions/61344/gpio-wait-for-edge-misbehaving-in-a-loop/61345#61345

Discussion

  • joan

    joan - 2017-02-02

    I incorrectly thought I could replicate this error (linked stack exchange post). I was wrong, my testing was faulty. When I test correctly the script works correctly.

     
  • Alan

    Alan - 2017-02-02

    I've been using python 3.4 that came by default by the RPi.
    Can't reproduce it anymore with self compiled 3.6 python

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.