I want to display weather data from a BME680 on a Unicron Hat HD


#1

I am currently scrolling my weather info on a Sense Hat 8x8 RGB LED matrix. I want to switch to 16x16 RGB and use a BME680 for the readings. The BME680 part is already done, all I’m using on the Sense hat now is the LED matrix. My text changes color based on the values, blue text for temp if it 0c or lower for example. The message endlessly repeats day, date, time, temp, humidity, pressure, UV index.
Seeing as there is no Scroll Hat HD I went with the Unicron Hat HD. I did a forum search and saw one thread on displaying a variable on the Unicorn Hat HD. To be honest I was lost as to what was done and why. So I decided to start my own new thread. My current python code is as follows. Be warned, there is a lot going on.

import os
import time, datetime
import bme680
import SI1145.SI1145 as SI1145
import ledshim
import RPi.GPIO as GPIO
from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED

ledshim.set_clear_on_exit()
   
sense = SenseHat()
sense.set_rotation(180)
sense.set_imu_config(False, False, False)
sense.low_light = False

uvs = SI1145.SI1145()
sensor = bme680.BME680()

sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)

sensor.set_gas_status(bme680.DISABLE_GAS_MEAS)
#sensor.set_gas_heater_temperature(320)
#sensor.set_gas_heater_duration(150)
#sensor.select_gas_heater_profile(0)

GPIO.setmode(GPIO.BCM)  
GPIO.setwarnings(False)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_OFF)  

s=(0.1) # scroll speed
w=(0)   # color all white toggle
o=(140) # orange white toggle value
x=(2)   # shutdown variable
A=(1)   # Auto mode

def set_multiple_pixels(indexes, r, g, b):
    for index in indexes:
        ledshim.set_pixel(index, r, g, b)

def Shutdown(channel):  
    global x
    x = (0)

def readvis():
    vis = uvs.readVisible()
    vis = (round(vis))

    global w
    global o
    global A

    if vis < 270 and A == (1):
        sense.low_light = True
        ledshim.set_brightness(0.4)
        ledshim.show()
        w = (0)
        o = (140)
    elif vis >= 270 and vis < 650 and A == (1):
        sense.low_light = False
        ledshim.set_brightness(1.0)
        ledshim.show()
        w = (0)
        o = (140)
    elif vis >= 650 and A == (1):
        sense.low_light = False
        ledshim.set_brightness(1.0)
        ledshim.show()
        w = (255)
        o = (255)

def ledtemp():
    if sensor.get_sensor_data(): 
       t = (sensor.data.temperature) 
       t = (round(t))

    if t > 28: # Realy Hot 
        set_multiple_pixels(range(0,27), 255, 0, 0)   # Red
        set_multiple_pixels(range(27,28), 255,140, 0) # Orange
        M = (t - 56) * (-1)
        ledshim.set_pixel(M, 255, 255, 255)
        # R R R R R R R R R R R R R R R R R R R R R R R R R R R O
    elif t > 0 and t <= 28: # Main
        set_multiple_pixels(range(0,3), 255, 140, 0)   # Orange
        set_multiple_pixels(range(3,16), 0, 255, 0)    # Green
        set_multiple_pixels(range(16,28), 255, 255, 0) # Yellow
        M = (28 - t)
        ledshim.set_pixel(M, 255, 255, 255)
        # O O O G G G G G G G G G G G G G Y Y Y Y Y Y Y Y Y Y Y Y
    elif t <= 0 and t >= -27:
        ledshim.set_all(0, 0, 255) #Blue
        M = (t * (-1))
        ledshim.set_pixel(M, 255, 255, 255)
        # B B B B B B B B B B B B B B B B B B B B B B B B B B B B
    elif t > -27:
        set_multiple_pixels(range(0,3), 255, 255, 255) #Blue
        set_multiple_pixels(range(3,28), 0, 255, 255) #Aqua
        M = (56 + t)
        ledshim.set_pixel(M, 255, 255, 255)
        # B B B A A A A A A A A A A A A A A A A A A A A A A A A A
    
    ledshim.show()
        
# is really stick down
def pushed_up(event):
    global A
    if event.action == ACTION_PRESSED:
       sense.low_light = True
       ledshim.set_brightness(0.4)
       ledshim.show()
       A = (0)
        
# is really stick up
def pushed_down(event):
    global A
    if event.action == ACTION_PRESSED:
       sense.low_light = False
       ledshim.set_brightness(1.0)
       ledshim.show() 
       A = (0)

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

def pushed_middle(event):
    global A
    if event.action == ACTION_PRESSED:
        A = (1)

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

GPIO.add_event_detect(5, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)

while True:

    readvis()
    ledtemp()

    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))


    if sensor.get_sensor_data(): 
       t = (sensor.data.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 and t < 30:
        tc = [255, o, w]   # Orange
    elif t >= 30:
        tc = [255, w, w]   # Red   
            
    msg = "and %sc" % (t)
    sense.show_message(msg, scroll_speed=s, text_colour=tc)

    readvis()
    ledtemp()
    
    if sensor.get_sensor_data(): 
       h = (sensor.data.humidity)
       h = (round(h))

    if h < 0:
        h = 0

    if h > 100:
        h = 100

    if h < 30:
        hc = [255, w, w]    # Red
    elif h >= 30 and h <= 60:
        hc = [w, 255, w]    # Green
    elif h > 60 and h < 80:
        hc = [255, 255, w]  # Yellow
    elif h >= 80:
        hc = [255, w, w]    # Red

    msg = "with %s%% Humidity" % (h)
    sense.show_message(msg, scroll_speed=s, text_colour=hc)

    readvis()
    ledtemp()
    
    if sensor.get_sensor_data(): 
       p = (sensor.data.pressure) 
       p = round(p)
        
    if p > 0 and p < 982:
        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 >= 982 and p < 1004:
        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 >= 1004 and p < 1026:
        pc = [w, 255, w]    # Green
        msg = "- Barometer is Mid Range @ %smb" % (p)
        sense.show_message(msg, scroll_speed=s, text_colour=pc)
    elif p >= 1026 and p < 1048:
        pc = [w, w, 255]    # Blue
        msg = "- Barometer is High @ %smb" % (p)
        sense.show_message(msg, scroll_speed=s, text_colour=pc)
    elif p >= 1048:
        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)

    readvis()
    ledtemp()

    uv = uvs.readUV()
    u = uv/100
    u = (round(u))

    if u > 0 and u < 3:
        msg = "- UV Index is Low @ %s" % (u)
        sense.show_message(msg, scroll_speed=s, text_colour=(w, 255, w))   # Green        
    elif u >= 3 and u < 6:
        msg = "- UV Index is Moderate @ %s" % (u)
        sense.show_message(msg, scroll_speed=s, text_colour=(255, 255, w)) # Yellow        
    elif u >= 6 and u < 8:
        msg = "- UV Index is High @ %s" % (u)
        sense.show_message(msg, scroll_speed=s, text_colour=(255, o, w))   # Orange       
    elif u >= 8 and u < 11:
        msg = "- UV Index is Very High @ %s" % (u)
        sense.show_message(msg, scroll_speed=s, text_colour=(255, w ,w))   # Red
    elif u >= 11:
        msg = "- UV Index is Extreme @ %s" % (u)
        sense.show_message(msg, scroll_speed=s, text_colour=(255, w, 255)) # Violet
        
    #vis = uvs.readVisible()
    #vis = (round(vis)) 

    #msg = "and the VIS is %s" % (vis)
    #sense.show_message(msg, scroll_speed=s, text_colour=(255, w, 255))

    if x == 0:
        sense.clear()
        ledshim.clear()
        ledshim.show()
        os.system("sudo shutdown now -P")
        time.sleep(30)
    elif x == 1:
        sense.clear()
        ledshim.clear()
        ledshim.show()
        raise SystemExit
        time.sleep(30)

# Last edited on Sep 15th 2018, fixed typo 
# curl https://get.pimoroni.com/bme680 | bash
# curl https://get.pimoroni.com/ledshim | bash
# run sudo crontab -e
# add
# @reboot python3 /home/pi/BMELED.py &

All I want to do initially is display say the temperature, and get it to change color based on its value. If I can do that I should be able to just repeat it for the others.

Even just showing the day date time will be a step in the right direction. The example file just seemed overly complex for what I ant to do. I’m no python expert but I don’t consider myself a noob either. any help will be muchly appreciated.


#2

Whew, the text.py file is giving me a headache. Nicely done, just confusing for somebody like me, that isn’t a python expert.
Can anybody recommend a nice simple font? Something that draws the letters with single lines, if you now what I mean?
o o o o o o o o o o o o o o o o
o
o
o
o
o
o
o o o o o o o o
o
o
o
o
o
o
o