🛠 Faire clignoter la LED de statut via GPIO
Objectives
Understand how the Orange Pi PC controls its GPIO pins and make the red status LED blink (PA15, named "orangepi:red:status" in the mainline device tree). You will learn the two possible approaches: libgpiod (recommended under Armbian/mainline) and WiringOP (the wiringPi fork maintained by Xunlong for Orange Pi).
Hardware
- Orange Pi PC running Armbian (mainline kernel)
- 5 V / 2 A minimum power supply on the DC jack (never the micro-USB OTG port, which cannot power the board)
- Optional: an external LED + 330 Ω resistor if you want to control a pin on the 40-pin connector
- Warning: 3.3 V logic; some power pins on the connector may deliver an unknown voltage (13 V/26 V reported on this H3 generation) — measure with a multimeter before connecting anything.
Complete Code
libgpiod approach (no proprietary library):
sudo apt install gpiod
# PA15 = broche 15 de gpiochip0 (banque PA)
gpioset "$(gpiofind PA15)" 1; sleep 0.2; gpioset "$(gpiofind PA15)" 0
# Boucle de clignotement
while true; do gpioset "$(gpiofind PA15)" 1; sleep 0.5; gpioset "$(gpiofind PA15)" 0; sleep 0.5; done
WiringOP approach in C (sunxi numbering: PA15 = 0×32 + 15 = 15):
/* blink.c — LED PA15 via WiringOP */
#include <wiringPi.h>
#define STATUS_LED 15
int main(void) {
if (wiringPiSetupG == -1) return 1;
pinMode(STATUS_LED, OUTPUT);
for (;;) {
digitalWrite(STATUS_LED, HIGH);
delay(150);
digitalWrite(STATUS_LED, LOW);
delay(150);
}
}
git clone https://github.com/orangepi-xunlong/wiringOP && cd wiringOP
./build && sudo ./build install
gcc -O2 blink.c -o blink -lwiringPi && sudo ./blink
Expected Verification
The red LED on the board blinks approximately 3 times per second. With gpioinfo, you see gpiochip0 (banks PA to PH) and gpiochip1 (r_pio). The PA15 line switches to output mode.
Common Errors
- Confusing the two gpiochips: PL10 (green LED) is on gpiochip1, PA15 is on gpiochip0.
- Using the physical pin number of the connector instead of the GPIO number (PA15 = 15 in WiringOP, not 10).
- Powering the board via micro-USB: the board does not turn on at all, this is normal, only the DC jack powers it.
- Forgetting
sudo: without permissions on /dev/gpiochip0, gpioset fails.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash