0

Is there an option to display Raspberry Pi's internal temperature value to be able to display it into Guizero UI?

I saw this source code on GitHub, but this only displays random float numbers in the GUI.

Actually, there is an option for Terminal to see current temperature of Raspberry Pi 3 as can be seen below:

/opt/vc/bin/vcgencmd measure_temp

Is there a way using measure_temp code to put into Guizero? Furthermore, Can we run Python terminal codes onto Guizero is also important question.

3

Add a function to read_cpu_temp then call that function to display instead of read_sensor:

from guizero import *
import random   

def read_sensor():
    return random.randrange(3200, 5310, 10) / 100

def read_cpu_temp():
    tFile = open('/sys/class/thermal/thermal_zone0/temp')
    temp = float(tFile.read())
    return temp/1000

def update_label():
    text.value = read_cpu_temp()
    # recursive call
    text.after(1000, update_label)

if __name__ == '__main__':
    app = App(title='Sensor Display!',
              height=100,
              width=200,
              layout='grid')

    title = Text(app, 'Sensor value:', grid=[0, 0])
    text = Text(app, "xx", grid=[1, 0])

    text.after(1000, update_label)
    app.display()
  • Thanks, also I found an alternative: def read_sensor(): temp=os.popen("vcgencmd measure_temp").readline() return(temp.replace("temp=","")) – Bay Oct 29 '18 at 12:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.