🛠 LED et bouton avec libgpiod sur le port 40 broches

Banana Pi BPI-M2 Zero (Allwinner H2+ / H3) · debutant · Schéma : IMG-bananapi-m2-zero-debutant-2-clignoter-gpiod-m2-zero.svg — connecteur 40 broches du BPI-M2 Zero (brochage compatible Pi Zero W) : LED + résistance 330 Ω entre la broche 7 (PA6) et la masse, bouton entre la broche 32 (PL2) et GND (broche 6).

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials