Skip to content

Instantly share code, notes, and snippets.

@danclegg
Created November 1, 2017 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danclegg/68fbfe4b7d34b192ef085641baee2efd to your computer and use it in GitHub Desktop.
Save danclegg/68fbfe4b7d34b192ef085641baee2efd to your computer and use it in GitHub Desktop.
A python class to present internal temperature of the Raspberry Pi
# -*- coding: utf-8 -*-
# The line above is to allow printing of the degree (°) symbol
from subprocess import call
class PanelTemperature:
degree_sign= u'\N{DEGREE SIGN}'
def __init__(self):
self.c = 0 #It is assumed C is delivered from /opt/vc/bin/vcgencmd measure_temp
self.f = 0
self.k = 0
getTemp()
def toK(self):
return self.c + 273
def toF(self):
return ((self.c * 1.8) + 32)
def getTemp(self):
t = call('/opt/vc/bin/vcgencmd measure_temp')
stripped = t.replace("'C","")
stripped = stripped.replace('temp=','')
self.c = float(stripped)
def getTempC(self):
self.getTemp()
return ('Temp: %d%s C\n',self.c,degree_sign)
def getTempF(self):
self.getTemp()
return ('Temp: %d%s F\n',self.f,degree_sign)
def getTempK(self):
self.getTemp()
return ('Temp: %d K\n',self.k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment