🛠 Surveiller température et fréquence du BCM2835
Objectives
Set up continuous monitoring of the BCM2835 SoC: temperature, current ARM frequency, and throttling indicator. The firmware throttles the CPU above 85 °C or when undervoltage is detected — no hard cutoff is documented for this board. You will use vcgencmd, log to a text database, and interpret the get_throttled flag bit by bit.
Hardware
- Raspberry Pi Model B Rev 1 (with or without heatsink/case — compare!)
- Legacy 32-bit image with
raspberrypi-firmware(vcgencmdpreinstalled) - Test load:
sudo apt install -y stress(optional, to induce throttling) - SSH access (see the Ethernet tutorial) to follow logs remotely.
Complete code
#!/bin/sh
# surveil.sh - journalise temperature, clock et drapeau de bridage
# format: horodatage;temp_c;arm_hz;throttled_hex
while true; do
T=$(vcgencmd measure_temp | sed 's/temp=//;s/.C//')
C=$(vcgencmd measure_clock arm | cut -d= -f2)
V=$(vcgencmd get_throttled | cut -d= -f2)
echo "$(date -Is);${T};${C};${V}" >> /var/log/pisoc.csv
sleep 30
done
# Lecture rapide :
# vcgencmd measure_temp -> 'temp=52.3'C (bridage au-dela de 85 C)
# vcgencmd measure_clock arm -> 700000000 au repos nominal
# vcgencmd get_throttled -> 0x0 = rien a signaler
# bit 0 sous-tension | bit 2 sous-tension subie | bit 3 bridage thermique
# bit 4 bridage sous-tension | bits 16-19 = memoire des evenements passes
# Provoquer la montee (test seulement, 256 MB de RAM : pas de stress --vm) :
stress --cpu 1 --timeout 120
Expected verification
tail -f /var/log/pisoc.csv scrolls with consistent temperatures (30-60 °C at idle depending on the case). During stress --cpu 1, the temperature rises and the measured frequency may drop below 700 MHz if the 85 °C threshold is reached; get_throttled then displays a non-zero flag with bit 3 (thermal throttling) or bit 0 (undervoltage) set.
Common errors
- Interpreting
get_throttledin decimal: it is a masked hexadecimal value, read it bit by bit (0x50000 = stored past events, not an active problem). - Confusing undervoltage and overheating: a 0x1 flag comes from the power supply (polyfuse F1, weak charger), not the heatsink.
vcgencmd: command not found: firmware missing from the image (minimal third-party ARMv6 images).- Stress test too aggressive on 256 MB: the OOM killer terminates processes before thermal behavior becomes interesting.
- Adding
over_voltageto gain MHz without monitoring the flags: undervoltage throttling cancels all benefits.
Other tutorials for this board
- Allumer une LED via le GPIO avec libgpiod
- Lire un bouton poussoir et afficher l'état dans la console
- Premier script Python : faire clignoter la LED
- Variation d'intensité LED avec le PWM matériel (et son piège)
- Lire un capteur I2C (température/humidité) sur le bus 1
- Configurer l'Ethernet 10/100 et piloter le Pi en SSH
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython