🛠 Allumer une LED via le GPIO

Hardkernel ODROID-XU4 (Samsung Exynos5422) · debutant · Schéma : IMG-odroid-xu4-debutant-1-odroidxu4-led-gpio.svg — L'ODROID-XU4 avec son header 30 broches, une LED et sa résistance 330 Ω branchées sur une broche GPIO, alimentation 5 V/4 A

Objectifs

Faire clignoter une LED sur l'ODROID-XU4 en utilisant le fork wiringPi maintenu par Hardkernel, ou libgpiod sous Armbian. Vous apprendrez à identifier les broches GPIO avec gpio readall (ou gpioinfo) et à respecter les niveaux de tension des broches.

Matériel

Code complet

/* blink.c — clignotement LED via wiringPi (fork Hardkernel)
 * Build : gcc -o blink blink.c -lwiringPi */
#include <wiringPi.h>
#include <stdio.h>

int main(void) {
    if (wiringPiSetup == -1) {   /* numerotation wiringPi */
        fprintf(stderr, "wiringPiSetup a échoue (lancer en root ?)\n");
        return 1;
    }
    /* Lancer d'abord `gpio readall` et choisir une broche programmable
       du header principal. Ne PAS deviner depuis une table Raspberry Pi. */
    const int LED = 0;
    pinMode(LED, OUTPUT);
    for (;;) {
        digitalWrite(LED, HIGH); delay(150);
        digitalWrite(LED, LOW);  delay(150);
    }
}

Compilez puis lancez : gcc -o blink blink.c -lwiringPi && sudo ./blink.

Vérification attendue

La LED clignote environ 3 fois par seconde (150 ms allumée, 150 ms éteinte). gpio readall affiche la broche choisie en mode OUTPUT et à l'état 1/0 en alternance.

Erreurs fréquentes

Autres tutoriels pour cette carte

Exemples de code pour cette carte

← Retour à la fiche 🛠 Tous les tutoriels