1. 程式人生 > >樹莓派 Raspberry PI之GPIO

樹莓派 Raspberry PI之GPIO

document ble lock back ocs 輸入輸出 indent 1.5 res

樹莓派 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

LED例子

from gpiozero import Button
from time import sleep
button = Button(2)
?
while True:
if button.is_pressed:
print("Pressed")
else:
print("Released")
sleep(1)

Button


from gpiozero import Button
from time import sleep
?
button = Button(2)
?
while True:
if button.is_pressed:
print("Pressed")
else:
print("Released")
sleep(1)

?

樹莓派 Raspberry PI之GPIO