🛠 Contrôler la LED SYS du NanoPi R5S
Objectives
The NanoPi R5S has four GPIO-controlled LEDs in the device tree: SYS (red), WAN, LAN1, and LAN2 (green). This tutorial teaches you how to discover them via sysfs, switch from an automatic trigger (heartbeat, netdev) to manual mode, and turn the SYS LED on/off from the command line. You will understand how the Linux LED subsystem (/sys/class/leds) works, which is applicable to any SBC board.
Hardware
- NanoPi R5S (2 or 4 GB) powered via USB-C PD 5 V/2 A minimum (PD power supply is mandatory; some fast chargers take a few seconds to start)
- microSD card with Debian/Ubuntu FriendlyElec or Armbian
- SSH access or HDMI screen + keyboard, or serial console (UART 3 pins at 1,500,000 bps)
Complete code
#!/bin/bash
# decouvrir_leds.sh — lister et piloter les LED du NanoPi R5S
ls /sys/class/leds/ # noms : SYS, WAN, LAN-1, LAN-2 (mainline)
# ou sys_led/wan_led/lan1_led... (vendor)
SYS=$(ls /sys/class/leds | grep -iE 'sys' | head -1)
echo "LED système détectée : $SYS"
# Mode manuel puis clignotement manuel
echo none | sudo tee "/sys/class/leds/$SYS/trigger"
echo 1 | sudo tee "/sys/class/leds/$SYS/brightness" # allumée
sleep 2
echo 0 | sudo tee "/sys/class/leds/$SYS/brightness" # éteinte
# Trigger heartbeat du noyau
echo heartbeat | sudo tee "/sys/class/leds/$SYS/trigger"
# Retour au trigger par défaut (habituellement cpu ou none)
cat "/sys/class/leds/$SYS/trigger" # la valeur active est entre crochets
Expected verification
After execution, ls /sys/class/leds/ displays at least four entries. The red SYS LED blinks in a heartbeat rhythm when the heartbeat trigger is active. In manual mode, the commands echo 1 / echo 0 on brightness visibly turn the LED on and off. Note: on recent mainline kernels (6.17+), netdev triggers have been removed from the device tree, and the default behavior of the LAN LEDs differs from vendor kernels 5.10/6.1.
Common errors
- Incorrect LED name: names change between vendor kernel (
wan_led) and mainline (WAN); always list them first withls /sys/class/leds. Permission deniedon sysfs files: usesudo teeinstead ofecho ... >(the redirection is performed by the shell without sudo).- Board does not boot: replace the USB-C power supply; a non-PD or too weak charger (less than 5 V/2 A) is the #1 cause.
- Confusing the red SYS LED (system status) with WAN (network activity): the red LED being permanently on is normal under Debian.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash