Skip to content

Instantly share code, notes, and snippets.

@schappim
Created December 6, 2024 07:05
Show Gist options
  • Save schappim/e7a9fb3d045b175a22f785cf2dec0023 to your computer and use it in GitHub Desktop.
Save schappim/e7a9fb3d045b175a22f785cf2dec0023 to your computer and use it in GitHub Desktop.

Measuring Raspberry Pi SoC Temperature

1. Using the vcgencmd Command

Run the following command in the terminal:

vcgencmd measure_temp

This will output the temperature in Celsius, e.g.:

temp=45.0'C

2. Reading from /sys/class/thermal

You can directly read the temperature from the system file:

cat /sys/class/thermal/thermal_zone0/temp

The output will be in millidegrees Celsius, e.g., 45000 means 45.0°C. To convert it to degrees Celsius, divide by 1000:

echo "$(cat /sys/class/thermal/thermal_zone0/temp) / 1000" | bc

3. Monitoring in Python

You can also use Python to read and display the temperature:

with open("/sys/class/thermal/thermal_zone0/temp") as f:
    temp = int(f.read()) / 1000
    print(f"Temperature: {temp}°C")

4. Use a GUI-Based Tool

If you're running a desktop environment, tools like Pi Apps or the Raspberry Pi Configuration utility may display the temperature.

5. Set Up Continuous Monitoring

Use a script or monitoring tool like Pi-hole, Node-RED, or Grafana with Prometheus to track and graph the temperature over time for better visibility.

Note: Ensure good ventilation or heatsinks if temperatures consistently exceed 70°C, as prolonged high temperatures can throttle performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment