Displat CPU temp on Pimoroni Four letter PHAT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import fourletterphat | |
from subprocess import Popen, PIPE | |
print(""" | |
Four Letter pHAT: cpu-temp.py | |
This example will display your Pi's CPU | |
temperature in degrees celsius. | |
Press Ctrl+C to exit. | |
""") | |
while True: | |
# Get temp forom vcgencmd in the format: "temp=XY.Z'C" | |
# and reduce to the format "XYZC" for display | |
temperature = Popen(["vcgencmd", "measure_temp"], stdout=PIPE) | |
temperature = temperature.stdout.read().decode('utf-8') | |
# Rempve "temp=" and the "." and "'" chars | |
temperature = temperature[5:].replace(".", "").replace("'", "").strip() | |
fourletterphat.clear() | |
fourletterphat.print_str(temperature) | |
fourletterphat.set_decimal(1, 1) | |
fourletterphat.show() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment