🛠 PWM : faire respirer la LED bleue
Objectives
Master PWM output on the ODROID-XU4 under mainline Linux: the device tree exposes the PWM0 channel for the fan and PWM2 for the blue heartbeat LED. You will release the kernel trigger to manually control the duty cycle and make the LED "breathe."
Hardware
- ODROID-XU4 running Armbian (kernel 6.6.x, mainline device tree exynos5422-odroidxu4)
- Root access (sudo); no wiring required, the blue LED is onboard
Complete Code
#!/usr/bin/env bash
# respirer.sh — fade de la LED bleue heartbeat (PWM2) du XU4
set -euo pipefail
CHIP=/sys/class/pwm/pwmchip0
# 1) Liberer le trigger heartbeat pose par le device tree
if [ -e /sys/class/leds/odroid:blue:heartbeat/trigger ]; then
echo none | sudo tee /sys/class/leds/odroid:blue:heartbeat/trigger
fi
# 2) Exporter le canal PWM2 (PWM0 = ventilateur, ne pas y toucher !)
echo 2 | sudo tee "$CHIP/export" >/dev/null 2>&1 || true
PWM="$CHIP/pwm2"
sudo tee "$PWM/period" >/dev/null <<< 1000000 # periode 1 ms (ns)
for d in $(seq 0 50000 1000000) $(seq 1000000 -50000 0); do
echo "$d" | sudo tee "$PWM/duty_cycle" >/dev/null
sleep 0.03
done
Expected Verification
The onboard blue LED gradually increases and decreases in brightness. cat $PWM/duty_cycle reflects the written values. The fan (pwm0, controlled by the thermal governor at 50/60/70 °C) continues to operate normally.
Common Errors
- Forgetting to write
noneto the heartbeat trigger: the kernel retains control of the channel, and your writes are ignored. - Exporting channel 0: it powers the pwm-fan; taking control of it breaks thermal regulation.
- Confusing period and duty cycle: both are expressed in nanoseconds; duty > period is invalid.
- Running without sudo: sysfs files are owned by root.
- Neglecting wear: fading in an infinite loop consumes some CPU; add a sleep.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash