Raspberry pi Raspberry PI 4 RPi.GPIO库不';我不能在Ubuntu 20.10上工作
我在Raspberry Pi 4 4GB上使用Ubuntu 20.10,但在我的代码终端上使用RPi.GPIO库会向我显示以下信息: “GPIO.setup(INT,GPIO.IN,pull\u up\u down=GPIO.PUD\u up) 运行时错误:未在RPi上运行!” 代码如下:Raspberry pi Raspberry PI 4 RPi.GPIO库不';我不能在Ubuntu 20.10上工作,raspberry-pi,libraries,Raspberry Pi,Libraries,我在Raspberry Pi 4 4GB上使用Ubuntu 20.10,但在我的代码终端上使用RPi.GPIO库会向我显示以下信息: “GPIO.setup(INT,GPIO.IN,pull\u up\u down=GPIO.PUD\u up) 运行时错误:未在RPi上运行!” 代码如下: #!/usr/bin/env python2.7 import RPi.GPIO as GPIO import subprocess from time import sleep GPIO.setmode(
#!/usr/bin/env python2.7
import RPi.GPIO as GPIO
import subprocess
from time import sleep
GPIO.setmode(GPIO.BCM) # use GPIO numbering
GPIO.setwarnings(False)
print('RPi.GPIO:',GPIO.VERSION)
INT = 12 # GPIO-12 button interrupt to shutdown procedure
# use a weak pull_up to create a high
GPIO.setup(INT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def main():
while True:
# set an interrupt on a falling edge and wait for it to happen
GPIO.wait_for_edge(INT, GPIO.FALLING)
# we got here because the button was pressed.
# wait for 3 seconds to see if this was deliberate
sleep(3)
# check the button level again
if GPIO.input(INT) == 0:
# still pressed, it must be a serious request; shutdown Pi
subprocess.call(['poweroff'], shell=True, \
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if __name__ == '__main__':
main()
我找不到代码的错误,Ubuntu和这个库之间有什么问题吗
非常感谢你 是否允许您的用户访问GPIO?如果没有,您必须先执行
sudo adduser username gpio
,这就是问题所在,非常感谢!