🛠 Allumer une LED via le GPIO
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
- ODROID-XU4 alimenté par un adaptateur 5 V/4 A (barillet 5,5/2,1 mm)
- 1 LED + résistance 330 Ω + fils Dupont
- Image Armbian (kernel 6.6.x) ou Ubuntu Hardkernel
- La carte possède un header 30 broches (GPIO, IRQ, SPI, ADC) et un header 12 broches (GPIO, I2S, I2C)
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
- Oublier
sudo: wiringPi a besoin d'un accès privilégié,wiringPiSetuprenvoie alors -1. - Utiliser une table de brochage Raspberry Pi : le fork Hardkernel (
github.com/hardkernel/wiringPi) a ses propres tables ODROID, toujours passer pargpio readall. - Appliquer 5 V sur une broche : les IO n'ont pas de protection contre la surtension, la carte peut être détruite.
- Mauvaise résistance : sans 330 Ω, la LED grille (ou tire trop de courant).
Autres tutoriels pour cette carte
Exemples de code pour cette carte
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash