🛠 Faire clignoter une LED en C avec libgpiod sur Le Potato
Objectives
Blink an LED on the 40-pin connector of the Le Potato (AML-S905X-CC) in C using libgpiod, the interface officially recommended by Libre Computer — there is no wiringPi on this board and the vendor refuses to port it.
Hardware
- Le Potato AML-S905X-CC running Armbian (mainline kernel, meson-gxl)
- LED + 330 Ω resistor
- Physical pin 3 = GPIOAO_5 = gpiochip0 line 5; 3.3 V logic, no 5 V tolerant pins
- Ground on a GND pin (6, 9, 14, 20, 25, 30, 34 or 39)
Complete code
/* blink.c — gcc blink.c -o blink -lgpiod (paquet libgpiod-dev) */
#include <gpiod.h>
#include <stdio.h>
#include <unistd.h>
int main(void) {
struct gpiod_chip *chip = gpiod_chip_open_by_number(0);
if (!chip) { perror("gpiochip0"); return 1; }
struct gpiod_line *line = gpiod_chip_get_line(chip, 5); /* broche 3 */
if (!line || gpiod_line_request_output(line, "blink", 0)) {
perror("request"); return 1;
}
for (int i = 0; i < 10; i++) {
gpiod_line_set_value(line, i & 1);
usleep(200000);
}
gpiod_line_release(line);
gpiod_chip_close(chip);
return 0;
}
Expected verification
./blink blinks the LED 10 times at 5 Hz. During execution, gpioinfo gpiochip0 shows line 5 (named "7J1 Header Pin3" in the device tree) as requested by the consumer "blink".
Common errors
- Confusing physical pin and GPIO line: pin 3 = line 5 (GPIOAO_5). Check with
lgpio info 3(libretech-wiring-tool) orgpioinfo. - libgpiod 2.x API differs from 1.x (
gpiod_line_request): adapt according to the distribution. - Sending 5 V to a pin: no pin is 5 V tolerant, board damage.
- Permission denied: add your user to the
gpiogroup or run as root.
Other tutorials for this board
- Lire un bouton poussoir avec libgpiod (pull-up interne)
- GPIO en Python avec python3-libgpiod sur Le Potato
- Fondu LED progressif avec PWM sous sysfs (meson)
- Capteur BME280 (I2C) sur Le Potato : overlay et lecture
- Console série (ttyAML0) et SSH sur Le Potato
- Boot SD/eMMC et récupération (pyamlboot) sur Amlogic S905X
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash