Read temp sensors from command line


31 posts   Page 1 of 2   1, 2
by kraades » Wed Jul 18, 2012 8:21 am
Is it possible to read the temperature sensors from the command line?

I have the Pi at a remote location that I can access using ssh and I would like to read the current temperature.
Posts: 6
Joined: Wed Jul 18, 2012 8:03 am
by AndrewS » Wed Jul 18, 2012 11:40 am
The Pi hardware doesn't include any temperature sensors. However you can hook up an I2C temperature sensor to the GPIO pins (and then read that from the command line) - search the forums for more info.
User avatar
Posts: 2193
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
by Gert van Loo » Wed Jul 18, 2012 9:52 pm
AndrewS wrote:The Pi hardware doesn't include any temperature sensors. ....

Actually: we have. In fact we have several of them in different places on the silicon to check the silicon temperature. It is not generally known and there is no use in knowing as they requires some very special SW to access and read. To use them you have to go trough the Reset-Power-Clock manager module and we keep that closed also because if you do wrong things there you can accidentally over voltage the chip. Even we 'in-the-know' do not access registers in that module directly and prefer to use dedicated, tested and verified routines to do the work for us.
User avatar
Raspberry Pi Engineer
Raspberry Pi Engineer
Posts: 1843
Joined: Tue Aug 02, 2011 7:27 am
by AndrewS » Thu Jul 19, 2012 12:25 am
Learn something new every day :)
Let me revise my statement to "The Pi hardware doesn't include any user-accessible temperature sensors. ...." then ;)
User avatar
Posts: 2193
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
by limaunion » Thu Jul 19, 2012 12:40 am
it's very easy to monitor the temperature using an external sensor with a usb<>serial converter, check this: http://martybugs.net/electronics/tempse ... rdware.cgi
HTH
Posts: 18
Joined: Sun Mar 11, 2012 1:49 pm
by jbeale » Thu Jul 19, 2012 1:25 am
Gert van Loo wrote:In fact we have several of them in different places on the silicon to check the silicon temperature.... Even we 'in-the-know' do not access registers in that module directly and prefer to use dedicated, tested and verified routines to do the work for us.


Temperature is probably the most often sensed physical property. Whatever measurements I make on any system, I always include ambient temperature, because it has some measurable effect on almost everything and it's useful to correlate just how much effect that is. So if there was some way to have visibility of the chip temperature from the user space, that would be very useful. Obviously chip temp != ambient temp, but at constant system power draw and ambient airflow they will move together.

Currently I use a LM35 3-terminal analog-output temperature sensor, with a I2C 18-bit ADC connecting to an Arduino, and that in turn reporting via USB-serial to the R-Pi. Once I get a chance, I plan to figure out the R-Pi I2C interfacing and cut out the Arduino. This is the I2C ADC module: http://jeelabs.com/products/analog-plug

With averaging it has usable resolution to 0.0001 degrees. My office temperature is currently 23.2520 C and rising at a rate of 0.0088 C per minute.
User avatar
Posts: 1886
Joined: Tue Nov 22, 2011 11:51 pm
by Atilla » Thu Jul 26, 2012 11:29 pm
So, is there documentation available about how to access those sensors, at all? Warranty isn't something that troubles me, as I just overvolted it anyway, to try and see how greater clock speeds will feel like.

Surely, as long as there are docs, it cannot be so hard to *read* a couple of values out.
Posts: 4
Joined: Thu Jul 19, 2012 9:19 pm
by AndrewS » Fri Jul 27, 2012 10:54 am
The short answer is no.
The only 'docs' available is the BCM2835 peripherals PDF linked to from http://elinux.org/RPi_Hardware#Components which has no mention of temperature sensors. The "very special SW to access and read" that Gert refers to can only be written by Broadcom employees.
User avatar
Posts: 2193
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
by Atilla » Fri Jul 27, 2012 12:40 pm
Alright, that clears up things a lot, thanks.
Posts: 4
Joined: Thu Jul 19, 2012 9:19 pm
by feverish » Fri Jul 27, 2012 2:37 pm
If you are willing to look into Arduino documentation, there are several detailed HOW-TOs on measuring temperature that would readily adapt to Raspi, either using, say an LM35 or a varistor.
Posts: 251
Joined: Wed Jun 27, 2012 2:29 pm
by Burngate » Fri Jul 27, 2012 3:59 pm
Gert van Loo wrote:
AndrewS wrote:The Pi hardware doesn't include any temperature sensors. ....

Actually: we have. In fact we have several of them in different places on the silicon to check the silicon temperature. It is not generally known and there is no use in knowing as they requires some very special SW to access and read. To use them you have to go trough the Reset-Power-Clock manager module and we keep that closed also because if you do wrong things there you can accidentally over voltage the chip. Even we 'in-the-know' do not access registers in that module directly and prefer to use dedicated, tested and verified routines to do the work for us.

Just out of interest ...
Those sensors are there for a reason - does the blob read them at any time, and does it do anything with the readings? Such as dropping volts or frequency to reduce power?
Or is it just for you to check on how we broke it when it gets returned?
Hardware ace - level: Cowboy
User avatar
Posts: 2351
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
by Tompen » Sun Sep 09, 2012 6:11 pm
There is a documented firmware interface to read the temperature from the Broadcom chip.
But someone needs to write a little linux tool to use it....
Posts: 20
Joined: Tue Aug 14, 2012 4:11 pm
by hojnikb » Mon Sep 10, 2012 8:41 am
So there is a possibility to have a software acces of temparaure sensor(s) in the future ??
+°´°+,¸¸,+°´°~ Everyone should have a taste of UK Raspberry Pie =D ~°´°+,¸¸,+°´°+
Rasberry Pi, SoC @ 1225Mhz :o, 256MB Ram @ 550Mhz, 16GB SD-Card, Raspbian
User avatar
Posts: 110
Joined: Mon Jun 04, 2012 3:59 pm
Location: @Home
by Licaon_Kter » Mon Sep 10, 2012 8:52 am
run sudo rpi-update now
reboot
run /opt/vc/bin/vcgencmd measure_temp ( info: viewtopic.php?p=169726#p169726 )
BFQ+BFS or RT on a RPi? 4'real: https://github.com/licaon-kter/ (source and compiled!)
User avatar
Posts: 240
Joined: Wed Sep 05, 2012 10:12 am
Location: Between the keyboard and the chair.
by dom » Mon Sep 10, 2012 8:59 am
Burngate wrote:Those sensors are there for a reason - does the blob read them at any time, and does it do anything with the readings? Such as dropping volts or frequency to reduce power?
Or is it just for you to check on how we broke it when it gets returned?

The sensor is mainly there for adjusting sdram refresh with temperature (you need to refresh more at high temperature).
The latest firmware does disable overclock/overvolt when it reaches 85'C which should bring it back down.
However at 24'C ambient, I couldn't get the temperature above 77'C with absolute maximum overclock/overvolt settings and stress testing ARM+GPU. I doubt if this limit will be hit by many.
Raspberry Pi Engineer
Raspberry Pi Engineer
Posts: 3864
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by hojnikb » Mon Sep 10, 2012 9:00 am
this is just awsome !

do i need to use rpi-update or is the kernel in raspbian bleeding edge repo also updated with this ?
+°´°+,¸¸,+°´°~ Everyone should have a taste of UK Raspberry Pie =D ~°´°+,¸¸,+°´°+
Rasberry Pi, SoC @ 1225Mhz :o, 256MB Ram @ 550Mhz, 16GB SD-Card, Raspbian
User avatar
Posts: 110
Joined: Mon Jun 04, 2012 3:59 pm
Location: @Home
by hojnikb » Mon Sep 10, 2012 9:01 am
dom wrote:
Burngate wrote:Those sensors are there for a reason - does the blob read them at any time, and does it do anything with the readings? Such as dropping volts or frequency to reduce power?
Or is it just for you to check on how we broke it when it gets returned?

The sensor is mainly there for adjusting sdram refresh with temperature (you need to refresh more at high temperature).
The latest firmware does disable overclock/overvolt when it reaches 85'C which should bring it back down.
However at 24'C ambient, I couldn't get the temperature above 77'C with absolute maximum overclock/overvolt settings and stress testing ARM+GPU. I doubt if this limit will be hit by many.

wow, that is great to have a protection like that ;)
+°´°+,¸¸,+°´°~ Everyone should have a taste of UK Raspberry Pie =D ~°´°+,¸¸,+°´°+
Rasberry Pi, SoC @ 1225Mhz :o, 256MB Ram @ 550Mhz, 16GB SD-Card, Raspbian
User avatar
Posts: 110
Joined: Mon Jun 04, 2012 3:59 pm
Location: @Home
by Dweeber » Wed Sep 19, 2012 10:58 am
Wanted the output in F instead of C. Script gives both.

https://gist.github.com/3748975

Outputs:
temp=122.54'F (50.3'C)
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com
User avatar
Posts: 606
Joined: Fri Aug 17, 2012 3:35 am
Location: Mesa, AZ
by waters » Mon Apr 15, 2013 10:10 am
The following script builds on Dweeber’s output in Fahrenheit example to provide information from frequency and voltage sensors. Those who think in Celsius can uncomment line 9.

#!/bin/bash
echo
date
echo
tm=`/opt/vc/bin/vcgencmd measure_temp`
tc=`echo $tm| cut -d '=' -f2 | sed 's/..$//'`
tf=$(echo "scale=1; (1.8*$tc)+32" | bc)
echo -e "temp:\t $tf'F ($tc'C)"
#echo -e "temp:\t $(/opt/vc/bin/vcgencmd measure_temp)" ;
for src in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi ; do echo -e "$src:\t $(/opt/vc/bin/vcgencmd measure_clock $src)" ; done
for id in core ; do echo -e "$id:\t $(/opt/vc/bin/vcgencmd measure_volts $id)" ; done
for id in sdram_c sdram_i sdram_p ; do echo -e "$id: $(/opt/vc/bin/vcgencmd measure_volts $id)" ; done
for codec in H264 MPG2 WVC1 ; do echo -e "$codec:\t $(/opt/vc/bin/vcgencmd codec_enabled $codec)" ; done
echo
echo 'firmware version'
/opt/vc/bin/vcgencmd version
Posts: 5
Joined: Sun Feb 24, 2013 4:27 pm
by PIV8DR » Fri Apr 19, 2013 10:32 pm
Simple Script to get version / temperature of CPU / Voltage of memory cards

#!/bin/bash
clear

#Getting System Information
/opt/vc/bin/vcgencmd version
/opt/vc/bin/vcgencmd measure_temp
/opt/vc/bin/vcgencmd measure_volts core
/opt/vc/bin/vcgencmd measure_volts sdram_c
/opt/vc/bin/vcgencmd measure_volts sdram_i
/opt/vc/bin/vcgencmd measure_volts sdram_p
Posts: 5
Joined: Wed Apr 10, 2013 6:53 pm
by ryanjennings » Sat Apr 20, 2013 3:24 pm
This is a pretty economical and simple way to get temperature.

http://learn.adafruit.com/adafruits-ras ... ng/ds18b20

http://www.ebay.com/itm/2PCS-IC-DS18B20 ... 43b133fe6b

The ds18b20 can be daisy chained so you can read multiple temperatures. I won't go into lots of details, just wanted to throw it out there in case you weren't familiar with the 1-wire system.

Ryan
Posts: 8
Joined: Mon Jul 09, 2012 4:14 pm
by luckyloo » Sun Apr 28, 2013 7:32 am
Hi, This is my first post, so please forgive me if I leave any essential information out.
I am using the latest version of Raspbian and following the Adafruit instructions you mention. I can obtain a temperature reading using the 'cat w1 slave' command, but when I follow the software instructions on page 11, I get a message telling me 'list index out of range' in Line 9. The line containing the error is: device_folder=glob.glob(base_dir+'28*')[0]. I have replaced the '*' with the sensor number '-000004ab6156'. Any help would be greatly appreciated. Please note GPIO pins have been installed, but not set as I understand latest software versions already have this set to automatically read inputs on all pins. Also I ran 'sudo apt-get update' and 'sudo apt-get upgrade' on 27 April 2013, so system is completely up to date.

Many thanks for any help anyone can offer.

Luckyloo
Posts: 2
Joined: Sun Apr 28, 2013 7:12 am
by PIV8DR » Sun Apr 28, 2013 2:34 pm
Luckyloo,

I made a few slight modifications to my earlier post; however, everything reported just fine. Here is the modified code see if this will work for you.

#!/bin/bash
clear
sleep 2
echo
date
echo
echo 'Firmeare Version'
/opt/vc/bin/vcgencmd version
echo
tm=`/opt/vc/bin/vcgencmd measure_temp`
tc=`echo $tm| cut -d '=' -f2 | sed 's/..$//'`
tf=$(echo "scale=1; (1.8*$tc)+32" | bc)
echo -e "temp:\t $tf'F ($tc'C)"
#echo -e "temp:\t $(/opt/vc/bin/vcgencmd measure_temp)" ;
echo
for src in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi ; do echo -e "$src:\t $(/opt/vc/bin/vcgencmd measure_clock $sr$
for id in core ; do echo -e "$id:\t $(/opt/vc/bin/vcgencmd measure_volts $id)" ; done
for id in sdram_c sdram_i sdram_p ; do echo -e "$id: $(/opt/vc/bin/vcgencmd measure_volts $id)" ; done
for codec in H264 MPG2 WVC1 ; do echo -e "$codec:\t $(/opt/vc/bin/vcgencmd codec_enabled $codec)" ; done
echo
who
echo
uptime
echo
Posts: 5
Joined: Wed Apr 10, 2013 6:53 pm
by jbeale » Sun Apr 28, 2013 3:29 pm
PIV8DR, I think there is a slight syntax error on line 16 of your latest script ("for src in arm core h264 ..."), but the following works for me:

Code: Select all
#!/bin/bash
clear
sleep 2
echo
date
echo
echo 'Firmware Version'
/opt/vc/bin/vcgencmd version
echo
tm=`/opt/vc/bin/vcgencmd measure_temp`
tc=`echo $tm| cut -d '=' -f2 | sed 's/..$//'`
tf=$(echo "scale=1; (1.8*$tc)+32" | bc)
echo -e "temp:\t $tf'F ($tc'C)"
#echo -e "temp:\t $(/opt/vc/bin/vcgencmd measure_temp)" ;
echo
for src in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi ; do echo -e "$src:\t $(/opt/vc/bin/vcgencmd measure_clock $src)" ; done
for id in core ; do echo -e "$id:\t $(/opt/vc/bin/vcgencmd measure_volts $id)" ; done
for id in sdram_c sdram_i sdram_p ; do echo -e "$id: $(/opt/vc/bin/vcgencmd measure_volts $id)" ; done
for codec in H264 MPG2 WVC1 ; do echo -e "$codec:\t $(/opt/vc/bin/vcgencmd codec_enabled $codec)" ; done
echo
who
echo
uptime
echo


Here is my output:
Code: Select all
Sun Apr 28 08:30:40 PDT 2013

Firmware Version
Apr 25 2013 01:07:36
Copyright (c) 2012 Broadcom
version 386589 (release)

temp:    88.7'F (31.5'C)

arm:     frequency(45)=700000000
core:    frequency(1)=250000000
h264:    frequency(28)=0
isp:     frequency(42)=250000000
v3d:     frequency(43)=250000000
uart:    frequency(22)=3000000
pwm:     frequency(25)=0
emmc:    frequency(47)=100000000
pixel:   frequency(29)=108000000
vec:     frequency(10)=0
hdmi:    frequency(9)=163682000
dpi:     frequency(4)=0
core:    volt=1.20V
sdram_c: volt=1.20V
sdram_i: volt=1.20V
sdram_p: volt=1.23V
H264:    H264=enabled
MPG2:    MPG2=disabled
WVC1:    WVC1=disabled

pi       tty2         2013-04-25 20:13
pi       ttyAMA0      2013-04-27 13:36

 08:30:40 up 2 days, 12:54,  2 users,  load average: 0.18, 0.27, 0.42
User avatar
Posts: 1886
Joined: Tue Nov 22, 2011 11:51 pm
by luckyloo » Mon Apr 29, 2013 2:32 pm
Thanks for your help guys,
The problem is now resolved. :D

Luckyloo
Posts: 2
Joined: Sun Apr 28, 2013 7:12 am