weebuolu
Posts: 4
Joined: Fri Mar 11, 2016 9:18 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Wed Apr 13, 2016 8:53 pm

This is a really stupid question but I'm stuck just getting the decimal value out of "/opt/vc/bin/vcgencmd measure_temp". I get "temp=49.9'C" where I just nee "49.9". I see python examples but is there some simple grep / awk / sed command that will get this out for me?

I feel I'm getting close with this but all it does is still return the whole line...just highlights exactly the part I need in red

/opt/vc/bin/vcgencmd measure_temp | grep -E '[0-9]{,3}\.[0-9]{,3}'

weebuolu
Posts: 4
Joined: Fri Mar 11, 2016 9:18 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Wed Apr 13, 2016 9:00 pm

Never mind :) Feel silly now.

I just needed an extra grep switch - o

/opt/vc/bin/vcgencmd measure_temp | grep -E -o '[0-9]{,3}\.[0-9]{,3}'

49.4

David613
Posts: 57
Joined: Tue Mar 08, 2016 5:20 am

Re: [Tutorial] Show RPI's Temperature with a command.

Wed May 18, 2016 3:46 am

I've been trying to get an accurate temp from my pi running Ubuntu, I've tried cat /sys/class/thermal/thermal_zone0 temp and /opt/vc/bin vcgenmd measure_temp. Both give the same temp, but both are very much higher then it seems like they should be, within under 2min of starting the pi after its defiantly at room temp the lowest I've gotten was 41°c. Room temp is around 19°c. Is there any real way it could be getting that hot in just about 2min? For instance I just got a temp of 48.9°c and then checked uptime and it was 19 min. Any advice would be appreciated.

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

Re: [Tutorial] Show RPI's Temperature with a command.

Wed May 18, 2016 4:43 am

41°C isn't hot. It's about the normal running temperature for a Pi1 or 2. A Pi 3 will run hotter.

I wouldn't worry about it unless it starts getting over 60°C with little loading, or 70+ with a medium load.

Try comparing those figures with a PC. My old laptop when idling is showing 42. My new one (with very light light use) is showing up to 50. I know some of my old desktops used to run between 80 and 100 when fully loaded (with a good heatsink and fan) and were set to shutdown if they reached 120.

David613
Posts: 57
Joined: Tue Mar 08, 2016 5:20 am

Re: [Tutorial] Show RPI's Temperature with a command.

Thu May 19, 2016 5:24 pm

Right, I know that it's not that hot, but what I'm wondering is why after being off for several hours (up to about 8 hours) within just a few minutes of powering it on why is the temp so much higher then room temp? Will it really create that much heat that quickly? Or is there something going on with the calibration?

FlashT
Posts: 64
Joined: Fri Jul 24, 2015 3:51 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Wed May 25, 2016 4:26 pm

And what's the max safe temeprature for RPI2?

Red Baron
Posts: 1
Joined: Sun Aug 23, 2015 7:50 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Sun Jul 24, 2016 8:11 pm

Just a small update for those who use this method of getting the core temperature.

I'm surprised that noone here posted about the

Code: Select all

watch
tool. This is basically a tool for monitoring a specific thing on your system - changes in files, devices, temperatures, wifi signal etc.

If you do

Code: Select all

watch -n 10 vcgencmd measure_temp
in your SSH session (of course it also work on the Pi locally too ;)) you will get an update on the return value of the

Code: Select all

measure_temp
every 10 seconds.

If you want more data you can use the htop patch which adds temperature monitoring to the ever so awesome task manager tool

Code: Select all

htop
.

If temperature is an issue for someone add a heatsink for passive cooling. If that's not enough add active cooling with a tiny fan. You can connect the fan to the 5V and GND pins of the Pi in order to provide it with power. I doubt that a larger fan will be necessary since the small one directs the cool air pretty neatly straight to the heat sink of the CPU.

David613
Posts: 57
Joined: Tue Mar 08, 2016 5:20 am

Re: [Tutorial] Show RPI's Temperature with a command.

Sun Jul 24, 2016 9:43 pm

