Pimaxin
Posts: 78
Joined: Sat Jan 19, 2019 7:34 pm

[ubuntu] Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 1:32 am

I have Ubuntu installed on my Raspberry Pi 4 and was wondering if there's a way to run vcgencmd or get the CPU tempature?

mallets
Posts: 5
Joined: Thu Sep 19, 2019 4:00 am

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 4:02 am

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
works for me. I'm still searching for the CPU freq value though.

Pimaxin
Posts: 78
Joined: Sat Jan 19, 2019 7:34 pm

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 9:17 am

mallets wrote:
Thu Sep 19, 2019 4:02 am

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
works for me. I'm still searching for the CPU freq value though.
What’s 38459 supposed to mean?

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

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 9:31 am

Pimaxin wrote:
Thu Sep 19, 2019 9:17 am
mallets wrote:
Thu Sep 19, 2019 4:02 am

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
works for me. I'm still searching for the CPU freq value though.
What’s 38459 supposed to mean?
It's a prime number!
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Working in the Application's Team.

Heater
Posts: 18028
Joined: Tue Jul 17, 2012 3:02 pm

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 9:42 am

The successor to 38458.
Memory in C++ is a leaky abstraction .

Heater
Posts: 18028
Joined: Tue Jul 17, 2012 3:02 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 10:30 am

A clue for American viewers. It works in Centigrade.
Memory in C++ is a leaky abstraction .

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

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 10:32 am

Pimaxin wrote:
Thu Sep 19, 2019 9:17 am
mallets wrote:
Thu Sep 19, 2019 4:02 am

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
works for me. I'm still searching for the CPU freq value though.
What’s 38459 supposed to mean?
If that is the value returned from that command for you, it means your CPU temperature is currently 38.459°C
Unreadable squiggle

User avatar
DougieLawson
Posts: 41203
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: [ubuntu] Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 10:34 am

Take the prime number divide by 1000, multiply by 1.8 and add 32. You'l then get the temperature on the scale of that really bad physicist Mr. F.

I'm surprised nobody has suggested getting the userland (https://GitHub.com/raspberrypi/userland) pieces installed on Ubuntu. To add some of the missing pieces.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Heater
Posts: 18028
Joined: Tue Jul 17, 2012 3:02 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 11:56 am

Now, now, you can't go round calling members of the FRS "bad physisists".

Physics did not exist back then. Guys like Mr F. invented it for us.

Rock bands and authors have been celebrating his name for ages: https://en.wikipedia.org/wiki/Fahrenhei ... biguation)
Memory in C++ is a leaky abstraction .

User avatar
BluPI2
Posts: 52
Joined: Sun May 10, 2015 3:56 am
Location: United States

Re: [ubuntu] Getting CPU tempature on Ubuntu

Sun Sep 22, 2019 5:40 am

There is a nice way to add this to the taskbar in Ubuntu

Steps
1. Right-click taskbar and click +add to panel

2. Scroll down and Highlight Command(Shows the output of a command), Click Add

3. Right-click the newly added widget, click preferences, and set interval seconds to 5
and max character width to 2. Copy and Paste this command into the Command Box

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
You now get the temperature displayed in your taskbar which updates every 5 seconds displayed in Celsius.

Even in the United States we still use Centigrade to measure the temperature of a CPU.
Proud Owner of a Raspberry Pi 3B and 3B+ running Ubuntu Mate

aduen
Posts: 1
Joined: Tue May 05, 2020 11:33 am

Re: [ubuntu] Getting CPU tempature on Ubuntu

Tue May 05, 2020 11:50 am

For the bash aficionados:

Code: Select all

#!/bin/bash

temp=$(</sys/class/thermal/thermal_zone0/temp)

temp_f=`echo "$temp/1000" | bc -l`
printf "CPU Temp: %.3f°C\n"  $temp_f
>> CPU Temp: 40.407°C

aturfer
Posts: 5
Joined: Sat Feb 25, 2012 7:50 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Sat Jun 06, 2020 11:12 pm

For those who feel like compiling something, create file temp.c with the following:

Code: Select all

#include <stdio.h>

int main(int argc, char *argv[]) 
{
   FILE *fp;

   int temp = 0;
   fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
   fscanf(fp, "%d", &temp);
   printf(">> CPU Temp: %.2f°C\n", temp / 1000.0);
   fclose(fp);

   return 0;
}
Compile with:

Code: Select all

$ gcc temp.c -o temp
Then copy to directory in your path:

Code: Select all

$ sudo mv ./temp /usr/local/bin/
Run from anywhere:

Code: Select all

aturfer@pi4:~$ temp
>> CPU Temp: 42.35°C

aturfer
Posts: 5
Joined: Sat Feb 25, 2012 7:50 pm

Re: Getting CPU tempature on Ubuntu

Sat Jun 06, 2020 11:44 pm

mallets wrote:
Thu Sep 19, 2019 4:02 am
I'm still searching for the CPU freq value though.

Current CPU frequency:

Code: Select all

echo ">> CPU Freq:" $(($(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)/1000))MHz

To get min/max CPU frequency range:

Code: Select all

lscpu | grep -i mhz

saikiran91
Posts: 1
Joined: Sat Jul 04, 2020 1:32 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Sat Jul 04, 2020 1:34 pm

aturfer wrote:
Sat Jun 06, 2020 11:12 pm
For those who feel like compiling something, create file temp.c with the following:

Code: Select all

#include <stdio.h>

int main(int argc, char *argv[]) 
{
   FILE *fp;

   int temp = 0;
   fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
   fscanf(fp, "%d", &temp);
   printf(">> CPU Temp: %.2f°C\n", temp / 1000.0);
   fclose(fp);

   return 0;
}
Compile with:

Code: Select all

$ gcc temp.c -o temp
Then copy to directory in your path:

Code: Select all

$ sudo mv ./temp /usr/local/bin/
Run from anywhere:

Code: Select all

aturfer@pi4:~$ temp
>> CPU Temp: 42.35°C
Simple and sexy. One more request how can we get a continuous updates.

insanish1
Posts: 1
Joined: Mon Aug 10, 2020 3:25 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Mon Aug 10, 2020 3:28 pm

saikiran91 wrote:
Sat Jul 04, 2020 1:34 pm
aturfer wrote:
Sat Jun 06, 2020 11:12 pm
For those who feel like compiling something, create file temp.c with the following:

Code: Select all

#include <stdio.h>

int main(int argc, char *argv[]) 
{
   FILE *fp;

   int temp = 0;
   fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
   fscanf(fp, "%d", &temp);
   printf(">> CPU Temp: %.2f°C\n", temp / 1000.0);
   fclose(fp);

   return 0;
}
Compile with:

Code: Select all

$ gcc temp.c -o temp
Then copy to directory in your path:

Code: Select all

$ sudo mv ./temp /usr/local/bin/
Run from anywhere:

Code: Select all

aturfer@pi4:~$ temp
>> CPU Temp: 42.35°C
Simple and sexy. One more request how can we get a continuous updates.
root@brobdinang:~# watch tempchk
Attachments
tempchk.PNG
tempchk.PNG (4.8 KiB) Viewed 20288 times

wirpool
Posts: 1
Joined: Sat Aug 22, 2020 7:55 am

Re: [ubuntu] Getting CPU tempature on Ubuntu

Sat Aug 22, 2020 8:04 am

Hi everyone, you can check the temperature with a command

install it with

Code: Select all

sudo apt lm-sensors
than type the following for temperature

Code: Select all

sensors
add -f as below if you want the temp in farenheit

Code: Select all

sensors -f
obviusly you can find all info typing

Code: Select all

sensors --help
hope it will be usefull :D :D

SnowFuhrer
Posts: 1
Joined: Sat Dec 19, 2020 8:24 am

Re: [ubuntu] Getting CPU tempature on Ubuntu

Sat Dec 19, 2020 8:28 am

Just been learning bash tonight xD. Here is a modified script which has live update.

Code: Select all

#!/bin/bash

temp=$(</sys/class/thermal/thermal_zone0/temp)

while true
do
 temp=$(</sys/class/thermal/thermal_zone0/temp)
 temp_f=`echo  "$temp/1000" | bc -l`
 printf  "CPU Temp: %.3f C\r\e\e[?25l"  $temp_f
 sleep 1
done

couling
Posts: 6
Joined: Sat Aug 25, 2012 11:01 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Wed Mar 10, 2021 3:52 pm

So the original question was about the vcgencmd command. I'm a little surprised that comments haven't pointed out that it's available in the libraspberrypi-bin package.

Assuming you have "universe" in your /etc/apt/sources.list you can just:

Code: Select all

sudo apt-get install libraspberrypi-bin

There's a note here to suggest that "linux methods" are inaccurate:
Due to the architecture of the SoCs used on the Raspberry Pi range, and the use of the upstream temperature monitoring code in the Raspberry Pi OS distribution, Linux-based temperature measurements can be inaccurate.

User avatar
kerry_s
Posts: 2046
Joined: Thu Jan 30, 2020 7:14 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Wed Mar 10, 2021 4:02 pm

Code: Select all

sudo apt install gnome-shell-extension-system-monitor
then reload:
alt+f2 r

WB4WTN
Posts: 21
Joined: Thu Jan 17, 2013 9:27 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Tue Apr 13, 2021 9:37 pm

I just use vcgencmd measure_temp.

User avatar
kerry_s
Posts: 2046
Joined: Thu Jan 30, 2020 7:14 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Tue Apr 13, 2021 10:14 pm

WB4WTN wrote:
Tue Apr 13, 2021 9:37 pm
I just use vcgencmd measure_temp.
i do to, but ubuntu does not have that.

fprietog
Posts: 3
Joined: Sun Mar 28, 2021 5:15 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Wed Apr 14, 2021 11:23 am

Command vcgencmd is available for Ubuntu in the package libraspberrypi-bin.

Anyway, my favorite ways to control temperature are psensor and indicator-sensors, both graphical.

Return to “Ubuntu”