如何解决Raspberry PI 4 RPi.GPIO 库在 Ubuntu 20.10 上不起作用
我在 RaspBerry Pi 4 4GB 上使用 Ubuntu 20.10,但在我的代码终端上使用 RPi.GPIO 库向我显示此消息:
"GPIO.setup(INT,GPIO.IN,pull_up_down=GPIO.PUD_UP) 运行时错误:未在 RPi 上运行!”
这是代码:
#!/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,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()
非常感谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。