🛠 Variation d'intensité d'une LED avec un signal PWM

Orange Pi 3B (Rockchip RK3566) · intermediaire · Schéma : IMG-orangepi-3b-intermediaire-1-opi3b-pwm-led.svg — LED pilotée par une sortie PWM du connecteur 40 broches de l'Orange Pi 3B via un transistor

Objectives

Vary the intensity of an LED (breathing light effect) using a PWM signal generated by the Orange Pi 3B. The official datasheet indicates PWM on the 40-pin connector; the exact PWM pin to use >

Hardware

Complete Code

# 1. Repérer les contrôleurs PWM exposés
ls /sys/class/pwm/            # pwmchip0, pwmchip1...
# 2. Réserver un canal (exemple : canal 0 du pwmchip0)
echo 0 | sudo tee /sys/class/pwm/pwmchip0/export
# 3. Signal : période 20 kHz (en ns), puis rapport cyclique 0..period
sudo sh -c 'echo 50000 > /sys/class/pwm/pwmchip0/pwm0/period'
sudo sh -c 'echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable'
# 4. Respiration lumineuse (fade)
#!/bin/bash
P=/sys/class/pwm/pwmchip0/pwm0
for p in $(seq 0 500 50000); do echo $p | sudo tee $P/duty_cycle >/dev/null; sleep 0.03; done
for p in $(seq 50000 -500 0); do echo $p | sudo tee $P/duty_cycle >/dev/null; sleep 0.03; done

Expected Verification

The LED gradually brightens and then dims. cat $P/duty_cycle follows the written values; the complete cycle lasts approximately 6 seconds.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials