Measure the Temperature in RetroPie
Measure the Temperature in RetroPie
by Jeff on July 23rd, 2016 No Comments »
 , , ,

I was looking for an easy way to measure the temperature on RetroPie from the command line. I may, eventually, modify this script to log and keep averages. For now, this will simply measure the temperature in RetroPie and output the temp in Celsius and Fahrenheit.

You’ll want to save this script to the home directory for easy access

cd ~

Copy and paste the following Measure the Temperature in RetroPie script

#!/usr/bin/perl
#Measures the CPU temp in RetroPie
#Outputs in Celsius and Fahrenheit
#Written by negeric
#https://technologyand.me/2016/07/23/measure-the-temperature-in-retropie/
#I'm not perl dev, so this could be optimized
sub CtoF {
     my $c = shift;
     my $f;
     $f = (9 * $c/5)+32;
     return $f;
}
my $tempWithC=`/opt/vc/bin/vcgencmd measure_temp | awk '{split(\$0,a,"="); print a[2]}'`;
chomp($tempWithC);
my ($tempCelcius,$c)=split(/\'/,$tempWithC);
my $fah = CtoF $tempCelcius;
print $tempCelcius . " C - " . $fah . " F\n";

Create a new Perl file

nano cputemp.pl

Paste the code from above, save and quit

CTRL+X

Now run it

pi@retropie:~ $perl cputemp.pl
54.8 C - 130.64 F

I am no true Perl dev, so feel free to optimize this code and send it back to me.