🛠 LED et bouton avec libgpiod sur le port 40 broches
Objectives
The BPI-M2 Zero features a 40-pin connector whose pinout matches that of the Raspberry Pi (Zero W cases and hats fit), but the pins belong to Allwinner banks: gpiochip0 covers banks A to E (PA6 = pin 7, already wired as PWM1 by default) and gpiochip1 covers the R_PIO PL bank (PL2 = pin 32, PL4 = pin 36; PL10 drives the red power LED). You will blink an LED and read a button using libgpiod tools, without any proprietary library.
Hardware
- BPI-M2 Zero running Armbian (mainline kernel)
- LED + 330 Ω resistor between pin 7 (PA6) and a GND pin (the logic level is 3.3 V, never apply 5 V to a pin)
- Push button between pin 32 (PL2) and pin 6 (GND)
- Breadboard and Dupont wires
Complete code
sudo apt update && sudo apt install -y gpiod
# Repérer les puces et le nom des lignes du connecteur (CON2-Pxx)
gpiodetect
gpioinfo gpiochip0 | grep -e CON2-P07 -e CON2-P11
# PA6 est PWM1 par défaut : libérer la broche si un overlay pwm la revendique
sudo armbian-config # System > Hardware > décocher_pwm/pwm-user, puis reboot
# Clignoter 10 fois sur PA6 (broche 7), impulsions de 500 ms
for i in $(seq 10); do
gpioset -c gpiochip0 PA6=1 --time 500ms
sleep 0.5
done
# Écouter le bouton sur PL2 — attention : banque PL = gpiochip1 !
gpiomon --num-events 5 --rising-edge gpiochip1 PL2
Expected verification
The LED blinks ten times; gpiomon displays one event per press (rising-edge thanks to the internal pull-up or wiring to GND); gpioinfo shows the PA6 line as "requested" during the gpioset command. The red PWR LED (PL10) remains permanently lit, it is not the test LED.
Common errors
- Looking for PL2 on gpiochip0: the R_PIO bank is a second controller, gpiochip1 — gpiodetect shows this.
- Forgetting that PA6 is claimed by the PWM driver: gpioset fails until the overlay is disabled (or use a free pin).
- Sending 5 V to a logic pin: the connector provides 3.3 V logic, the pins are not 5 V tolerant everywhere.
- Running gpioset without permissions: use sudo or add the user to the gpio group.
- Confusing the numbering: here we name the lines (PA6, PL2), not the wiringPi indices which differ depending on the forks.
Other tutorials for this board
- Flasher Armbian et premier boot du BPI-M2 Zero
- Wi-Fi AP6212 : le piège de l'antenne U.FL non fournie
- Console série sur USB-OTG : dépanner sans réseau ni câble UART
- Activer le bus SPI0 et piloter un petit écran TFT
- Survivre avec 512 Mo : zram, swap compressé et services légers
- Câbler l'Ethernet 10/100 EMAC avec le carrier Zero-EPHY
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash