🛠 Faire clignoter une LED via le GPIO avec libgpiod
Objectives
Discover the 40-pin connector on the Radxa ROCK 3B (Rockchip RK3568) and blink an LED using libgpiod, the modern Linux GPIO API officially recommended by Radxa — the legacy "gpio export" sysfs mechanism is deprecated. You will learn how to identify the correct chip (gpiochip) and line using gpiofind/gpioinfo, rather than copying numbers inherited from Raspberry Pi tutorials.
Hardware
- Radxa ROCK 3B running Radxa OS (Debian) or a mainline image, powered via USB-C (PD 12 V / 2 A recommended by official documentation)
- 1 LED + 330 Ω resistor, female-to-male Dupont cables
- HDMI display or SSH session
Complete Code
sudo apt update && sudo apt install -y gpiod
gpiodetect # RK3568 : gpiochip0..gpiochip3 (banques GPIO0..GPIO3)
gpiofind PIN_7 # renvoie « gpiochipLigne » pour la broche 7 du connecteur
# Nommage Rockchip : GPIO3_C5 -> gpiochip3, ligne 21 (banque*8 + groupe + index)
sudo gpioset -m signal $(gpiofind PIN_7) 1 & # reste haut jusqu'au Ctrl-C
sudo gpioget $(gpiofind PIN_11) # lire une autre broche
# Clignotage 10 cycles sans compiler :
for i in $(seq 1 10); do sudo gpioset --time=0.2 $(gpiofind PIN_7) 1; sleep 0.3; done
Expected Verification
gpiodetect displays gpiochip0 through gpiochip3. gpiofind PIN_7 returns a chip/line pair; with the correct wiring, the LED lights up for ~0.2 s on each loop iteration. The RGB heartbeat LED (driven by the "heartbeat" trigger in the device tree) already blinks under Linux: you can disable it with echo none | sudo tee /sys/class/leds/*/trigger if it interferes with your measurements.
Common Errors
- Looking for Raspberry Pi BCM numbers: under Radxa OS / Rockchip kernel, you work with gpiochip + libgpiod lines, and the connector pinout is Radxa's (color-coded), not the Pi's.
- Forgetting
sudo: GPIO lines are restricted until the "gpio" udev rule is configured (re-login after adding your user to the gpio group). - Running
gpiosetwithout-m signalor--timecauses it to exit immediately and reset the pin to 0: you won't see any blinking. - Wiring a GPIO to 5 V: the connector logic operates at 3.3 V (5 V is only available on power pins 2/4).
- Forcing a Raspberry Pi HAT onto the connector: compatibility is "mostly compatible" (ROCK Pi 4 / Pi 3-4) but not exact — compare the connector color coding beforehand, otherwise you risk wiring a UART signal to an I2C pin.
Other tutorials for this board
- Lire un bouton poussoir en Python avec python3-libgpiod
- Premier réseau : Ethernet double gigabit, Wi-Fi optionnel et SSH
- Installer et booter le système sur un SSD NVMe (M.2 M-Key)
- Interroger un capteur I2C sur le connecteur 40 broches
- Surveiller température et fréquence CPU, piloter le ventilateur PWM
- Routeur / passerelle réseau double Gigabit avec OpenWrt et PoE
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash