🛠 Surveiller température et fréquence CPU
Objectives
Instrument the Model B Rev 2: read the temperature and the ARM11 frequency (700 MHz) via vcgencmd, understand thermal throttling above 85 °C (and in case of undervoltage), and verify an overclock from the config.txt era.
Hardware
- Raspberry Pi Model B Rev 2 (BCM2835, 512 MB), stable 5 V power supply
- Heatsink or fan for the load experiment
sudo apt install -y sysstat(optional); root access fornproc/load
Complete code
# Boucle de surveillance: temperature, horloge courante, drapeau de bridage
while true; do
printf "%s " "$(date +%T)"
vcgencmd measure_temp
vcgencmd measure_clock arm
vcgencmd get_throttled
sleep 5
done
# Surcharge CPU (ARMv6 mono-cœur) pour declencher le bridage:
yes > /dev/null &
# Overclock classique Rev 2 dans /boot/config.txt (avec refroidissement):
# arm_freq=900
# over_voltage=4
# force_turbo=1
/* rev.c - confirmer le modele avant d'interpretter les mesures.
Build: gcc rev.c -o rev && ./rev */
#include <stdio.h>
#include <string.h>
int main(void) {
char line[256];
FILE *f = fopen("/proc/cpuinfo", "r");
if (!f) { perror("cpuinfo"); return 1; }
while (fgets(line, sizeof line, f))
if (strncmp(line, "Revision", 8) == 0) printf("%s", line);
fclose(f);
return 0;
}
Expected verification
measure_temp rises with load then stabilizes; measure_clock arm drops below 900000000 (or 700000000) when the temperature exceeds 85 °C; get_throttled displays a non-zero flag in case of an event, with bits 16 and above signaling an undervoltage.
Common errors
- Reading
get_throttledonly once: the flag is historical, it must be compared over time. - Overclocking without cooling or a proper power supply: SD card instability and permanent throttling.
- Confusing °C with the throttling flag state: the temperature goes down, but the flag remains.
- Forgetting that the GPU and CPU share the 512 MB: a high
gpu_mem=starves monitoring and load.
Other tutorials for this board
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython