树莓派 Raspberry PI之GPIO
树莓派各版本硬件原理图:https://www.raspberrypi.org/documentation/hardware/raspberrypi/README.md
配置
- 两个5V,3.3V输出端口
- IO输入输出电压0-3.3V
- 支持输出PWM
- 两路SPI总线
- 两路IIC总线
- 一路串口
GPIO python库
GPIO Zero库:https://gpiozero.readthedocs.io/en/stable/
安装GPIO Zero库步骤
- 更新系统包
sudo apt update
- 安装包
- python3:
sudo apt install python3-gpiozero
- python2:
sudo apt install python-gpiozero
- python3:
LED例子
from gpiozero import Buttonfrom time import sleepbutton = Button(2)?while True: if button.is_pressed: print("Pressed") else: print("Released") sleep(1)
Button
from gpiozero import Buttonfrom time import sleep?button = Button(2)?while True: if button.is_pressed: print("Pressed") else: print("Released") sleep(1)
?
原文地址:https://www.cnblogs.com/BlogsOfLei/p/9206162.html
时间: 2024-10-11 16:37:03