🛠 Surveiller température et fréquence CPU sous contrainte
Objectives
Instrument the Orange Pi 3B (4× Cortex-A55 up to 1.8 GHz, RK3566 in 22 nm): read thermal zone temperatures, observe the actual frequency of each core, trigger an alert threshold, and test passive cooling vs. a fan on the 2-pin connector.
Hardware
- Orange Pi 3B running Armbian, 5 V / 3 A power supply
- Adhesive heatsink and/or 5 V fan on the 2-pin fan connector
- >
Complete Code
# 1. Températures (degrés milli-C) et politiques thermiques
paste <(for z in /sys/class/thermal/thermal_zone*/type; do cat $z; done) \
<(for z in /sys/class/thermal/thermal_zone*/temp; do echo "scale=1;$(cat $z)/1000"|bc; done)
# 2. Fréquence réelle par cœur pendant une charge
sudo apt install stress-ng
(trap 'kill %1' INT; stress-ng --cpu 4 --timeout 60s) &
while sleep 2; do grep -H . /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq; done
# 3. Alerte simple toutes les 10 s
while sleep 10; do
t=$(($(cat /sys/class/thermal/thermal_zone0/temp)/1000))
[ $t -gt 75 ] && logger -p user.warning "CPU trop chaud : ${t}°C"
done
# 4. Compteur de passages en limitation thermique (throttle)
grep . /sys/class/thermal/thermal_zone*/policy 2>/dev/null
sudo dmesg | grep -i -e thermal -e throttle
Expected Verification
Under stress-ng --cpu 4, scaling_cur_freq climbs toward 1.8 GHz and then stabilizes; without a heatsink, the frequency drops back down and dmesg may display thermal messages. With a heatsink/fan, the temperature caps out lower and the frequency holds longer.
Common Errors
- Reading
/sys/class/thermal/thermal_zone0/tempwithout dividing by 1000: values are in milli-degrees. - Relying on
cpufreq-infoonly once: frequency is instantaneous, so you must sample under load. - Using a 5 V / 2 A power supply: throttling may come from under-powering rather than thermal issues.
- Reversing the 2-pin fan (polarity) or connecting it without a common ground.
- Comparing zones:
soc-thermal(die) andpmu-thermaldo not rise at the same rate.
Other tutorials for this board
- Faire clignoter une LED via le GPIO avec libgpiod
- Lire un bouton poussoir et afficher l'état dans la console
- Premier script Python : bouton + LED avec python3-libgpiod
- Variation d'intensité d'une LED avec un signal PWM
- Interroger un capteur I2C sur les broches 3/5 du connecteur
- Configurer Ethernet gigabit et Wi-Fi puis se connecter en SSH
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash