Skip to content

Part 3. Sense HAT Temperature Correction

jrbail01 edited this page Dec 18, 2018 · 15 revisions

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 or try to calibrate the temperature sensor reading.

A Much Less Compact but Accurate Solution

A good solution for getting the sensor away from the Pi is a cable that lets the Sense HAT dangle away from the Pi. A 6", 40-pin IDE male to female extension cable cable will do the trick https://www.amazon.com/gp/product/B00FZ41S84/).

Complete Setup with Cable

While not as compact as without the cable, this solution provides temperature reading accuracy.

Complete Setup with Cable

A Much Less Accurate but Compact Solution

If you do not want to use an extension cable, a calibration equation can get our local temperature readings in the general ballpark. This is not a super accurate solution but definitely helps. 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.

Alternatively, you can send the raw temperature into your Initial State account and use a Real-Time Expression to do the correction on your dashboard. See https://support.initialstate.com/hc/en-us/articles/360002999932-Introduction-to-Real-Time-Expressions for more information on Real-Time Expressions.

<< Part 3: Hyper-Local Weather Dashboard - Part 4: (Bonus) Add a Map to Your Dashboard >>