Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Part 3. Sense HAT Temperature Correction
You may notice that your Sense HAT's temperature readings seem a bit high - that's because they are. The culprit is the heat generated from the Pi’s CPU heating up the air around the Sense HAT when it is sitting on top of the Pi.
To make the temperature sensor useful, we need to either get the HAT away from the Pi (which would eliminate the important benefit of being a compact solution) or try to calibrate the temperature sensor reading. A good solution for getting the sensor away from the Pi is either a cable that lets the Sense HAT dangle away from the Pi (like this cable https://www.amazon.com/gp/product/B00FZ41S84/) or using something like a GrovePi HAT (https://github.com/initialstate/grovepi/wiki).
The CPU is the primary cause of the parasitic heat affecting our temperature sensor, so we need to figure out the correlation.
When reviewing the Enviro pHAT for the Pi Zero we came up with an equation to account for the CPU temperature affecting a hat's temperature reading. We just need the CPU temperature and a scaling factor to calculate the calibrated temperature:
temp_calibrated = temp - ((cpu_temp - temp)/FACTOR)
We can find the factor by recording the actual temperature and solving for it.
In order to find the actual temperature in the room, we need a different temperature sensor setup. Using a DHT22 sensor (setup instructions here and script here), we can record and visualize both temperatures simultaneously:
The result reveals that the Sense HAT's reading is off by 5-6 degrees Fahrenheit pretty consistently.
Adding the CPU temperature into the mix (with this script), first off shows that it is extremely hot, and second off reveals a sort of wave that the Sense HAT measurement mimics.
After recording for about 24 hours, I solved for the factor using six different readings at six different points in time. Averaging the factor values gave a final factor value of 5.466.
Applying the equation
temp_calibrated = temp - ((cpu_temp - temp)/5.466), the calibrated temperature came to within one degree of the actual temperature reading:
You can run this calibration correction on the Pi itself. See https://github.com/initialstate/wunderground-sensehat/blob/master/sensehat_darksky_calibrated.py script.