/kernel_reloaded/

Author:

Other contacts

Novi članci

Flickr Goodness

Categories

March 2, 2013 @ 22:42

Formatting output from Raspberry Pi temperature sensors

 
Raspberry Pi crew released tools and drivers than enabled reading from CPU and GPU temperature sensors.
 
In order to read GPU temperature use:
$ /opt/vc/bin/vcgencmd measure_temp
$ temp=43.3’C
 
Reading CPU temperature is similar, just read value from sys file system:
$ cat /sys/class/thermal/thermal_zone0/temp
$ 43850
 
As you can see both outputs need additional formatting to get only number values from them, and if you wish to have decimal precision then it gets a bit more complicated…
 

GPU Temperature
Formatting GPU temperature output can be done with cut command, so lets show only characters from 6 to 9.
 
$ /opt/vc/bin/vcgencmd measure_temp|cut -c6-9
$ 43.3
 
CPU temperature
Acquiring and formatting CPU temperature is similar procedure but with a twist…
 
$ cat /sys/class/thermal/thermal_zone0/temp
$ 43850
 
CPU temperature is shown without decimal point, but it is obvious that numbers after first two are decimal.
 
If you just divide by 1000 in bash you loose precision of decimal places because bash doesn’t work with decimal numbers :(
 
$ echo $((`cat /sys/class/thermal/thermal_zone0/temp`/1000))
$ 43
 
So lets try something else…
$ echo $((`cat /sys/class/thermal/thermal_zone0/temp|cut -c1-2`)).$((`cat /sys/class/thermal/thermal_zone0/temp|cut -c3-5`))
$ 43.312
 
Or you can use variable to get same effect:
CPUOUT=`cat /sys/class/thermal/thermal_zone0/temp`
CPU=`cut -c1-2 < << $CPUOUT`.`cut -c3-5 <<< $CPUOUT`

$ 43.312
 
This prints first two digits, then decimal point and lastly last three digits. If anybody has other solution please share it in the comments...
 

Filed under diy, english, gadgets, linux, tips&tricks

5 Comments »

  1. Posted by Zelja

    March 3, 2013 @ 12:32

    A bc?

    bc -l <<< "scale=3; $CPUOUT/1000"

    Ono "scale" ti je broj znamenki iza tocke, koliko ih god zelis.

  2. Posted by valent

    March 3, 2013 @ 17:55

    bc sam htio izbjeci zbog minimalizma i kako bi bilo što univerzalnije rješenje, ali inaće je bc odličan izbor. Na Raspberry Pi nije problem instalirati bc, no na neki openwrt router već je jer nema puno mjesta u flash memoriji…

  3. Posted by Valent Turkovic

    March 3, 2013 @ 17:58

    bc sam htio izbjeci zbog minimalizma i kako bi bilo što univerzalnije rješenje, ali inaće je bc odličan izbor. Na Raspberry Pi nije problem instalirati bc, no na neki openwrt router koji ima vrlo malo mjesta na flashu bi mogao biti problem…

  4. Posted by Ricardo Arturo Cabral

    March 3, 2013 @ 19:06

    This is how I do it. I pipe the output to the stream editor to perform a replacement of the whole output and just leave the number part.
    /opt/vc/bin/vcgencmd measure_temp | sed “s/temp=([0-9]+.[0-9]+)’C/1/”

  5. Posted by Zelja

    March 4, 2013 @ 1:06

    Ako je prostor jako veliki problem, uvijek mozes napisati mali programcic u C-u koji ce zauzeti par kB. Ako imas busybox, imas awk i sed, pa mozes preko toga. Cut binary ima 35 kB, a bc 70 kB, a sam bash mislim da to ne moze… mozda preko builtin printf-a?

RSS feed for comments on this post · TrackBack URI

Leave a Comment

    Archives

    Flickr photostream

    SSL is required

    Meta meta :)