🛠 Surveiller température et fréquence CPU

Raspberry Pi 3 Model B (model-3b) · avance · Schéma : IMG-model-3b-avance-2-model3b-surveillance-thermique.svg — courbe de température du BCM2837 avec zones 80 °C (ralentissement progressif) et 85 °C (bridage matériel CPU+GPU), sondes vcgencmd et /sys/class/thermal

Objectives

Set up monitoring of the temperature and core frequency of the Raspberry Pi 3 Model B. Know the thresholds for the 3B: progressive throttling of the Arm cores between 80 °C and 85 °C, hardware throttling of CPU + GPU at 85 °C (no soft software limit on this model). Interpret the get_throttled flag and log the history to size a case or a fan.

Hardware

Full code

#!/usr/bin/env bash
# thermal_log.sh — échantillonne température, fréquence et drapeaux de bridage
# seuils du 3B : 80 °C ralentissement progressif, 85 °C bridage dur CPU+GPU

while true; do
  temp_c=$(vcgencmd measure_temp | grep -oE '[0-9]+\.[0-9]+')
  temp_sysfs=$(($(cat /sys/class/thermal/thermal_zone0/temp) / 1000))
  freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)
  throttled=$(vcgencmd get_throttled | cut -d= -f2)
  echo "$(date -Is) temp_C=$temp_c temp_sysfs=$temp_sysfs freq_kHz=$freq throttled=$throttled"
  sleep 5
done | tee -a /var/log/thermal.log

# Dans un autre terminal, provoquer la montée en température :
#   stress --cpu 4 --timeout 300
# Decoder un drapeau (ex. 0x50000 = sous-tension + bridage) :
#   printf '%x\n' $((0x50000 & (1<<0)))   # bit 0 : sous-tension

Expected verification

At idle, vcgencmd measure_temp and the sysfs file give the same temperature (±1 °C), for example 40–45 °C. During stress --cpu 4, the scaling_cur_freq frequency drops below 1200000 kHz when the temperature exceeds 80 °C, and vcgencmd get_throttled changes to a non-zero value with the throttling bit set. After stopping the load, temperature and frequency drop back down. The log allows tracing the curve and comparing open/closed cases.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials