🛠 Variation d'intensité d'une LED en PWM
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
- ODROID-M1 running Armbian (mainline or vendor kernel)
- For external PWM: LED, resistor, NPN transistor (the onboard LED requires no wiring)
- >
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
- Writing to pwm0 before exporting: the directory does not exist yet, wait 1 s.
- Period in nanoseconds: 20000000 = 20 ms, not 20.
- Driving a power LED directly from the pin: exceeding the GPIO max current, use a transistor.
- >
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash