Get temperature of your Raspberry Pi
You Raspberry Pi has some nice commands that comes from its firmware that gets you information about the condition of some hardware components. One of this commands is able to measure and prints out the current temperature of your temperature sensor on your board. This may sounds complicated, but is really simple!
All you need is vcgencmd which gets you different informations based on parameters you set. You can get a list of all possible commands if you type this command into command line:
You will get a list of all possible parameters. Some of them are really interesting.
Get system temperature
For this you need the measure_temp param. With it you will get the current temperature on your board:
You will get the current temperature in degree Celsius. The output is not good formatted. I want to get a better output and a temperature in Fahrenheit. So for this use the following script:
#!/bin/bash tm=`/opt/vc/bin/vcgencmd measure_temp` tc=`echo $tm| cut -d '=' -f2 | sed 's/..$//'` tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc) echo temp = $tc\°C \($tf\°F\)
You can call the script with this command and you may get following output:
sh .get_temperature.sh temp = 49.8°C (121.64°F)
Get current clock frequency
You can get clock frequency information with the measure_clock param. For this you also need the name of the component which should get measured. There are many different possible components, you can find a list here. One of this components is ARM which gets you your current clock speed of your processor:
vcgencmd measure_clock arm frequency(45)=700074000
I get the standard value of 700 Million Hertz or 700 MHz.
Get the voltage
Another nice possibility is to measure the voltage. You need the measure_volts param and again you need the name of the component. Here you have 4 possibilities: core (standard), sdram_c, sdram_i, sdram_p:
vcgencmd measure_volts core volt=1.20V
You have now learned how to get online board information! It is a good idea to write a script to get this values regularly. Maybe you want to store it into database and display it with a small PHP web app?
Hi there how do i get vcgencmd?
Raspbian Linux (debian wheezy) has it already installed
Hi, I also try to find, where to get vcgencmd. Apt-get cant get it.
am on Raspbian Linux (Jessie)
vcgencmd is located under /usr/bin. You are right, it is not possible to install it with your packet manager. It was pre-installed on my Raspbian Linux version…
please any one know how i can Display this Values „Temperature“ into a PHP pages,
This is really easy. There is a php command for executing shell commands (exec). So with this little php script you can display the temperature:
for id in core sdram_c sdram_i sdram_p ; do \
echo -e „$id:\t$(vcgencmd measure_volts $id)“ ; \
TC1=`echo $TC | cut -d ‚.‘ -f1`
TC2=`echo $TC | cut -d ‚.‘ -f2`
#echo TC=$TC, $TC1 $TC2
TF=$(( (9*(10*$TC1 + $TC2) +25)/50 +32 ))
TC=`echo $tm| cut -d ‚=‘ -f2 | sed ’s/..$//’`
echo temp = $TC\°C \($TF\°F\)