🛠 PWM : faire respirer la LED bleue

Hardkernel ODROID-XU4 (Samsung Exynos5422) · intermediaire · Schéma : IMG-odroid-xu4-intermediaire-1-odroidxu4-pwm-led.svg — Signal PWM en dents de scie sortant du contrôleur PWM de l'ODROID-XU4 (canal 2) vers la LED bleue heartbeat, canal 0 relié au ventilateur

Objectives

Master PWM output on the ODROID-XU4 under mainline Linux: the device tree exposes the PWM0 channel for the fan and PWM2 for the blue heartbeat LED. You will release the kernel trigger to manually control the duty cycle and make the LED "breathe."

Hardware

Complete Code

#!/usr/bin/env bash
# respirer.sh — fade de la LED bleue heartbeat (PWM2) du XU4
set -euo pipefail
CHIP=/sys/class/pwm/pwmchip0

# 1) Liberer le trigger heartbeat pose par le device tree
if [ -e /sys/class/leds/odroid:blue:heartbeat/trigger ]; then
  echo none | sudo tee /sys/class/leds/odroid:blue:heartbeat/trigger
fi

# 2) Exporter le canal PWM2 (PWM0 = ventilateur, ne pas y toucher !)
echo 2 | sudo tee "$CHIP/export" >/dev/null 2>&1 || true
PWM="$CHIP/pwm2"

sudo tee "$PWM/period" >/dev/null <<< 1000000      # periode 1 ms (ns)
for d in $(seq 0 50000 1000000) $(seq 1000000 -50000 0); do
  echo "$d" | sudo tee "$PWM/duty_cycle" >/dev/null
  sleep 0.03
done

Expected Verification

The onboard blue LED gradually increases and decreases in brightness. cat $PWM/duty_cycle reflects the written values. The fan (pwm0, controlled by the thermal governor at 50/60/70 °C) continues to operate normally.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials