![Raspberry Pi 0 W 自发事件触发输入引脚](https://linux22.com/image/1607793/Raspberry%20Pi%200%20W%20%E8%87%AA%E5%8F%91%E4%BA%8B%E4%BB%B6%E8%A7%A6%E5%8F%91%E8%BE%93%E5%85%A5%E5%BC%95%E8%84%9A.png)
我有两个“Cylewet 25Pcs AC 1A 125V 3Pin SPDT 限位微动开关”,它们通常处于打开状态,并通过内部上拉电阻连接到两个 Pi 引脚。如果不加以注意,它们会自发调用已注册的函数,就像被按下一样。这可能是什么原因造成的?以下是代码的重要部分:
import RPi.GPIO as GPIO
def func(channel: int):
...
log.debug('The end breaker is pressed - channel %i', channel)
GPIO.setup([18,19], GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(18, GPIO.FALLING, callback=func)
GPIO.add_event_detect(19, GPIO.FALLING, callback=func)
以下是日志:
2019-10-26 14:10:03,982 INFO last activity
2019-10-26 16:46:21,676 DEBUG module(func[xxx]): The end breaker is pressed - channel 18
2019-10-26 16:46:21,681 DEBUG module(func[xxx]): The end breaker is pressed - channel 18
2019-10-26 16:46:21,688 DEBUG module(func[xxx]): The end breaker is pressed - channel 19