1、进入conda环境,安装python_periphery
sudo pip3 install python-periphery
2、切换为root,并激活conda(非root无法操作外设)
3、确定gpio端口
gpio readall
或者
ls /sys/kernel/debug/gpio
这里使用的引脚GPIO4_B2对应GPIO138
4、代码(例)
from periphery import GPIO
import time
LED_PIN = 138
LED_GPIO = GPIO(LED_PIN, "out")
while True:
try:
LED_GPIO.write(True)
LED_GPIO.write(False)
print("LED OFF!")
time.sleep(0.5)
except KeyboardInterrupt:
LED_GPIO.write(False)
break
except IOError:
print ("Error")
LED_GPIO.close()
4、运行
OK