🛠 GPIO avec libgpiod : faire clignoter une LED et lire un bouton
Objectives
Learn the GPIOs of the ZERO 3W as of 2026: no sysfs (deprecated), but libgpiod, the recommended path in Radxa documentation. The 40-pin connector is electrically compatible with Raspberry Pi (3.3 V logic, never 5 V on the pins!), with its specific pitfalls: pins 3, 5, 27, and 28 are unusable as GPIOs due to I2C pull-up resistors, and pins 8/10 = U-Boot serial console. You will write a blink program in C and an interrupt-driven button in Python.
Hardware
- 1 Radxa ZERO 3W (the 40-pin connector is unsoldered on base SKUs — plan for a soldering iron or higher-tier SKUs where it is soldered)
- 1 LED + 330 Ω resistor; 1 push button
- Breadboard jumper wires; stable 5 V/2 A power supply
sudo apt install gcc libgpiod-dev gpiod python3-libgpiod
Pinout rules (source: official hardware-interface)
- All GPIO logic is 3.3 V (absolute maximum 3.63 V) — never inject 5 V into a pin.
- Pins 3, 5, 27, 28: additional I2C pull-ups, “behave abnormally as GPIO” — do not use them as digital I/O.
- Pins 8/10 (TX/RX): this is UART2_M0, the U-Boot console — see the dedicated serial tutorial.
- Pin 35 = GPIO3_A4; pin 11 = GPIO3_A1. Rockchip rule: bank 3 →
gpiochip3, letter A=0/B=8 + offset → line 4 for A4.
Blink in C (pin 35, GPIO3_A4)
/* blink.c — compile : gcc blink.c -o blink -lgpiod */
#include <gpiod.h>
#include <stdio.h>
int main(void) {
struct gpiod_chip *chip = gpiod_chip_open_by_name("gpiochip3");
if (!chip) { perror("gpiochip3"); return 1; }
struct gpiod_line *line = gpiod_chip_get_line(chip, 4); /* A4 = ligne 4 */
if (gpiod_line_request_output(line, "blink", 0) < 0) { perror("request"); return 1; }
for (int i = 0; i < 10; i++) { /* 5 cycles ON/OFF */
gpiod_line_set_value(line, 1); sleep(1);
gpiod_line_set_value(line, 0); sleep(1);
}
gpiod_line_release(line); gpiod_chip_close(chip);
return 0;
}
Without compiling: gpioset -m signal $(gpiofind GPIO3_A4)=1 — gpiofind avoids hardcoding chip/line.
Event-driven button (pin 11, GPIO3_A1)
#!/usr/bin/env python3 # apt install python3-libgpiod gpiod
# Bouton : broche 11 -> 3V3 ; pull-down (flag gpiod ou résistance externe vers GND)
import gpiod
chip = gpiod.Chip("gpiochip3")
line = chip.get_line(1) # A1 = ligne 1
line.request(consumer="bouton", type=gpiod.LINE_REQ_EV_RISING_EDGE)
while True:
if line.event_wait(sec=None): line.event_read; print("appui")
Expected verification
gcc blink.c -o blink -lgpiod && ./blink makes the LED blink 5 times. The Python script prints “press” on each button press, without polling (kernel blocking). gpioinfo gpiochip3 shows your requested lines.
Common errors
- Using pins 3/5/27/28 as GPIO: the board’s I2C pull-ups distort everything — the official documentation is explicit.
- Counting like on a Pi (BCM GPIO): here you reason in chip/line (gpiochip3, line 4) or kernel name via
gpiofind GPIO3_A4. - Forgetting that the connector is not soldered on entry-level SKUs: check your order before buying wires!
- 5 V on a pin: the absolute maximum is 3.63 V — direct 5 V can destroy the pin.
- Requesting a line already occupied by an overlay:
requestfails — list active overlays (sudo rsetup) and thegpioinfoof each chip. - Connecting to pins 8/10 thinking you are doing safe GPIO: you short-circuit the U-Boot console (see the UART tutorial).
Other tutorials for this board
- Premiers pas avec la Radxa ZERO 3W : flasher Radxa OS et démarrer
- Wi-Fi 6 et Bluetooth 5.4 : se connecter, choisir l'antenne, connaître sa révision
- Installer le système sur l'eMMC : rkdeveloptool, MaskROM et gain de fiabilité
- Caméra MIPI CSI : brancher une Raspberry Pi Camera (OV5647/IMX219) sur la ZERO 3W
- Noyau mainline avec Armbian : vérifier le device tree, ajouter un overlay, lire le SARADC
- NPU 0,8 TOPS : inférence RKNN (YOLO, Whisper) sur la ZERO 3W
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash