🛠 Variation d'intensité d'une LED en PWM

ODROID-M1 (Hardkernel) · intermediaire · Schéma : IMG-odroid-m1-intermediaire-1-odroidm1-pwm-led.svg — LED de puissance pilotée par un transistor NPN depuis une broche PWM du connecteur 40 broches, avec résistance de base

Objectives

Make an LED "breathe" by modulating the pulse width (PWM). Two approaches on the ODROID-M1: the onboard led-work LED via kernel triggers (guaranteed to work on Armbian/mainline, as the device tree rk3568-odroid-m1.dts registers it with the heartbeat trigger), and the RK3568B2 hardware PWM on the 40-pin connector.

Hardware

Full Code

# 1) Sans câblage : variation logicielle de la LED bleue embarquée
ls /sys/class/leds/led-work/trigger   # contient « timer » et « heartbeat »
echo timer > /sys/class/leds/led-work/trigger
echo 200 > /sys/class/leds/led-work/delay_on
echo 800 > /sys/class/leds/led-work/delay_off

# 2) PWM matériel (si un pwmchip est exposé côté connecteur)
cat /sys/class/pwm/pwmchip*/label 2>/dev/null
# Exporter le canal 0, période 20 ms, rapport cyclique 50 % :
echo 0 > /sys/class/pwm/pwmchip0/export
sleep 1
printf 20000000 > /sys/class/pwm/pwmchip0/pwm0/period
printf 10000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
printf 1 > /sys/class/pwm/pwmchip0/pwm0/enable

Expected Verification

The blue LED blinks rhythmically (timer mode); with hardware PWM, the external LED gradually modulates from off to full intensity.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials