GPIO Zero Python library1. Install GPIO Zero2. GPIO pin arrangement3. Pin number4. Import the GPIO Zero library5. Reference materials
GPIO Zero is a Python library for beginners, used to control the GPIO interface of the Raspberry Pi;
It provides a simple and easy-to-use interface for controlling peripheral devices such as LEDs, buttons, servos, motors, and various sensors.
GPIO Zero is installed by default in Raspberry Pi OS desktop images and Raspberry Pi OS Lite images.
Updated repository list and software
xxxxxxxxxx
sudo apt update
Install GPIO Zero
xxxxxxxxxx
sudo apt install python3-gpiozero
Open the terminal and run the command: pinout
xxxxxxxxxx
This tool is provided by the GPIO Zero Python library
The GPIO Zero library uses Broadcom (BCM) pin numbers instead of physical (BOARD) numbers: that is, to control GPIO17, you need to specify 17 instead of 11 for the pin number in the program.
Note: When using the Raspberry Pi GPIO pins, you need to pay attention to the pin connection method between the module and the Raspberry Pi motherboard to prevent damage to the motherboard.
xxxxxxxxxx
common problem:
LED: When using LED, a current limiting resistor should be added;
Motor: connected through the motor control board/driver board, not directly connected.
Import the entire library
xxxxxxxxxx
import gpiozero
Import a single interface: use the Button interface in the GPIO Zero library
xxxxxxxxxx
from gpiozero import Button
For more GPIO pin usage, please refer to the tutorial provided on the official website of the GPIO Zero library!
Official website link: https://gpiozero.readthedocs.io/en/latest/