I would caution with adding a fan to make sure that the fan can function on the gpio current and voltage. When i got my first pi case it came with a fan so I assumed it would just be a matter of hiking it up but it never ran. It just got very hot. I'm not sure if it was because it was a defective fan or it needed higher current then the gpio provides. It was some cheapie they probably got for 5¢and only had the voltage requirement labeled so it could go either way.

solo2500
Posts: 106
Joined: Sat Jul 09, 2016 12:38 am

Re: [Tutorial] Show RPI's Temperature with a command.

Sun Jul 31, 2016 5:21 pm

This doesn't seem to work for me?
Ok... cd ~
pwd= /home/pi
sudo nano .bash_aliases
then paste in: alias temp='/opt/vc/bin/vcgencmd measure_temp'
back out (cont X)
and when I type temp: -bash: temp: command not found
I'm new to Linux coding!!! help please!

eXsoR wrote:So i decided to make a quick Tutorial on how to show the Raspberry PI's Temperature.
Note: this is using the on-board sensor.

The command to do this is:
/opt/vc/bin/vcgencmd measure_temp
You can also simplify the command by making an alias and adding it to your ~/.bashrc or as instructed in the bashrc file. Make a file in your home directory called .bash_aliases and put your aliases in that file rather then in the .bashrc file.

Making the .bash_aliases file by running the command:
sudo nano .bash_aliases
Make sure you are in your home directory before making the file. You can check by making sure your terminal says [email protected] ~ $ and (~) meaning you are in your home directory. if you are not just run the command
cd ~
.



In the file wright the aliases. example:
alias temp='/opt/vc/bin/vcgencmd measure_temp'
note: if you don't put the apostrophe ( ' ) before and after the command it wont work. Also note that I put the nickname that you are going to give this command, followed up a equals sign (=).

I hope you guys find this useful is I did. Since i live in a very hot environment that I like to check the temp here and there. :D
I'm a total novice, non-programer (...basically a hack.)

DNPNWO
Posts: 126
Joined: Fri Jul 08, 2016 1:51 am

Re: [Tutorial] Show RPI's Temperature with a command.

Sun Jul 31, 2016 5:31 pm

David613 wrote:I would caution with adding a fan to make sure that the fan can function on the gpio current and voltage. When i got my first pi case it came with a fan so I assumed it would just be a matter of hiking it up but it never ran. It just got very hot. I'm not sure if it was because it was a defective fan
Chances are you never changed the connector wires around- red on GPIO 4 and black on GPIO 6. First time I connected mine to the Pi, it didn't turn on either- until I reversed the wires...and I am using a 12v brushless PC fan on the 5v rail, and it works just fine.

DirkS
Posts: 10127
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: [Tutorial] Show RPI's Temperature with a command.

Sun Jul 31, 2016 5:57 pm

solo2500 wrote:This doesn't seem to work for me?
Ok... cd ~
pwd= /home/pi
sudo nano .bash_aliases
then paste in: alias temp='/opt/vc/bin/vcgencmd measure_temp'
back out (cont X)
and when I type temp: -bash: temp: command not found
Did you log out and login again (or reboot) before trying to use the alias?

solo2500
Posts: 106
Joined: Sat Jul 09, 2016 12:38 am

Re: [Tutorial] Show RPI's Temperature with a command.

Sun Jul 31, 2016 7:51 pm

DirkS wrote:
solo2500 wrote:This doesn't seem to work for me?
Ok... cd ~
pwd= /home/pi
sudo nano .bash_aliases
then paste in: alias temp='/opt/vc/bin/vcgencmd measure_temp'
back out (cont X)
and when I type temp: -bash: temp: command not found
Did you log out and login again (or reboot) before trying to use the alias?
THANK YOU! you're a genius! (or I'm a dummy!!!!)
I'm a total novice, non-programer (...basically a hack.)

RNCLOCK
Posts: 2
Joined: Wed Sep 07, 2016 4:23 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Wed Sep 07, 2016 4:31 pm

I know this thread is old, but stumbled across it while looking for a way to watch real time temperature changes on PI3. Thought I would post my resolution. It is a python script that creates a small box with both C anf F temperatures updating every 2 secs. Made a desktop icon to run on demand. Created for 1900x1080 display. Geometry puts it in lower right corner.


******* CODE *******
#!/usr/bin/env python
import tkinter as tk
import os

def temp_label(label):

def Temp():
t = os.popen("vcgencmd measure_temp").readline()
c=(t.replace("temp=","").replace("'C\n",""))
f=round(9.0/5.0*int(float(c))+32,1)
label.config(text="\nTemp= "+str(f)+" F\n\n"+"Temp= "+str(c)+" C\n")
label.after(2000, Temp)
Temp()

box = tk.Tk()
box.title("Temperatures")
box.geometry('+1800+1030')
box.configure(bg="light green")
label = tk.Label(box, fg="black", bg="light green", padx=12, pady=12, height=3, relief= "flat")
label.pack()
temp_label(label)
stop = tk.Button(box, text='Stop', width=5, fg="white", bg="red", relief= "raised", command=box.destroy)
stop.pack()
box.mainloop()

RNCLOCK
Posts: 2
Joined: Wed Sep 07, 2016 4:23 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Wed Sep 07, 2016 7:12 pm

Code: Select all

#!/usr/bin/env python
import tkinter as tk
import os

def temp_label(label):

    def Temp():
        t = os.popen("vcgencmd measure_temp").readline()
        c=(t.replace("temp=","").replace("'C\n",""))
        f=round(9.0/5.0*int(float(c))+32,1)
        label.config(text="\nTemp= "+str(f)+" F\n\n"+"Temp= "+str(c)+" C\n")
        label.after(2000, Temp)
    Temp()

box = tk.Tk()
box.title("Temperatures")
box.geometry('+1800+1030')
box.configure(bg="light green")
label = tk.Label(box, fg="black", bg="light green", padx=12, pady=12, height=3, relief= "flat")
label.pack()
temp_label(label)
stop = tk.Button(box, text='Stop', width=5, fg="white", bg="red", relief= "raised", command=box.destroy)
stop.pack()
box.mainloop()
Sorry, first attempt did not format code correctly. Here is correct posting.

jytou
Posts: 3
Joined: Sun Jan 08, 2017 4:43 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Sun Jan 08, 2017 5:33 pm

=> /opt/vc/bin/vcgencmd measure_temp
I doubt this is the GPU temp. It shows exactly the same as the CPU temp (launch a compilation to see the CPU go up, but not GPU and launch a video to see GPU temp go up but not CPU).
Is there any temp sensor in the GPU?

nextperson
Posts: 1
Joined: Sun Mar 05, 2017 2:51 am

Re: [Tutorial] Show RPI's Temperature with a command.

Sun Mar 05, 2017 2:54 am

@jytou, yeah it looks like it's one and the same the CPU and GPU temperature.
Check out the comment from onebuck here: https://www.cyberciti.biz/faq/linux-fin ... ent-796904

xXRoboBoyXx
Posts: 38
Joined: Sat Feb 04, 2017 3:22 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Fri Apr 14, 2017 11:56 pm

RNCLOCK wrote:

Code: Select all

#!/usr/bin/env python
import tkinter as tk
import os

def temp_label(label):

    def Temp():
        t = os.popen("vcgencmd measure_temp").readline()
        c=(t.replace("temp=","").replace("'C\n",""))
        f=round(9.0/5.0*int(float(c))+32,1)
        label.config(text="\nTemp= "+str(f)+" F\n\n"+"Temp= "+str(c)+" C\n")
        label.after(2000, Temp)
    Temp()

box = tk.Tk()
box.title("Temperatures")
box.geometry('+1800+1030')
box.configure(bg="light green")
label = tk.Label(box, fg="black", bg="light green", padx=12, pady=12, height=3, relief= "flat")
label.pack()
temp_label(label)
stop = tk.Button(box, text='Stop', width=5, fg="white", bg="red", relief= "raised", command=box.destroy)
stop.pack()
box.mainloop()
Sorry, first attempt did not format code correctly. Here is correct posting.

I Pasted this in and ran it (after sudo chmod +x) and it gave me:

Code: Select all

File "./TempBox.py", line 7
    def Temp():
      ^
IndentationError: expected an indented block
Do you have any help???
3.141592653589...

SANGER_A2
Posts: 59
Joined: Sun Mar 04, 2012 7:39 pm
Contact: Website

Re: [Tutorial] Show RPI's Temperature with a command.

Fri May 05, 2017 9:44 pm

I combined this along with a couple of other scripts that other people have posted here to provide a constant output of CPU and GPU temperature temperature and CPU clock speed that updates every second. All you have to do it press ctrl+c on the keyboard to cancel it. Really useful to run in a separate terminal/putty window while running a command like

Code: Select all

stress -c 4 -t 900s
(assuming you have installed stress from apt) or if you want to monitor which processes cause the CPU to change from it's minimum processor speed.

I wasn't able to find any way to get current GPU frequency (mine scales between 200 and 500), so if anyone knows, please post here!

Anyway, here it is. All of the clever stuff was done by others, I just combined it into a form that was useful to me and will hopefully be useful to others! If you wanted it to update more quickly, just increase the number after sleep at the end (it's seconds) or use a decimal. Bare in mind that if you use a value that's too small it may use more CPU-time itself!

Code: Select all

#!/bin/bash
while true;
do
        cpuSpeed0=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq);
        cpuSpeed1=$(($cpuSpeed0/1000));

        cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp);
        cpuTemp1=$(($cpuTemp0/1000));
        cpuTemp2=$(($cpuTemp0/100));
        cpuTempM=$(($cpuTemp2 % $cpuTemp1));

        echo GPU $(/opt/vc/bin/vcgencmd measure_temp)"  |  CPU temp="$cpuTemp1"."$cpuTempM"'C  |  CPU freq"=$cpuSpeed1"MHz";

        sleep 1;
done

kevalpatel2106
Posts: 1
Joined: Tue Jul 04, 2017 1:54 am

Re: [Tutorial] Show RPI's Temperature with a command.

Tue Jul 04, 2017 1:56 am

If you want to constantly measure the temperature of the raspberry pi, here is the great tutorial which I followed to write the python script for that: https://medium.com/@kevalpatel2106/moni ... dfdf82989f

wgblondel
Posts: 1
Joined: Tue Aug 08, 2017 3:16 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Tue Aug 08, 2017 3:19 pm

solo2500 wrote:
Sun Jul 31, 2016 7:51 pm
DirkS wrote:
solo2500 wrote:This doesn't seem to work for me?
Ok... cd ~
pwd= /home/pi
sudo nano .bash_aliases
then paste in: alias temp='/opt/vc/bin/vcgencmd measure_temp'
back out (cont X)
and when I type temp: -bash: temp: command not found
Did you log out and login again (or reboot) before trying to use the alias?
THANK YOU! you're a genius! (or I'm a dummy!!!!)
If you don't want to reboot, you can do

Code: Select all

source .bash_aliases
And it will reload the config file ;)

(I know this is an old post. But it's very well indexed on Google, and I thought this info would be useful :))

amanusk
Posts: 2
Joined: Sat Aug 05, 2017 11:54 am

Re: [Tutorial] Show RPI's Temperature with a command.

Wed Aug 09, 2017 5:20 pm

I also want to add a solution in case it is useful to someone.

We have created a tool for monitoring CPU temperature/frequency/utilization. It works on *NIX based systems and on both X86 and ARM.

It is a terminal UI tool that shows stats in a graphical way.
Check it out on github:
https://github.com/amanusk/s-tui

Here is a screenshot:
Image

RPi, RPi2 RPi3 tested successfully.

It also has integration for stress to test stability and thermal throttling.

chrisfenton
Posts: 3
Joined: Thu Aug 10, 2017 2:31 pm

Re: [Tutorial] Show RPI's Temperature with a command.

Thu Aug 10, 2017 3:54 pm

Try this:

/opt/vc/bin/vcgencmd measure_temp|awk -F '=' '{print $2}'|awk -F "'" '{print $1}'

Return to “Beginners”