Sparks135
Posts: 104
Joined: Tue Feb 28, 2017 7:44 pm

GPU & CPU Temp in Fahrenheit

Sat Apr 15, 2017 12:05 pm

I am using this code to show GPU Temp in Fahrenheit and CPU Temperature in Fahrenheit. How do I convert this to show both?

Code: Select all

#!/bin/bash
# Script: my-pi-temp.sh
# Purpose: Display the ARM CPU and GPU  temperature of Raspberry Pi 2/3 
# Author: Vivek Gite <www.cyberciti.biz> under GPL v2.x+
# -------------------------------------------------------
cpu=$(</sys/class/thermal/thermal_zone0/temp)
echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $(/opt/vc/bin/vcgencmd measure_temp)"
echo "CPU => $((cpu/1000))'C"CENTIGRADE=$(vcgencmd measure_temp | awk -F "[=\']" '{print $2}')
FARENHEIT=$(echo "(1.8 * $CENTIGRADE) + 32" |bc)
echo temp=$FARENHEIT\'F
As you can see below the temp must be for the GPU I need it to show each.

This my output now:
GPU => temp=54.8'C
CPU => 54'C
temp=132.4'F

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2489
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: GPU & CPU Temp in Fahrenheit

Tue Apr 18, 2017 2:00 pm

This is NOT a Device Tree question, so you're in the wrong forum - beginners might have been better - but here you go:

Code: Select all

#!/bin/bash
gpu=$(/opt/vc/bin/vcgencmd measure_temp | awk -F "[=\']" '{print $2}')
cpu=$(</sys/class/thermal/thermal_zone0/temp)
cpu=$(echo "$cpu / 100 * 0.1" | bc)
cpuf=$(echo "(1.8 * $cpu) + 32" |bc)
gpuf=$(echo "(1.8 * $gpu) + 32" |bc)
echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $gpu'C ($gpuf'F)"
echo "CPU => $cpu'C ($cpuf'F)"
I've broken into down into a few more steps for clarity.
Running it now I get:

Code: Select all

Tue 18 Apr 13:59:01 UTC 2017 @ raspberrypi
-------------------------------------------
GPU => 47.8'C (118.0'F)
CPU => 48.3'C (118.9'F)
But Fahrenheit is an antique and should die quickly. 8-)

Sparks135
Posts: 104
Joined: Tue Feb 28, 2017 7:44 pm

Re: GPU & CPU Temp in Fahrenheit

Tue Apr 18, 2017 5:40 pm

PhilE wrote:This is NOT a Device Tree question, so you're in the wrong forum - beginners might have been better - but here you go:

Code: Select all

#!/bin/bash
gpu=$(/opt/vc/bin/vcgencmd measure_temp | awk -F "[=\']" '{print $2}')
cpu=$(</sys/class/thermal/thermal_zone0/temp)
cpu=$(echo "$cpu / 100 * 0.1" | bc)
cpuf=$(echo "(1.8 * $cpu) + 32" |bc)
gpuf=$(echo "(1.8 * $gpu) + 32" |bc)
echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $gpu'C ($gpuf'F)"
echo "CPU => $cpu'C ($cpuf'F)"
I've broken into down into a few more steps for clarity.
Running it now I get:

Code: Select all

Tue 18 Apr 13:59:01 UTC 2017 @ raspberrypi
-------------------------------------------
GPU => 47.8'C (118.0'F)
CPU => 48.3'C (118.9'F)
But Fahrenheit is an antique and should die quickly. 8-)
Thank you that did the trick. Your method is so much cleaner. Thanks again.

OutsourcedGuru
Posts: 64
Joined: Mon Jun 19, 2017 11:15 pm

Re: GPU & CPU Temp in Fahrenheit

Fri Jun 30, 2017 10:54 pm

As someone in the states and since we still use Fahrenheit, it would be nice to have this support via raspi-config (display celsius or fahrenheit) versus a single setting.

User avatar
DougieLawson
Posts: 36576
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GPU & CPU Temp in Fahrenheit

Sat Jul 01, 2017 6:29 am

OutsourcedGuru wrote:As someone in the states and since we still use Fahrenheit, it would be nice to have this support via raspi-config (display celsius or fahrenheit) versus a single setting.
A better option would be for you to shout at your Government until they drop the use of Imperial and American units and start using ISO units for everything. I'm sure Mr. Trump would like the chaos that would cause.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

OutsourcedGuru
Posts: 64
Joined: Mon Jun 19, 2017 11:15 pm

Re: GPU & CPU Temp in Fahrenheit

Mon Jul 03, 2017 9:44 pm

DougieLawson wrote:
OutsourcedGuru wrote:As someone in the states and since we still use Fahrenheit, it would be nice to have this support via raspi-config (display celsius or fahrenheit) versus a single setting.
A better option would be for you to shout at your Government until they drop the use of Imperial and American units and start using ISO units for everything. I'm sure Mr. Trump would like the chaos that would cause.
"Is there anyone who ever remembers
Changing their mind from the paint on a sign?
Is there anyone who really recalls
Ever breaking record off
For something someone yelled real loud one time
?
Oh, everyone believes
In how they think it ought to be
Oh, everyone believes
And they're not going easily..."
~ John Mayer - Belief lyrics

Jeffrey.j
Posts: 8
Joined: Sun Mar 12, 2017 8:54 pm

Re: GPU & CPU Temp in Fahrenheit

Sun May 27, 2018 12:05 am

PhilE wrote:
Tue Apr 18, 2017 2:00 pm
This is NOT a Device Tree question, so you're in the wrong forum - beginners might have been better - but here you go:

Code: Select all

#!/bin/bash
gpu=$(/opt/vc/bin/vcgencmd measure_temp | awk -F "[=\']" '{print $2}')
cpu=$(</sys/class/thermal/thermal_zone0/temp)
cpu=$(echo "$cpu / 100 * 0.1" | bc)
cpuf=$(echo "(1.8 * $cpu) + 32" |bc)
gpuf=$(echo "(1.8 * $gpu) + 32" |bc)
echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $gpu'C ($gpuf'F)"
echo "CPU => $cpu'C ($cpuf'F)"
I've broken into down into a few more steps for clarity.
Running it now I get:

Code: Select all

Tue 18 Apr 13:59:01 UTC 2017 @ raspberrypi
-------------------------------------------
GPU => 47.8'C (118.0'F)
CPU => 48.3'C (118.9'F)
But Fahrenheit is an antique and should die quickly. 8-)
Hi. I know this is an older post but I was hoping that you could briefly explain these parts:

Code: Select all

 awk -F "[=\']" '{print $2}' 
,

Code: Select all

cpu=$(echo "$cpu / 100 * 0.1" | bc)
(Just why this one is nessessary), and why is there a “<“ here:

Code: Select all

cpu=$(</sys/class/thermal/thermal_zone0/temp)
. Also, if I were to make this an alias, how would I do that? Thank you.

User avatar
Paeryn
Posts: 2747
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: GPU & CPU Temp in Fahrenheit

Sun May 27, 2018 1:54 am

Jeffrey.j wrote:
Sun May 27, 2018 12:05 am
PhilE wrote:
Tue Apr 18, 2017 2:00 pm

Code: Select all

#!/bin/bash
gpu=$(/opt/vc/bin/vcgencmd measure_temp | awk -F "[=\']" '{print $2}')
cpu=$(</sys/class/thermal/thermal_zone0/temp)
cpu=$(echo "$cpu / 100 * 0.1" | bc)
cpuf=$(echo "(1.8 * $cpu) + 32" |bc)
gpuf=$(echo "(1.8 * $gpu) + 32" |bc)
echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $gpu'C ($gpuf'F)"
echo "CPU => $cpu'C ($cpuf'F)"
Hi. I know this is an older post but I was hoping that you could briefly explain these parts:

Code: Select all

 awk -F "[=\']" '{print $2}' 
That is a very simple awk program that splits each line from the input file into fields where fields are delimited by either an equals sign or a single quote and outputs the second field.
-F "[=\']" sets the field separator, if you give a string of more than one character then the string is a regular expression.
'{print $2}' is the awk program to run. No pattern is given so it will be applied to every line, $n means the item that is the nth field.
Jeffrey.j wrote:
Sun May 27, 2018 12:05 am

Code: Select all

cpu=$(echo "$cpu / 100 * 0.1" | bc)
(Just why this one is nessessary), and why is there a “<“ here:

Code: Select all

cpu=$(</sys/class/thermal/thermal_zone0/temp)
. Also, if I were to make this an alias, how would I do that? Thank you.
$(<filename) says return the contents of the file filename, here the content of that file is a string (e.g. 49388) so the variable cpu will have that string. Think of it as $(cat filename), just that bash will do it itself rather than calling cat to do it.
The temperature from that file is the temperature*1000. $(echo "$cpu / 100 * 0.1" | bc) passes the equation (using the value above) "49388 / 100 * 0.1" to the calculator program bc. It isn't just divided by 1000 because in bc the divide operator returns the quotient so 49388 / 100 will give the answer 493 (the 0.88 is discarded), this is then multiplied by 0.1 to effectively divide by a further 10 to get the answer but this time keeping the fractional part to give 49.3
She who travels light — forgot something.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2489
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: GPU & CPU Temp in Fahrenheit

Sun May 27, 2018 1:51 pm

That's a very detailed and accurate answer. All I would add is the reason for the awk command.

The output from "vcgencmd measure_temp" is of the form "temp=48.3'C", so a lazy (laziness can be a virtue) way of extracting the number is to split the input at the "=" and the "'", and keep the second element.

Jeffrey.j
Posts: 8
Joined: Sun Mar 12, 2017 8:54 pm

Re: GPU & CPU Temp in Fahrenheit

Sun May 27, 2018 7:14 pm

Paeryn wrote:
Sun May 27, 2018 1:54 am
Jeffrey.j wrote:
Sun May 27, 2018 12:05 am
PhilE wrote:
Tue Apr 18, 2017 2:00 pm

Code: Select all

#!/bin/bash
gpu=$(/opt/vc/bin/vcgencmd measure_temp | awk -F "[=\']" '{print $2}')
cpu=$(</sys/class/thermal/thermal_zone0/temp)
cpu=$(echo "$cpu / 100 * 0.1" | bc)
cpuf=$(echo "(1.8 * $cpu) + 32" |bc)
gpuf=$(echo "(1.8 * $gpu) + 32" |bc)
echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $gpu'C ($gpuf'F)"
echo "CPU => $cpu'C ($cpuf'F)"
Hi. I know this is an older post but I was hoping that you could briefly explain these parts:

Code: Select all

 awk -F "[=\']" '{print $2}' 
That is a very simple awk program that splits each line from the input file into fields where fields are delimited by either an equals sign or a single quote and outputs the second field.
-F "[=\']" sets the field separator, if you give a string of more than one character then the string is a regular expression.
'{print $2}' is the awk program to run. No pattern is given so it will be applied to every line, $n means the item that is the nth field.
Jeffrey.j wrote:
Sun May 27, 2018 12:05 am

Code: Select all

cpu=$(echo "$cpu / 100 * 0.1" | bc)
(Just why this one is nessessary), and why is there a “<“ here:

Code: Select all

cpu=$(</sys/class/thermal/thermal_zone0/temp)
. Also, if I were to make this an alias, how would I do that? Thank you.
$(<filename) says return the contents of the file filename, here the content of that file is a string (e.g. 49388) so the variable cpu will have that string. Think of it as $(cat filename), just that bash will do it itself rather than calling cat to do it.
The temperature from that file is the temperature*1000. $(echo "$cpu / 100 * 0.1" | bc) passes the equation (using the value above) "49388 / 100 * 0.1" to the calculator program bc. It isn't just divided by 1000 because in bc the divide operator returns the quotient so 49388 / 100 will give the answer 493 (the 0.88 is discarded), this is then multiplied by 0.1 to effectively divide by a further 10 to get the answer but this time keeping the fractional part to give 49.3
Thank you so much this really helps! Also is there a way I could make this into an alias?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2489
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: GPU & CPU Temp in Fahrenheit

Sun May 27, 2018 7:17 pm

Yes, in one form or another, but what advantage do you think that would have?

Jeffrey.j
Posts: 8
Joined: Sun Mar 12, 2017 8:54 pm

Re: GPU & CPU Temp in Fahrenheit

Sun May 27, 2018 10:28 pm

PhilE wrote:
Sun May 27, 2018 7:17 pm
Yes, in one form or another, but what advantage do you think that would have?
Well I plan on checking the temperature every once in a while, so instead of typing this all in/copy and pasting it, I could just type in a simple command that is an alias to simplify it.

Update: I played around with it and I figured out how to do it :D! Thank you for the help though.

JeffZ123
Posts: 16
Joined: Sun Aug 12, 2018 3:43 pm

Re: GPU & CPU Temp in Fahrenheit

Wed Aug 22, 2018 4:05 pm

Thanks for the script!

Also simple thing probably everyone knows, but you can use the watch command to monitor the output in a dedicated window (where the script above is put in the file "temperature.sh") like so:

(Ctrl-C to exit)

Code: Select all

[email protected]:~ $watch temperature.sh

Every 2.0s: ./temperature.sh                                                                                                                                           retropie: Wed Aug 22 16:04:04 2018

Wed Aug 22 16:04:04 UTC 2018 @ retropie
-------------------------------------------
GPU => 41.9'C (107.4'F)
CPU => 41.3'C (106.3'F)


See the watch man page for how to configure things like output frequency (--interval) etc.

drushtx
Posts: 36
Joined: Wed Mar 21, 2012 6:16 pm
Location: Houston, Texas
Contact: Website Yahoo Messenger Facebook YouTube

Re: GPU & CPU Temp in Fahrenheit

Wed Dec 26, 2018 9:29 pm

DougieLawson wrote:
Sat Jul 01, 2017 6:29 am
OutsourcedGuru wrote:As someone in the states and since we still use Fahrenheit, it would be nice to have this support via raspi-config (display celsius or fahrenheit) versus a single setting.
A better option would be for you to shout at your Government until they drop the use of Imperial and American units and start using ISO units for everything. I'm sure Mr. Trump would like the chaos that would cause.
Seriously? This is permissible? May I take political potshots at Mrs. May, as well or would the author prefer to "educate" me with an instructive baseball bat?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2489
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: GPU & CPU Temp in Fahrenheit

Wed Dec 26, 2018 10:08 pm

Dougie is skating on very thin ice with that signature of his.

User avatar
Greg Erskine
Posts: 115
Joined: Sat Sep 15, 2012 4:20 am

Re: GPU & CPU Temp in Fahrenheit

Thu Dec 27, 2018 12:51 am

drushtx wrote:
Wed Dec 26, 2018 9:29 pm
Seriously? This is permissible? May I take political potshots at Mrs. May, as well
Would anyone care?
or would the author prefer to "educate" me with an instructive baseball bat?
He is NOT allowed to figuratively "use" his "educational baseball bat" on this forum. Are you trying to bait him? :mrgreen:
* Raspberry Pi is a trademark of the Raspberry Pi Foundation

OutsourcedGuru
Posts: 64
Joined: Mon Jun 19, 2017 11:15 pm

Re: GPU & CPU Temp in Fahrenheit

Sat Oct 19, 2019 11:07 pm

PhilE wrote:
Wed Dec 26, 2018 10:08 pm
Dougie is skating on very thin ice with that signature of his.
Well, you saw my response earlier

An operating system if it's released to the world should attempt to make the world's citizens feel included. We add locales, default languages, we format references to money and dates correctly for each person. We even accommodate the right-to-left sort of languages on displays and consoles. I should know since I've recently written a program which supports many different languages/locales and everything formats as expected for each.

That said, there's nothing to suggest that Celsius is the only way the world communicates heat. It's an exceedingly-simple calculation. The omission in Raspbian of the configurable option seems like an oversight.

Is this being considered or not as a feature?

User avatar
scruss
Posts: 2628
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: GPU & CPU Temp in Fahrenheit

Sun Oct 20, 2019 12:15 am

OutsourcedGuru wrote:
Sat Oct 19, 2019 11:07 pm
Is this being considered or not as a feature?
I think it's only likely to happen if someone upstream ports it; that is, no-one at the Raspberry Pi/Raspbian teams have time. Since the current maintainer of lxpanel is in Ukraine, they're probably not going to do it themselves either. So submit patches or it's unlikely to happen.

Language, script and locale are a part of national identity. Being the only country using weird old units? That's a choice.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
DougieLawson
Posts: 36576
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GPU & CPU Temp in Fahrenheit

Sun Oct 20, 2019 3:52 pm

The USA is in a group of three that use non-metric things.

The rest of the world is either fully metric or stupidly stuck in their 50 year transition from imperial (feet/inches/yards/furlongs/miles, pounds/ounces, inHg, etc) to mostly metric - like the silly Untied Kingdom. I was taught both systems at school 50 years ago.

I liked the way Ireland changed speed limits first then changed distances between towns (the UK could follow that example).

We also need to accept that 500ml of beer/milk is close enough to 568ml to not adversely affect the price. It's obvious the quantity per unit will change, the price per unit won't. I'll rely on Wetherspoons doing the right thing with a "metric pint".

There still remains no value in the Fahrenheit temperature regardless of metrication.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24162
Joined: Sat Jul 30, 2011 7:41 pm

Re: GPU & CPU Temp in Fahrenheit

Sun Oct 20, 2019 6:38 pm

All the docs use centigrade, all posts on forums use centigrade. Having something report in fahrenheit would be massively confusing.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

gordon77
Posts: 4305
Joined: Sun Aug 05, 2012 3:12 pm

Re: GPU & CPU Temp in Fahrenheit

Sun Oct 20, 2019 6:44 pm

DougieLawson wrote:
Sun Oct 20, 2019 3:52 pm
a "metric pint".

:lol: a metric pint, that's a new concept to confuse.

User avatar
scruss
Posts: 2628
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: GPU & CPU Temp in Fahrenheit

Sun Oct 20, 2019 8:53 pm

jamesh wrote:
Sun Oct 20, 2019 6:38 pm
… Having something report in fahrenheit would be massively confusing.
You could sell a lot of CPU fans to the unsuspecting, though …
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
PeterO
Posts: 5148
Joined: Sun Jul 22, 2012 4:14 pm

Re: GPU & CPU Temp in Fahrenheit

Sun Oct 20, 2019 9:03 pm

gordon77 wrote:
Sun Oct 20, 2019 6:44 pm
DougieLawson wrote:
Sun Oct 20, 2019 3:52 pm
a "metric pint".
:lol: a metric pint, that's a new concept to confuse.
At the time we went metric my late Father owned a Joinery business. Sometimes I used to go to work with him during my school holidays.
I can remember the timber merchants would sell "metric yards" of wood (which were 39 inches if I remember correctly). :lol:
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
davidcoton
Posts: 4258
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: GPU & CPU Temp in Fahrenheit

Sun Oct 20, 2019 10:53 pm

PeterO wrote:
Sun Oct 20, 2019 9:03 pm
At the time we went metric my late Father owned a Joinery business. Sometimes I used to go to work with him during my school holidays.
I can remember the timber merchants would sell "metric yards" of wood (which were 39 inches if I remember correctly). :lol:
A "metric foot" is 300mm, still used in the building trade as a standard unit (though the name is not often remembered).
It is a unit aligned with the metric system but approximately the same as an imperial foot.

So I suspect a "metric yard" may be 900mm (35.5") -- timber is still commonly sold in multiples of 900mm.
39" is also possible, as that converts to about 990mm, but the logic there is reversed (an imperial measurement approximating to 1m),

Network cable is commonly supplied with a length of 305m (1000ft) on a drum.
Signature retired

User avatar
rpdom
Posts: 15596
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPU & CPU Temp in Fahrenheit

Mon Oct 21, 2019 8:08 am

I still find model railways amusing.

They work in scales like 4mm = 1foot.

Return to “Beginners”