How to monitor the temperature of the Raspberry Pi
We can monitor the temperature of the Raspberry Pi by different methods:
All these methods to find the temperature of the Raspberry Pi are explained in detail.
How to monitor the temperature of the Raspberry Pi by using Python script
We will create a file of name “temp.py” with the nano text editor, for this, we will use the command:
When the file is opened, type the following Python code in the file to monitor the temperature of the Raspberry Pi 4:
#import gpiozero library
temp= gz.CPUTemperature().temperature
#save the value of temperature of Raspberry Pi in "temp" variable
round_temp= round(temp,1)
#round the value of temperature to one decimal
print ("The temperature of Raspberry Pi:")
print (temp)
print ("Temperature's value rounded to one decimal:")
print (round_temp)
#printed the values of temp and round_temp variables
Explanation of code: In the above code, we have to import the library of the gpiozero and then find out the CPU temperature and store the value in the “temp” variable. Then use the round() function to round off the store value of the temp variable and store it in the round_temp variable. Finally using the print command, we have printed both values on the screen.
The output of the above Python script to monitor the temperature can be checked by running the python code using the command:
$ python temp.py |
How to monitor the temperature of the Raspberry Pi by using a bash command
If we want to display the temperature of the Raspberry Pi through the bash command, we will display the “/sys/class/thermal/thermal_zone0/temp” where the temperature of the Raspberry Pi 4 has been stored, for this purpose, we will use the command:
The answer is without the decimal which means the temperature is 48.686 degrees.
How to monitor the temperature of the Raspberry Pi by using vcgencmd
We can also find out the temperature through the terminal of the Raspberry Pi 4 using the vcgencmd utility which comes pre-installed with Raspberry pi:
How to monitor the temperature of the Raspberry Pi by using a GUI
We can also use the graphical user interface to monitor the temperature and can set it on the top menu bar so it will continuously display the temperature of the Raspberry Pi 4, for this purpose, we will right-click from the mouse on the top menu bar of the desktop of Raspberry Pi, a drag-down menu will appear, choose the “Add/Remove Panel Items…”:
A window will appear, click on the “Add” button:
Find out the “Temperature Monitor” and click on the “Add” button to add it on the title bar of the desktop:
Set its position on the menu bar, as we want to set it between the Spacer and Digital Clock, we will place it in between by using the “Up” button:
Once the position is set, click on the “Close” button:
The temperature of the Raspberry Pi 4 is displaying on the top of the menu bar as highlighted in the figure below:
Conclusion
The temperature of the CPU rises with the excessive use of the Raspberry Pi 4 which can damage the board. There are different methods to find out the temperature of the board of the Raspberry Pi 4. In this write-up, we have discussed different methods to find out the temperature of the board of the Raspberry Pi 4.