There are a few things you can do to monitor the temperature on your Raspberry Pi. The first is to use the GPIO pins to output a digital value. This can be used to track the temperature in real-time. The second is to use the gpio_read() function to read the temperature from a GPIO pin. This can be used to track the temperature in text or as a graph. Finally, you can use the gpio_write() function to write data to a GPIO pin. This can be used for things like setting a temperature or reading data from a sensor.
Monitoring Temperature on The Pi
We will assume that you already have setup your Raspberry Pi, are using Raspbian, and that you are able to access a console prompt – either via SSH or via a desktop based login.
If you happen to have a brand new Ubuntu installation on your Pi instead, checkout vcgencmd for Ubuntu 20.04 aarch64 on RPi 4B by Hamid Elaosta.
Once you are at the terminal prompt, you will first want to check that the vcgencmd utility is available to you. It will likely be present if you are using Raspbian. Let’s check:
If you received output, which had more information then a leading vcgencmd:, then you are good to go.
Testing Temperature on the Pi Manually
Go ahead and execute the following command:
You should receive output similar to the following:
Note that the temperature on your Pi may be higher, for example 45 degrees Celsius. Mine (a Raspberry Pi 4) runs in a tight metal enclosure (the armour twin fan aluminum radiator housing) with a single cooling fan running, and it is quite cool here tonight. I have another Raspberry Pi 3 with a plastic shell, a couple of heat sinks and no fan, and that one is running at 44.4 Degrees Celsius currently.
How Much is Too Much?
Good question. The Raspberry Pi foundation recommends to keep your Raspberry Pi below 85 degrees Celsius. That is an upper limit, and you should note that there may some chips on the Raspberry mainboard which are only qualified to go up to 70 Degrees Celsius. In general, if you can run at 50 degrees Celsius or less, it seems you should be in the green zone.
Even if you should go above it, you may be able to add a little fan, some cooling sinks, and quickly drive down the temperature. The environment/room temperature is off importance too. If your environment gets hotter (summer weather etc.) expect your Raspberry Pi to go up in temperature also.
And it is good to keep in mind that the Raspberry Pi will generally throttle (i.e. slow down) when the temperature reaches a certain point. Unless you’re doing something non-default like overclocking, or changing settings.
There is also a lot to be said about which case you choose for your Raspberry Pi 4. Various choices will lead to either much better or much worse cooling results. For a solid overview on cases, see Raspberry Pi 4 Cases, Temperature and CPU Throttling Under Load by Martin Rowan.
Scripting Temperature and More
The vcgencmd command is quite versatile. You can read more about it on the vcgencmd manual page. Let’s create a small script with a few of the most useful commands, which we store as ~/temperature.sh:
Here, we checked the temperature, the throttle status (see the website link above for more info), a Volts readout and the memory available to the GPU and to the ARM processor. Note that your total memory may be larger than what shows available to ARM. You can see your total memory by using a tool like htop (sudo apt install htop && htop), or simply by running free -mh at the command line (first result, top left, is your total memory size).
Wrapping up
Keeping your Raspberry Pi Cool is surely one important aspect of running your Pi well. Invest in a case which optimizes temperature, add one or two fans, and most importantly, monitor the temperature performance of the system regularly, including under load. Enjoy the multitude of information vcgencmd can provide you with, and keep an eye on that temperature!