Raspberry Pi 4:Python - 运行时错误:等待边缘时出错

问题描述 投票:0回答:1

我正在尝试使用 Lm358 放大器模块获取 HB100 多普勒雷达的下降沿。

错误是 RuntimeError: 等待边缘时出错

它运行得很好,突然停止了。

我已经尝试过另一个雷达和放大器模块,但错误仍然存在。 我尝试过切换 GPIO 引脚,但没有成功。

代码如下

我正在使用 Raspberry-Pi 4 和 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()
python python-3.x raspberry-pi gpio
1个回答
0
投票

我找到了一个帖子,上面写着:

Raspberry Pi OS Bookworm 包含预装的“RPi.GPIO”,与 Bookworm 或 Pi 5 不兼容。

帖子: https://forums.raspberrypi.com/viewtopic.php?t=360130

我正在使用书虫。

解决方案是在Python中安装rpi-lgpio

pip uninstall rpi.gpio
pip install rpi-lgpio

现在可以工作了。

© www.soinside.com 2019 - 2024. All rights reserved.