Sense Hat internal temperature


#1

I just happened to have a Sense Hat lying around here which wasn't doing anything so I decided to make it work for a living. It's now inside the print volume and is being used to monitor the ambient temperature inside the box.

The Python SenseHat marquee() function allows it to display the temperature (in Fahrenheit here) as it scrolls across the dot matrix display. It will also log the temperature readings to disk.

#!/usr/bin/python

from sense_hat import SenseHat
from datetime import datetime
import time
import arrow
sense = SenseHat()
gray = (48, 48, 48)
marquee = sense.show_message
f = open('./temp-data.csv', 'a');
try:
    while True:
        tC = round(sense.get_temperature(), 1) - 8.5
        tF = round(((tC * 9) / 5) + 32, 1)
        msg = "{0}".format(tF)
        marquee(msg, scroll_speed=0.2, text_colour=gray)
        msgPrint = '"' + datetime.now().strftime('%m/%d/%Y %H:%M') + '",' + msg + ',' + "{0}".format(tC)
        f.write(msgPrint + '\n')
        print(msgPrint)
        time.sleep(10)
finally:
    sense.clear()
    f.close()