小编Fer*_*ere的帖子

RuntimeError:您必须首先设置()GPIO通道

当我用sudo python3 program.py执行并按下de switch 1时抛出下一个异常:

Taking picture...
Picture takeng...
Traceback (most recent call last):
  File "main.py", line 21, in <module>
    if GPIO.input(switch1):
RuntimeError: You must setup() the GPIO channel first
Run Code Online (Sandbox Code Playgroud)

我为这个项目使用了覆盆子凸轮库和rpi.gpio库.任何人都知道我的代码中发生了什么?

import RPi.GPIO as GPIO
import time
import picamera

# initial config for gpio ports
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

# input switches
switch1 = 22
switch2 = 23
switch3 = 24

# setup
GPIO.setup(switch1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(switch2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(switch3, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# main loop
while True:
    if GPIO.input(switch1):
        print ("Taking picture...") …
Run Code Online (Sandbox Code Playgroud)

python camera gpio raspberry-pi

1
推荐指数
1
解决办法
9414
查看次数

标签 统计

camera ×1

gpio ×1

python ×1

raspberry-pi ×1