Re: [Tutorial] Show RPI's Temperature with a command.
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}'
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}'
Re: [Tutorial] Show RPI's Temperature with a command.
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

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
Re: [Tutorial] Show RPI's Temperature with a command.
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.
Re: [Tutorial] Show RPI's Temperature with a command.
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.
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.
Re: [Tutorial] Show RPI's Temperature with a command.
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?
Re: [Tutorial] Show RPI's Temperature with a command.
And what's the max safe temeprature for RPI2?
Re: [Tutorial] Show RPI's Temperature with a command.
Just a small update for those who use this method of getting the core temperature.
I'm surprised that noone here posted about the 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
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 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.
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.
I'm surprised that noone here posted about the
Code: Select all
watch
If you do
Code: Select all
watch -n 10 vcgencmd measure_temp

Code: Select all
measure_temp
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.
Re: [Tutorial] Show RPI's Temperature with a command.
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.
Re: [Tutorial] Show RPI's Temperature with a command.
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!
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: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./opt/vc/bin/vcgencmd measure_temp
Making the .bash_aliases file by running the command:Make sure you are in your home directory before making the file. You can check by making sure your terminal says pi@raspberrypi ~ $ and (~) meaning you are in your home directory. if you are not just run the commandsudo nano .bash_aliases.cd ~
In the file wright the aliases. example: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 (=).alias temp='/opt/vc/bin/vcgencmd measure_temp'
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.
I'm a total novice, non-programer (...basically a hack.)
Re: [Tutorial] Show RPI's Temperature with a command.
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.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
Re: [Tutorial] Show RPI's Temperature with a command.
Did you log out and login again (or reboot) before trying to use the alias?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
Re: [Tutorial] Show RPI's Temperature with a command.
THANK YOU! you're a genius! (or I'm a dummy!!!!)DirkS wrote:Did you log out and login again (or reboot) before trying to use the alias?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
I'm a total novice, non-programer (...basically a hack.)
Re: [Tutorial] Show RPI's Temperature with a command.
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()
******* 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()
Re: [Tutorial] Show RPI's Temperature with a command.
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()
Re: [Tutorial] Show RPI's Temperature with a command.
=> /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?
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?
-
- Posts: 1
- Joined: Sun Mar 05, 2017 2:51 am
Re: [Tutorial] Show RPI's Temperature with a command.
@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
Check out the comment from onebuck here: https://www.cyberciti.biz/faq/linux-fin ... ent-796904
-
- Posts: 38
- Joined: Sat Feb 04, 2017 3:22 pm
Re: [Tutorial] Show RPI's Temperature with a command.
RNCLOCK wrote:Sorry, first attempt did not format code correctly. Here is correct posting.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()
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
3.141592653589...
Re: [Tutorial] Show RPI's Temperature with a command.
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 (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
stress -c 4 -t 900s
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
-
- Posts: 1
- Joined: Tue Jul 04, 2017 1:54 am
Re: [Tutorial] Show RPI's Temperature with a command.
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
Re: [Tutorial] Show RPI's Temperature with a command.
If you don't want to reboot, you can dosolo2500 wrote: ↑Sun Jul 31, 2016 7:51 pmTHANK YOU! you're a genius! (or I'm a dummy!!!!)DirkS wrote:Did you log out and login again (or reboot) before trying to use the alias?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
Code: Select all
source .bash_aliases

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

Re: [Tutorial] Show RPI's Temperature with a command.
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:

RPi, RPi2 RPi3 tested successfully.
It also has integration for stress to test stability and thermal throttling.
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:

RPi, RPi2 RPi3 tested successfully.
It also has integration for stress to test stability and thermal throttling.
-
- Posts: 3
- Joined: Thu Aug 10, 2017 2:31 pm
Re: [Tutorial] Show RPI's Temperature with a command.
Try this:
/opt/vc/bin/vcgencmd measure_temp|awk -F '=' '{print $2}'|awk -F "'" '{print $1}'
/opt/vc/bin/vcgencmd measure_temp|awk -F '=' '{print $2}'|awk -F "'" '{print $1}'
-
- Posts: 11
- Joined: Sun Jul 19, 2020 9:52 am
Re: [Tutorial] Show RPI's Temperature with a command.
Hiya, just wanted to report this command doesn't work on the new 64-bit Raspberry Pi OS.
pi@raspberrypi:~ $ /opt/vc/bin/vcgencmd measure_temp
-bash: /opt/vc/bin/vcgencmd: No such file or directory
This is being ran via SSH but same result when running locally. Just letting y'all know!
pi@raspberrypi:~ $ /opt/vc/bin/vcgencmd measure_temp
-bash: /opt/vc/bin/vcgencmd: No such file or directory
This is being ran via SSH but same result when running locally. Just letting y'all know!
Re: [Tutorial] Show RPI's Temperature with a command.
danielktdoranie wrote: ↑Sun Jul 19, 2020 9:55 amHiya, just wanted to report this command doesn't work on the new 64-bit Raspberry Pi OS.
pi@raspberrypi:~ $ /opt/vc/bin/vcgencmd measure_temp
-bash: /opt/vc/bin/vcgencmd: No such file or directory
This is being ran via SSH but same result when running locally. Just letting y'all know!
Code: Select all
which vcgencmd
/usr/bin/vcgencmd
vcgencmd measure_temp
temp=38.0'C
Re: [Tutorial] Show RPI's Temperature with a command.
It was moved.danielktdoranie wrote: ↑Sun Jul 19, 2020 9:55 amHiya, just wanted to report this command doesn't work on the new 64-bit Raspberry Pi OS.
pi@raspberrypi:~ $ /opt/vc/bin/vcgencmd measure_temp
-bash: /opt/vc/bin/vcgencmd: No such file or directory
2) libraspberrypi0, libraspberrypi-dev and libraspberrypi-doc have been moved out of /opt/vc/* and into /usr/* instead (making it more standard). Any code built against these libraries will require changing to refer to a more standard location (/usr/lib/ rather than /opt/vc/lib)