Skip to content

Latest commit

 

History

History
116 lines (80 loc) · 5.3 KB

CheckPiTemperature.md

File metadata and controls

116 lines (80 loc) · 5.3 KB

Getting the Operating Temperature of a Raspberry Pi

The "official" Raspberry Pi documentation defines available methods for monitoring core temperatures; see the heading labeled "Monitoring core temperature".

Get the temperature of the GPU and CPU:

The vcgencmd utility will provide the temperature of the GPU module on the RPi. Note that it will provide other data also.

$ vcgencmd measure_temp
temp=53.0'C

The temp of the CPU is found in a file: /sys/class/thermal/thermal_zone0/temp

The value recorded here is 1,000 x the temp in °C. Here's one way to get the temp from the contents of this file:

$ cpu=$(</sys/class/thermal/thermal_zone0/temp)
$ echo "$((cpu/1000))°C"
56°C

Which will give a truncated integer value. Calculating a real number can be done using the calc command. If calc isn't available, it can be installed as follows:

$ sudo apt-get install apcalc

And the calculation is then performed as follows:

$ calc $(</sys/class/thermal/thermal_zone0/temp)/1000
53.556

There is a new temperature available in the RPi4:

According to this source, there's a new feature that reads the internal temperature of the PMIC, but only on RPI4 (and future hardware versions?):

$ vcgencmd measure_temp pmic
temp=52.4'C

That's a lot of commands to get the temperature - is there an easier way?

Of course - define a function in ~/.bashrcNote 1:

pitemp () {
printf %'s\n' "PMIC temperature: $(vcgencmd measure_temp pmic | grep -o [0-9][0-9]\.[0-9])°C"
printf %'s\n' "GPU temperature: $(vcgencmd measure_temp | grep -o [0-9][0-9]\.[0-9])°C"
printf %'s\n' "CPU temperature: $(calc -p $(</sys/class/thermal/thermal_zone0/temp)/1000)°C"
}

Edit ~/.bashrc to add this function, then source it, and run it:

$ source .bashrc    
# OR, IF YOU PREFER: 
$ . ~/.bashrc 	# This also sources .bashrc to your current shell
$ pitemp
PMIC temperature: 51.4°C
GPU temperature: 52.0°C
CPU temperature: 54.043°C
$

Note 1: If you have more than a few aliases (or functions), you may find it preferable to put them in a separate file; e.g. ~/.bash_aliases. Why? Frequent edits to ~/.bashrc may result in accidental changes that affect bash default behavior, and restoring it might be difficult - the restoration will certainly require more of your time! Therefore, placing your aliases and functions in ~/.bash_aliases may be a better approach. Note also that the filename ~/.bash_aliases works because this filename is defined in ~/.bashrc as follows:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

This ensures that each time ~/.bashrc is sourced, ~/.bash_aliases is also sourced. And yes, you can add or change this to include whatever filenames you wish to use; ~/.bash_functions, or ~/.bash_prototypes, or whatever.


ADDENDUM:

And speaking of Raspberry Pi 4B and temperature, know this: "The Organization" announced a new firmware build for the USB3 host adapter that should save about 300mW. This was eventually applied through the routine apt-get upgrade process, and you may not have noticed it. If you're wondering whether the fix has been applied, it's easy to check:

$ sudo rpi-eeprom-update
BCM2711 detected
BOOTLOADER: up-to-date
CURRENT: Thu 16 Apr 17:11:26 UTC 2020 (1587057086)
 LATEST: Thu 16 Apr 17:11:26 UTC 2020 (1587057086)
 FW DIR: /lib/firmware/raspberrypi/bootloader/critical
VL805: up-to-date
CURRENT: 000137ad
 LATEST: 000137ad

If the command fails, or if you get a different output, you may need to run the upgrade process.

The Organization did thermal testing on this firmware. Their test results were briefed in this blog post. The blog highlights the improvements of the various firmware upgrades, and explains that the power-dissipation management firmware can be gotten through the normal apt full-upgrade process.


REFERENCES:

Q&A: Alias quotation and escapes; setting up aliases and functions for getting the temperature.

Q&A: Why is Raspberry Pi 3B / 3B+'s CPU temperature precision 0.538°C?

Q&A: Raspberry Pi tolerance towards high temperature

How to find out Raspberry Pi GPU and ARM CPU temperature on Linux