Author's Picture
Author: Joel Gray Published: 26 September 2022 Read Time: ~3 minutes

Monitoring Temperatures Raspberry Pi OS

This will be a more straightforward blog than you’re used to from me. I recently began using my Raspberry Pi 4 as a home NAS to store my pc backups, movies and tv shows.

Naturally I jumped into this project head first with basically no thought or planning whatsoever… as usual. I can be quite impulsive, it’s a gift and a curse. Anyway this meant that I had just a bare bones Rasp Pi 4 with no passive or active cooling solution of any kind.

This lead to me constantly checking my temperatures for fear of running the Pi too hot for too long. Although it would probably be fine as it’s smart enough to thermal throttle itself to stay safe, it is not good practice to run your equipment at their limits if you can avoid it.

On a fun note: I decided to make a quick little DIY tower cooler for my Rasp Pi by stacking some coins on top of the CPU and resting a metal hip last on top of the coins and the USB ports (which were also very hot). The hip flask was overkill and didn’t make much difference but the whole DIY cooler dropped the CPU temps by 9 degrees Celsius which isn’t nothing.

Raspberry Pi Diy Cooler
DIY Heat Sync

Beware when doing something like this, I had my flask slip and short my board when I was trying to transfer some files over the network and had to start again so I don’t recommended this if you can avoid it, but the tower of coins is a nice little hack to drop temperatures by increasing the heat conducting surface area of the CPU. Anywayyyyy… back to the point of this post.

I found that monitoring the temperatures on the Pi to not be really intuitive and there are separate utilities that monitor the GPU and the CPU temps, and they also display the results in different formats. So I’ve written a very simple little script to check both temperatures and format the results in degrees Celsius.

You can download the script from my GitHub.

If you want to create the script yourself you need to do the following. Run the following command in your home directory.

$ cd ~
$ nano showTemps.sh

Copy the text from the shell below and paste it into the file editor which is open on your screen. To save and close the file, press Ctrl+x then type ‘y’ and press enter.

#! /bin/bash

degrees=$'\u00b0'

gpu_temp="$(vcgencmd measure_temp)"
echo GPU Temp: ${gpu_temp:5:4}"${degrees}"C

cpu_temp=$(</sys/class/thermal/thermal_zone0/temp)
cpu_temp=$((cpu_temp/100))
echo CPU Temp: ${cpu_temp:0:2}.${cpu_temp:2:3}"${degrees}"C

Remember that when you first get this script you need to make it executable to run. To do that we use the ‘chmod’ command.

$ chmod u+x ./showTemps.sh

Then you run the script you simply run the following command:

$ ./showTemps.sh

OUTPUT:
GPU Temp: 48.2°C
CPU Temp: 48.1°C

Additionally if you want to constantly monitor the temperature you can use the ‘watch’ command to rerun the command every 2 secs to keep an up to date running monitor of the current temperatures.

$ watch ./showTemps.sh

OUTPUT:
Every 2.0s: ./showTemps.sh                                                           user: Mon Sep 26 23:17:20 2022
GPU Temp: 48.2°C
CPU Temp: 48.1°C

Anyway that’s the end of this one. Nice quick and easy solution to monitor the temperatures of Raspberry Pi. If you have any questions or want to know anything else feel free to leave a comment or send me an email!

Written by Joel Gray

26/09/2022