🛠 Fondu LED progressif avec PWM sous sysfs (meson)

Libre Computer Amlogic boards — libre-amlogic (flagship: Le Potato AML-S905X-CC) · intermediaire · Schéma : IMG-libre-amlogic-intermediaire-1-libre-amlogic-intermediaire-pwm-fondu-led.svg — LED sur une broche PWM du connecteur 40 broches du Le Potato via résistance, fondu piloté par /sys/class/pwm après activation de l'overlay.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials