🛠 Fondu LED progressif avec PWM sous sysfs (meson)
Objectives
Implement an LED fade (intensity variation) on the Le Potato by exporting a PWM output from the meson controller via /sys/class/pwm, after enabling the corresponding device tree overlay.
Hardware
- Le Potato AML-S905X-CC running Armbian mainline
- LED + 330 Ω resistor on a PWM-compatible pin of the 40-pin connector
- Stable 5 V/2.5 A power supply (micro-USB)
Complete Code
#!/bin/bash
# fondu.sh — fondu LED via sysfs PWM (adapter pwmchipN selon votre overlay)
CHIP=0 # /sys/class/pwm/pwmchip$CHIP
OUT=/sys/class/pwm/pwmchip$CHIP
export $OUT/pwm0 2>/dev/null || echo 0 | sudo tee $OUT/export
duty_max=1000000 # période 1 ms en nanosecondes
echo $duty_max | sudo tee $OUT/pwm0/period
echo 1 | sudo tee $OUT/pwm0/enable
while true; do
for ((d=0; d<=duty_max; d+=25000)); do
echo $d | sudo tee $OUT/pwm0/duty_cycle >/dev/null; sleep 0.02; done
for ((d=duty_max; d>=0; d-=25000)); do
echo $d | sudo tee $OUT/pwm0/duty_cycle >/dev/null; sleep 0.02; done
done
Expected Verification
After enabling the overlay and rebooting, /sys/class/pwm/pwmchipN exists; after echo 0 > export, the pwm0 node appears and the LED fades in and out in a loop.
Common Errors
- PWM overlay not enabled: no
/sys/class/pwm/pwmchipNlinked to the header — enable the interface and reboot. - Confusing period and duty_cycle: both are in nanoseconds; duty_cycle > period is ignored or capped.
- Writing to
exportwithout permissions: use sudo/tee. - LED on a non-PWM pin: no effect even if sysfs responds — cross-reference with the schematic and
gpioinfo.
Other tutorials for this board
- Faire clignoter une LED en C avec libgpiod sur Le Potato
- Lire un bouton poussoir avec libgpiod (pull-up interne)
- GPIO en Python avec python3-libgpiod sur Le Potato
- Capteur BME280 (I2C) sur Le Potato : overlay et lecture
- Console série (ttyAML0) et SSH sur Le Potato
- Boot SD/eMMC et récupération (pyamlboot) sur Amlogic S905X
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash