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?
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.
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