Skip to content

Instantly share code, notes, and snippets.

@dweeber
Created September 19, 2012 10:49
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dweeber/3748975 to your computer and use it in GitHub Desktop.
Save dweeber/3748975 to your computer and use it in GitHub Desktop.
Bash script uses vcgencmd on Raspberry Pi with bc to calculate F value of Temp
#!/bin/bash
######################################################################
# Raspberry Pi
#
# Gross Script by Dweeber (Kevin Reed) <dweeber.dweebs@gmail.com>
# V1.0 2012-09-19
#
# Use the vcgencmd to obtain the Temp of the SOC
# then calculates the F value using bc.
#
# Requires bc to be loaded. If not then
# apt-get install bc
#
######################################################################
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 = $tf\'F \($tc\'C\)
@WalterS
Copy link

WalterS commented Sep 20, 2012

a) Why use 4 steps if you can do it in two:

```tc=$(/opt/vc/bin/vcgencmd measure_temp | awk -F"=|'" '{print $2}')```

b) degrees temperature is abbreviated as "°'" and not "'*"

echo "temp=$tf°F \($tc°C\)"

@WalterS
Copy link

WalterS commented Sep 20, 2012

Tried to use markdown in the last comment which obviously didn't work. Just disregard the stars and backticks.

@quigybo
Copy link

quigybo commented Jan 7, 2013

without relying on vcgencmd or bc:

awk '{printf("%.1f\n",$1/1e3)}' /sys/class/thermal/thermal_zone0/temp

Copy link

ghost commented Aug 21, 2013

or even

awk '{printf("%.1f °F\n",$1*1.8/1e3)}' /sys/class/thermal/thermal_zone0/temp

in the colonies.

@nilegardner
Copy link

You left out a constant:

awk '{printf("%.1f°F\n",(($1*1.8)/1e3)+32)}' /sys/class/thermal/thermal_zone0/temp

That will get you the temperature in degrees Fahrenheit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment