🛠 Faire clignoter une LED en C avec libgpiod sur Le Potato

Libre Computer Amlogic boards — libre-amlogic (flagship: Le Potato AML-S905X-CC) · debutant · Schéma : IMG-libre-amlogic-debutant-1-libre-amlogic-debutant-clignotement-led-c.svg — Le Potato AML-S905X-CC, broche 3 du connecteur 40 broches (GPIOAO_5) vers LED et résistance 330 Ω puis masse.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials