樹莓派 Raspberry PI之GPIO


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2024 CODEPRJ.COM