🛠 Surveiller température et fréquence CPU
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
- Raspberry Pi 3 Model B (note: pre-2019 boards use the BCM2837 without a heatsink, more sensitive to heat than the BCM2837B0 with a metal lid)
- Raspberry Pi OS Lite, included tools:
vcgencmd,/sys/class/thermal - Optional: heatsinks or a small USB fan to test the cooling effect
- Test load:
stress(sudo apt install -y stress)
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
- Panicking over a non-zero
throttledvalue: it is a history; restart or read the bits to distinguish undervoltage (bit 0) from thermal throttling. - Confusing undervoltage and overheating: a thin micro-USB cable triggers the same throttling; check the 2.5 A power supply first.
- Expecting 1.4 GHz: the 3B is capped at 1.2 GHz (the B0 allows it, but not the 3B firmware).
- Reading a single snapshot: throttling is transient; log every 5 s with the script.
- Closed case without airflow on a pre-2019 board without a lid: throttling is guaranteed under sustained load — this is precisely what motivated the switch to the BCM2837B0.
Other tutorials for this board
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython