Advertisement
Guest User

print CPU temperature on Raspberry Pi

a guest
Jan 4th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. import subprocess
  2. import time
  3.  
  4. while True:
  5.     args = ['cat', '/sys/class/thermal/thermal_zone0/temp']
  6.     try:
  7.         res = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
  8.     except:
  9.         print("Error.")
  10.  
  11.     output = res.communicate()
  12.     tempature = int(output[0]) / 1000.0
  13.     print('cpu tempature = {0:.4f}℃'.format(tempature))
  14.     time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement