ScrollPhat HD query

What I do on my sense hat is get the value just before I show it in the message. Then wash rinse and repeat.

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

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

    p = sense.get_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)
        

For me, the next message won’t start until the current one ends. They just run one after the other, and being in the while true just endlessly repeats them. When it gets to the end of the last one, it starts over again from the top. My individual readings are taken right before the first if statement.

It scrolls forever, and changes with the sensor. Both are good, just what I want it to do.

Yes, it stops when I ctrl+c

I’ll try this. Thank you.

So when you add the second message, all you see is the second message?
I’m not exactly sure I understand what the issue is after reading your last post?

Apologies for the confusion.
When the second sensor reading is displayed, it’s jumbled on top of the previous message, hence the clear between the two.

I’m giving the elif a go now and will let you know how it goes.

Thanks for your help and ideas so far.

Ah, OK, now I know what’s going on. The two messages are scrolling on the display at the same time.
One on top of the other giving you gibberish.

Yes, exactly that! :)

import time
import sys
from envirophat import light, motion, weather
import scrollphathd
from scrollphathd.fonts import font5x7

str_len = 0
scroll_x = 0

while True:

    hding = motion.heading()
    temperature = weather.temperature()
    lux = light.light()
    rgb = str(light.rgb())[1:-1].replace(' ', '')
        
    scrollphathd.set_brightness(0.2)
    scrollphathd.clear()

 if lux <= 100 :
        str_len = scrollphathd.write_string(("Too dark!  "), x=0, y=0, font=font5x7)
    elif lux > 100 :
        str_len = scrollphathd.write_string(("Too bright!  "), x=0, y=0, font=font5x7)

    scrollphathd.clear() 
    
    if hding <= 200 :    
        str_len = scrollphathd.write_string(("Closed"), x=0, y=0, font=font5x7) 
    elif hding > 200 :    
        str_len = scrollphathd.write_string(("Open"), x=0, y=0, font=font5x7)

    scrollphathd.scroll_to(scroll_x, 0)
    scrollphathd.show()
    time.sleep(0.01)
    scroll_x += 1
    if scroll_x >= str_len:
        scroll_x = 0

Without the .clear, it shows garbled text
With the .clear, it shows just the second if/elif loop

You might have to get creative and merge it into the one message

if lux <+ 100 and hding <= 200:
str_len = scrollphathd.write_string((“Too dark! - Closed”), x=0, y=0, font=font5x7)
if lux <+100 and hding >200:
str_len = scrollphathd.write_string((“Too dark! - Open”), x=0, y=0, font=font5x7)
etc

This seems to work OK:


    if lux <= 100 and hding <=200 :
        str_len = scrollphathd.write_string("Too dark & door closed Temp/%.1fC  "%(temperature), x=0, y=0, font=font5x7)
    elif lux <= 100 and hding >200:
        str_len = scrollphathd.write_string("Too dark & door open Temp/%.1fC  "%(temperature), x=0, y=0, font=font5x7)        
    elif lux > 100 and hding >200:
        str_len = scrollphathd.write_string("Too bright & door open Temp/%.1fC  "%(temperature), x=0, y=0, font=font5x7)
    elif lux > 100 and hding <200:
        str_len = scrollphathd.write_string("Too bright & door closed Temp/%.1fC  "%(temperature), x=0, y=0, font=font5x7)
        

Probably not the most tidy or efficient way to achieve the result I want, but it’ll do for me, for now anyway.
I can amuse myself for hours building dozens of elif permutations!

Thanks!

Sometimes you just have to go with what works.
In your case, one command stores the message (write_string) in memory, then another command tells the scroll hat to display it. (scrol_to, scroll.show, etc) You were storing twice (one on top of the other) but showing once, near as I can tell anyway.

I likely have a bunch of code that would give somebody with real python skills a headache. But you know what, it works. It does exactly what I want it to do. There may be a better way, but I’m not going to lose any sleep over how I did it. My code has lots of elif’s in it. Have a look at the PortWC.py file here lol.
https://1drv.ms/f/s!AjOYwiwlwDtpgsVkNRFKrcQ8HARM0Q

Another way to “maybe” do it is have a second scroll.show etc right after that scrollphat.clear you have between the two messages.
Save the first message in memory.
display it
clear it
store the second message in memory
display it
clear it.
wash rinse and repeat.
If it only shows each massage “once” it should work.

Now that’s an Impressive project!
I’m just trying to find a a way to tell if an up-n-over garage door is open or closed.
Envirophat ‘heading’ seems ideal, the other lux, temperature etc sensors are just nice to haves.

I was wondering what the open closed was all about lol. =) A relay wired to a GPIO pin would likely work. Or a light beam sensor. Beam broken door closed. Or what your doing now.;)
The lux sensor will tell you if somebody left the light on. ;)

I have a SI1145 light sensor on that portable weather clock. On the top of the case under a clear cover. I use the ambient light level to set my display brightness. In a dark room the LED shim is set to half brightness and the sense hat led matrix is set to half bright ness. It makes it easier on the eyes to read it and it doesn’t overpower the room with glaring colored lights.
In normal sunlight they both go to full bright. And in very bright sunlight I change the text color on the sense hat led matrix to all white, regardless of any other conditions. I find Blue and Red text hard to read in bright sunlight. I have partial color blindness. And I’m getting old lol. I also get the UV index from the Si1145.
The sense hat temp sensor doesn’t like being in an enclosed space and reads high due to heat given off by the Pi’s CPU. I added a BME680 mounted externally to get accurate readings. Its mounted on the outside bottom of the case out of direct sunlight and out of the weather, rain etc. Fresh air can get at it though.
It’s portable and headless, running off of a powerboost 1000c and 6600 MAH LIPO battery. It also has DS3231 RTC wired in so it can keep accurate time with no WIFI connection. Its a Pi A+ with no WIFI adapter.

My next planed modification is to replace the sense hat with a Unicorn Hat HD. All I’m using on the sense hat now is the 8x8 LED matrix. 16x16 would be a nice upgrade. I have a Unicorn Hat HD here, just having trouble figuring out how to scroll my messages on it. Not as easy as I thought it would be.

I built it to take out on my deck in the summer and to our dog park. Its nice to get real time temps etc so we can make sure the dogs get enough water and don’t get overheated.

Most of my Pi projects pictures are here if you want to have a look see.
https://1drv.ms/f/s!AjOYwiwlwDtpgUMsp2qnevKpGEHb