pythonpython-3.xraspberry-pigpio

Raspberry Pi 4: Python - RuntimeError: Error waiting for edge


I am trying to get the falling edge of a HB100 doppler radar with a Lm358 amplifier module.

The error is RuntimeError: Error waiting for edge

It was working great and stopped suddenly.

I have already tried with another radar and amplifier modules and the error continues. I have tried to switch the GPIO pins with no success.

The code is below

I am using Raspberry-Pi 4 and Python11

import RPi.GPIO as GPIO
import time

GPIO.cleanup()

AMPLIFICADOR_INPUT_PIN = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(AMPLIFICADOR_INPUT_PIN, GPIO.IN)

MAX_PULSE_COUNT = 10
MOTION_SENSITIVITY = 10

def count_frequency(GPIO_pin, max_pulse_count=10, ms_timeout=50):
    start_time = time.time()
    pulse_count = 0

    for count in range(max_pulse_count):

        edge_detected = GPIO.wait_for_edge(GPIO_pin, GPIO.FALLING, timeout=ms_timeout)

        if edge_detected is not None:
            pulse_count += 1

    duration = time.time() - start_time 
    frequency = pulse_count / duration
    
    return frequency

while True:
    doppler_freq = count_frequency(AMPLIFICADOR_INPUT_PIN)
    speed = doppler_freq / float (31.36)
    print (speed)

    if (speed>2):
        print ('high Speed'+ "Your speed="+ str(speed) +'Mph')        

    if doppler_freq < MOTION_SENSITIVITY:
        print("No motion was detected")

    else:
        print("Motion was detected, Doppler frequency was: {0}".format(doppler_freq))
        
GPIO.cleanup()

Solution

  • I have found a post and it says that:

    Raspberry Pi OS Bookworm includes a pre-installed 'RPi.GPIO' which is not compatible with Bookworm or a Pi 5.

    The post: https://forums.raspberrypi.com/viewtopic.php?t=360130

    I am using Bookworm.

    The solution is installing rpi-lgpio in Python

    pip uninstall rpi.gpio
    pip install rpi-lgpio
    

    Now it is working.