element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Raspi 4 CPU Temperature
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Raspberry Pi requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: eric_element14
  • Date Created: 17 Sep 2019 9:15 PM Date Created
  • Views 321 views
  • Likes 4 likes
  • Comments 2 comments
Related
Recommended

Raspi 4 CPU Temperature

eric_element14
eric_element14
17 Sep 2019

Just got my new RaspberryPi 4. I’d read about the CPU running hotter than previous models, so I decided to have a look for myself.


 

https://www.elinix.org/RPI_vcgencmd_usage gave details of how to do this.


 

I decided to wrap this up in a PyQt5 application so that I could monitor the temperature more easily.


 

So if anyone wants a copy here it is (to cut and paste) or download from:


 

http://www.concept-computing.co.uk

Login as Guest

 

Just got my new RaspberryPi 4. I’d read about the CPU running hotter than previous models, so I decided to have a look for myself.


 

https://www.elinix.org/RPI_vcgencmd_usage gave details of how to do this.


 

I decided to wrap this up in a PyQt5 application so that I could monitor the temperature more easily.


 

So if anyone wants a copy here it is (to cut and paste) or download from:


 

http://www.concept-computing.co.uk

 

 

Screenshot:


 


  image


 


 


 


 


 


  Code:


 

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

#

# cpu_temp.py

#

# Copyright 2019 alan.warden1@gmail.com

#

# This program is free software; you can redistribute it and/or modify

# it under the terms of the GNU General Public License as published by

# the Free Software Foundation; either version 2 of the License, or

# (at your option) any later version.

#

# This program is distributed in the hope that it will be useful,

# but WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

# GNU General Public License for more details.

#

# You should have received a copy of the GNU General Public License

# along with this program; if not, write to the Free Software

# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,

# MA 02110-1301, USA.

#

#


 

###################################

# see https://www.elinix.org/RPI_vcgencmd_usage

# for more info

###################################


 


 


 

import sys

import os


 

from PyQt5.QtWidgets import (QApplication, QDialog, QGridLayout,QLabel,

QLineEdit, QPushButton, QStatusBar, QMainWindow, QDesktopWidget)


 

from PyQt5.QtGui import (QGuiApplication, QIcon, QFont, QFontMetrics)

from PyQt5.QtCore import (Qt, QTimer)


 

class stats_dialog (QDialog):

  def __init__(self):

super(stats_dialog, self).__init__()

  # pastel yellow for the dialogue

self.setStyleSheet("background-color: rgb(250, 250, 210);")

  self.grid = QGridLayout ()

 

self.cpu_temp_lbl = QLabel ('CPU Temperature:')

self.cpu_temp_value = QLineEdit ('CPU')

self.cpu_temp_value.setReadOnly (True)

self.quit_btn = QPushButton ('&Quit')

self.shutdown_btn = QPushButton ('&Shutdown')

  self.tim = QTimer (self)

self.tim.setInterval (5000)

self.tim.start()

 

 

  # build the screen

self.grid.addWidget (self.cpu_temp_lbl,0,0)

self.grid.addWidget (self.cpu_temp_value,0,1)

self.grid.addWidget (self.quit_btn,1,0)

self.grid.addWidget (self.shutdown_btn,1,1)

self.setLayout (self.grid)

 

 

  # signals

self.tim.timeout.connect (self.tim_update)

self.quit_btn.clicked.connect (self.quit_prog)

self.shutdown_btn.clicked.connect (self.kill_computer)


 

 

  def tim_update (self):

os.system('vcgencmd measure_temp > cpu.txt')

  file_in = open ('cpu.txt')

  line = file_in.read ()

file_in.close ()

  line2 = line.split ('=')

self.cpu_temp_value.setText (line2[1])

 

  def quit_prog (self):

QGuiApplication.instance().quit()

 

  def kill_computer (self):

  os.system ('sudo shutdown -h now')

 

 

class main_win (QMainWindow):

  def __init__(self):

super(main_win, self).__init__()

self.setWindowTitle('System Stats')

  self.sb = QStatusBar ()

  self.tim = QTimer (self)

self.tim.setInterval (60000) # 1 minute

self.tim.start ()

self.setStatusBar (self.sb)

  self.dlg = stats_dialog ()

self.setCentralWidget (self.dlg)

 

  # signals

self.tim.timeout.connect(self.tim_update)

 

  def tim_update (self):

os.system('uptime > uptim.txt')

  file_in = open('uptim.txt')

  line = file_in.read ()

file_in.close ()

  line2 = line.split (',')

  msg = line2[0]

  if 'min' not in msg:

  msg = msg + ' hrs'

self.sb.showMessage ('Time: ' + msg)


 

 

def main(args):

  app = QApplication(sys.argv)

  scr = main_win()

scr.setWindowFlag (Qt.WindowStaysOnTopHint)

  scr_size = scr.geometry()

  screen = QDesktopWidget().screenGeometry()

  h_pos = (screen.width() - scr_size.width() ) / 2

  v_pos = (screen.height() - scr_size.height() ) / 2

  # Start roughly in the middle. Then move it to suit

scr.move(h_pos-h_pos/3, v_pos)

  scr.show ()

sys.exit(app.exec_())


 

if __name__ == '__main__':

sys.exit(main(sys.argv))


 


 


 

Notes:


 

This was written in Geany, you’ll need to set the build commands from python to python3 i.e

 

Notes:


 

This was written in Geany, you’ll need to set the build commands from python to python3 i.e


 

 

Notes:


 

This was written in Geany, you’ll need to set the build commands from python to python3 i.e


  image

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Also set the Tab Type to Spaces

 

 

Regards

 

Alan

  • Sign in to reply

Top Comments

  • dougw
    dougw over 3 years ago +4
    I am doing some temperature tests on the Raspberry Pi 4 as well - with a heat sink. I'll post notes on it in the next day or two.
  • luigimorelli
    luigimorelli over 3 years ago

    Hi! I did some testing with PI 3 temperatures with and without a heatsink: http://www.moreware.org/wp/blog/2019/08/08/geeekpi-extreme-cooling-fan-kit-for-raspberrypi-3/

     

    As you can see, when the PI (no matter wether 3 or 4) is under stress, it starts throttling (i.e. its working frequency diminishes). A heatsink (and/or a fan) is what you should use to get your PI cool and responsive: http://www.moreware.org/wp/blog/2019/07/21/raspberry-pi-4-nuovi-sistemi-di-raffreddamento/

     

    You can also find some interesting system parameters (like temperature or frequency on different cores) from your Raspy using a shell script: http://www.moreware.org/wp/blog/2019/08/02/linux-controllo-live-dei-parametri-di-utilizzo/ BTW, this one works on ALL Linux systems, not only on Raspies.

    HTH image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dougw
    dougw over 3 years ago

    I am doing some temperature tests on the Raspberry Pi 4 as well - with a heat sink. I'll post notes on it in the next day or two.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube