alphanumeric
Posts: 2100
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Two sense hats that ocasionally show over 100% humidity.

Mon Aug 07, 2017 12:07 pm

I have two sense hats that occasionally show over 100% humidity readings. It happens when the humidity is high, over 90%. Sometimes they read fine, then sometimes they read 114% etc? Condensation on the sensor maybe? I don't think it my code.

Code: Select all

import os
import time, datetime
from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
        
sense = SenseHat()
sense.set_rotation(180)
sense.set_imu_config(False, False, False)
sense.low_light = False

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" % (datetime.datetime.now().strftime(dateString))
    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 <= 27:
        tc = [w, 255, w]  # green
    elif t > 27:
        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 >= 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)
    else:
        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 < 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 @ %sm - Posible Percipitationb" % (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

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Two sense hats that ocasionally show over 100% humidity.

Thu Aug 10, 2017 8:29 am

This is a known bug in the firmware, it's not your code. It can also vary slightly between different Sense HATs.
My recommendation is to clamp the sensor measurement to 100, like so:

Code: Select all

h = sense.get_humidity()
h = round(h)
if h > 100:
    h = 100
I hope this helps.

alphanumeric
Posts: 2100
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Two sense hats that ocasionally show over 100% humidity.

Thu Aug 10, 2017 9:24 am

Ok, that's nice to know, I guess, lol. << Not laughing at you, by the way. It's just a bit funny it shows that your under water. I like your solution. I might use 99 instead of 100 though. Thanks for the reply.

Return to “Astro Pi”