Sense Hat sensor wierdness?

Here’s a weird one for you. Ambient light shining on the humidity sensor is affecting the humidity reading? If I put my sense hat out in bright sunlight, shining on the front of it, the % Humidity reading immediately drops. In very bright sun light it actually goes negative? I have two sense hats setup as weather clocks and they both do it. I had a friend check his and its also doing it. Twilight Zone anybody? here is the python code I’m using.

import os
import time, datetime
sense = SenseHat()
sense.set_imu_config(False, False, False)
sense.low_light = True

s=(0.065) # scroll speed
w=(0) # color all white toggle
x=(2) #shutdown variable

# is really stick down
def pushed_up(event):
    if event.action == ACTION_PRESSED:
       sense.low_light = True
# is really stick up
def pushed_down(event):
    if event.action == ACTION_PRESSED:
       sense.low_light = False

#is really stick right
def pushed_left(event):
    global w
    if event.action == ACTION_PRESSED:
        w = (255)
# is really stick left
def pushed_right(event):
    global w
    if event.action == ACTION_PRESSED:
        w = (0)

def pushed_middle(event):
    global x
    if event.action == ACTION_PRESSED:
        x = 0

sense.stick.direction_up = pushed_up
sense.stick.direction_down = pushed_down
sense.stick.direction_left = pushed_left
sense.stick.direction_right = pushed_right
sense.stick.direction_middle = pushed_middle

while True:

    dateString = "%A %B %-d %-I:%M:%p"
    msg = "It is %s" % (
    sense.show_message(msg, scroll_speed=s, text_colour=(w, 255, 255))

    t = sense.get_temperature()
    t = round(t)
    if t <= 0: 
        tc = [w, w, 255]  # Blue
    elif t > 0 and t < 13:
        tc = [255, 255, w]  # Yellow
    elif t >= 13 and t <= 25:
        tc = [w, 255, w]  # Green
    elif t > 25:
        tc = [255, w, w]  # Red                 
    msg = "and %sc" % (t)
    sense.show_message(msg, scroll_speed=s, text_colour=tc)

    h = sense.get_humidity()
    h = round(h)

    if h < 0:
        h = 0

    if h > 100:
        h = 100

    if h < 30:
        hc = [255, w, w]  # Red
        msg = "with %s%% Humidity" % (h)
        sense.show_message(msg, scroll_speed=s, text_colour=hc)
    elif h >= 30 and h <= 60:
        hc = [w, 255, w]  # Green
        msg = "with %s%% Humidity" % (h)
        sense.show_message(msg, scroll_speed=s, text_colour=hc)
    elif h > 60 and h < 80:
        hc = [255, 255, w]  # Yellow
        msg = "with %s%% Humidity" % (h)
        sense.show_message(msg, scroll_speed=s, text_colour=hc)
    elif h >= 80:
        hc = [255, w, w]  # Red
        msg = "with %s%% Humidity" % (h)
        sense.show_message(msg, scroll_speed=s, text_colour=hc)

    p = sense.get_pressure()
    p = round(p)
    if p > 0 and p < 985:
        pc = [255, w, w]  # Red
        msg = "- Barometer is Very Low @ %smb - Storm Watch" % (p)
        sense.show_message(msg, scroll_speed=s, text_colour=pc)
    elif p >= 985 and p < 1005:
        pc = [255, 255, w]  # Yellow
        msg = "- Barometer is Low @ %smb - Possible Percipitation" % (p)
        sense.show_message(msg, scroll_speed=s, text_colour=pc)
    elif p >= 1005 and p < 1025:
        pc = [w, 255, w]  # Green
        msg = "- Barometer is Mid Range @ %smb" % (p)
        sense.show_message(msg, scroll_speed=s, text_colour=pc)
    elif p >= 1025 and p < 1050:
        pc = [w, w, 255]  # Blue
        msg = "- Barometer is High @ %smb" % (p)
        sense.show_message(msg, scroll_speed=s, text_colour=pc)
    elif p >= 1050:
        pc = [255, w, w]  # Red
        msg = "- Barometer is Very High @ %smb - Expect Dry Conditions" % (p) 
        sense.show_message(msg, scroll_speed=s, text_colour=pc)
    if x == 0:
        os.system("sudo shutdown now -P")
    elif x == 1:
        raise SystemExit

# Last edited on April 19th 2018
# run sudo crontab -e
# add
# @reboot python3 /home/pi/ &

Well, I put a small piece of black packing foam / sponge over the sensor and masked out that section on my Ninja diffusor. Readings are no longer affected by the ambient light. They aren’t changing when I put it in direct sunlight anyway. Air is getting through the foam and I think the reading is accurate. My only concern now is whether the foam will retain any moisture in high humidity conditions.
I think I’ll be looking for another solution but this will do for now. I may try a plastic pop bottle cap with a pin hole in it to let air in. I’ll use my diffuser to hold it in place. I’ll just trim it down with an exacto knife

This is curious, I wonder if it’s heat that’s messing up the sensor, or the photo-electric effect. Or a combination!

My first thought was it was the heat building up in the case. I first noticed it on my portable setup. It’s in a waterproof case with some vent holes drilled into it. I added some more vent holes but it didn’t help. That Pi also has a Si1145 light sensor board I use to automatically adjust the brightness of the Sense Hat LED matrix. Thinking my code might have an error that was glitching the readings, I took me second indoor setup outside. That one is just an A+ with DS3231 RTC on a Proto Hat with the Sense hat on top of that. No case, its all open to the air. It did the same thing. Put it in the shade and it reads normal, put it in the sun and the humidity reading immediately drops. I’m talking seconds to change from 60% to 0%. It was I think +6 Celsius when I did that test. I had a friend check his and it did it too.

I had been suspecting something wasn’t right for a while now. Humidity seemed to be reading lower than it should be. I take my portable with me to our dog park to keep an eye on conditions. Because the LED matrix is hard to read in bright sunlight I usually have it positioned so the sun is behind it. And place in the shade if possible. The field got flooded where we normally sit and we changed ends. That put the sun the other way around and it was shining on the front of the case right onto the sense hat. I actually started seeing negative values. That had me go over my code with a fine toothed comb. I didn’t see anything but added code so it will only display as low as zero. I even redid it all from scratch and went back to Jessie. Same weirdness was happing. Seeing it change so fast is telling me its a photo-electric effect, not a temperature thing. I’m sure the case temps affect it, but that’s not what’s causing my quick big swings in readings.

My build pictures are here,!AjOYwiwlwDtpgq8_0VrdS3_H5xL_AA
All my Pi Projects are here,!AjOYwiwlwDtpgUMsp2qnevKpGEHb

Not sure if this factors into the weirdness but that HTS221 Humidity/Temperature sensor is capacitive? That means my foam may be messing up my readings. Guess I’ll have to compare, with and without the foam readings, and compare it to my other sense hat. The fun never ends. . I’m thinking now, I may have to make a hood to cover it that’s open at the bottom but with as much clearance as possible around the sensor. Or do it such that my foam doesn’t actually touch the sensor? Right now my foam is right on the open part of the sensor. My current case doesn’t lend itself to blocking the light from just that section of the sense hat.

My two sense hats are reading the same 60 % so I’ll leave it be for now. One has the foam on it one doesn’t. The one that doesn’t have any foam rarely see’s any direct sunlight. It also has a Ninja Black diffusor on it. I’ll modify it too at some point, once I’m sure what I have is working and not skewing up the readings. The portable is going get a BME680 at some point that will do all the readings, temp, humidity and pressure. The only thing I’ll use on the sense hat is the display. And eventually I’ll replace the sense hat with a Unicorn HD for larger crisper text. On the portable weather clock anyway. The in the house one will likely stay as is.

It must be photo-electric effect. A quick google for various terms around “humidity sensor” and “sunlight” seems to suggest a conventional wisdom of not placing them in direct sunlight.

For example (although the sensor on Sense HAT is a HTS221 I believe?):

(An additional reason for shading the PS-2154A is that the physical humidity sensor used is very light sensitive.)

I agree, that’s what it appears to be from what I’m seeing. My foam cover seems to have fixed my issue. And I don’t think its skewing my readings. Not enough to be noticeable anyway. I’m getting what look to be accurate readings. I don’t have anything else here at home I consider accurate to compare readings with.

Still waiting for a reply from the Pi Foundation, posted on their forum over a week ago. Not one reply?

It may be a case that they look at your post and think “Uh oh I don’t know the answer to this, better escalate it to an engineer” and… well escalating anything to an engineer is like tossing it into a black hole. It’ll radiate out at some point as a high-energy stream of information.

The datasheet isn’t much help: and neither is google, it seems.

I’ll give it another day or two then do something.
+9 C and nice clear blue skies today. A nice change from cold overcast rainy drizzly weather we’ve been having. Its supposed to go as high as 16 C tomorrow. =)

Hmm, this is interesting. Shining my LED flashlight on it does noting, but shining my older flashlight with an incandescent bulb in it lowers the reading. What’s missing from the light emitted from an LED, no UV maybe?

Google is saying white LED’s are Blue LED’s with extra phosphor. The plot thickens lol.

Replaced my BMP180 with a BME680 and I am now using it for my Temp, Humidity, and Pressure readings. It does not suffer from the same aversion to light as the sense hat humidity sensor. =)
I had been using the BMP180 mounted on the exterior of the case for temperature measurements. Heat given off by the Pi and sense hat throws off the readings of the sense hat temp sensor. It reads high due to hot air in the case.

1 Like