Need Help: Pico weather station guide using the Pico Explorer

@alphanumeric,Do you notice initial inaccurate values from the BME280 as you start up? I usually get high temperature and low pressure which usually corrects itself after a couple of loops. I’m running this on an Explorer with a BME280 plugged into the left breakout socket.

BME688 here at the moment, I’ll have to have a look and post back. On that note I had a BME280 in at one time and it always showed 87% humidity on start up, then updated to an actual value. Thats was why I swapped in my BME688.

Yes, BME280 returns a few trash readings before it settles down - I know the Enviro examples ignore the first few readings to get round this.

Not seeing anything weird on start up with my BME688. I have a bunch of BME280’s on the go here. They are running Enviro code on Raspberry Pi’s.
When I get a chance I’ll swap a 280 in place of my 688 and see what happens.

I found that my BME68xs were reading a couple of degrees warmer than the BME280 so they would probably benefit from some calibration/offsetting in code (makes sense, as the gas sensors include a heating element!).

Can you disable / turn off the heater / gas sensor?
Just swapped in my BME280. the barometric pressure starts off with a very low reading, 714 mb. I see a flash of red and then it updates to a correct value. If I wasn’t watching I wouldn’t see it.
This one has the address jumper cut so it took me a bit to figure out how to address it in the code.
bme = BreakoutBME280(i2c, 0x77)
My other BME280 did something similar but with the humidity, the first reading was always 87%. Same deal though, if I wasn’t watching when it started up I’d not see it.
I’m not seeing any gradual shifts, other than actual changes in temp etc from turning my heat on in the morning.

I just throw away the first few readings before starting to show the results.

I’m doing the same thing now. I get a nice clear all black screen for 2 seconds. Then it updates with good values.

    if time_elapsed < 2:
        temperature, pressure, humidity = bme.read()
        display.set_pen(black)
        display.clear()
        display.update()
    else:
        display.update()
        utime.sleep(1)
        display.set_pen(black)
        display.clear()

I’ve also added a display of the min and max temp reached. My full file is as follows.

# This file lets you make a little indoor weather station.

import utime

from breakout_bme280 import BreakoutBME280

from pimoroni_i2c import PimoroniI2C

from breakout_colourlcd240x240 import BreakoutColourLCD240x240

width = BreakoutColourLCD240x240.WIDTH
height = BreakoutColourLCD240x240.HEIGHT

display_buffer = bytearray(width * height * 2)  # 2-bytes per pixel (RGB565)
display = BreakoutColourLCD240x240(display_buffer, cs=(17), bl=(20))
display.set_backlight(1.0)

i2c = PimoroniI2C(sda=(4), scl=(5))
bme = BreakoutBME280(i2c)

# lets set up some pen colors to make drawing easier
tempcolor = display.create_pen(255, 255, 255)  # this colour will get changed in a bit
humidcolor = display.create_pen(255, 255, 255)  # this colour will get changed in a bit
presscolor = display.create_pen(255, 255, 255)  # this colour will get changed in a bit
white = display.create_pen(255, 255, 255)
black = display.create_pen(0, 0, 0)
red = display.create_pen(255, 0, 0)
green = display.create_pen(0, 255, 0)
blue = display.create_pen(0, 0, 255)
yellow = display.create_pen(255, 255, 0)
orange = display.create_pen(255, 140, 0)

# converts the temperature into a barometer-type description and pen colour
def describe_temperature(temperature):
    global tempcolor
    if temperature < 0:
        description = "very cold"
        tempcolor = blue
    elif 0 <= temperature < 14:
        description = "cold"
        tempcolor = yellow
    elif 14 <= temperature < 25:
        description = ""
        tempcolor = green
    elif 25 <= temperature < 30:
        description = "hot"
        tempcolor = orange
    elif temperature >= 30:
        description = "very hot"
        tempcolor = red
    else:
        description = ""
        tempcolor = black
    return description

# converts pressure into barometer-type description
def describe_pressure(pressure):
    global presscolor
    if pressure < 982:
        description = "stormy"
        presscolor = red
    elif 982 <= pressure < 1004:
        description = "precip"
        presscolor = yellow
    elif 1004 <= pressure < 1026:
        description = "change"
        presscolor = green
    elif 1026 <= pressure < 1048:
        description = "fair"
        presscolor = blue
    elif pressure >= 1048:
        description = "dry"
        presscolor = orange
    else:
        description = ""
        presscolor = black
    return description


# converts humidity into good/bad description
def describe_humidity(humidity):
    global humidcolor
    if humidity < 30:
        description = "dry"
        humidcolor = orange
    elif 30 <= humidity < 61:
        description = ""
        humidcolor = green
    elif 61 <= humidity < 81:
        description = "humid"
        humidcolor = yellow
    elif humidity >= 81:
        description = "very humid"
        humidcolor = red        
    else:
        description = ""
        humidcolor = black        
    return description

min_temp = None
max_temp = None

start_time = utime.time()

while True:
    
    time_elapsed = utime.time() - start_time
    
    # read the sensors
    temperature, pressure, humidity = bme.read()
            
    # pressure comes in pascals which is a reight long number, lets convert it to the more manageable mb
    pressuremb = pressure / 100
    
    # draw a thermometer/barometer thingy
    display.set_pen(125, 125, 125)
    display.circle(190, 190, 40)
    display.rectangle(180, 45, 20, 140)

    # switch to red to draw the 'mercury'
    display.set_pen(red)
    display.circle(190, 190, 30)
    thermometerheight = int(120 / 30 * temperature)
    if thermometerheight > 120:
        thermometerheight = 120
    if thermometerheight < 1:
        thermometerheight = 1
    display.rectangle(186, 50 + 120 - thermometerheight, 10, thermometerheight)

    # drawing the pressure text
    display.set_pen(presscolor)
    display.text('{:.0f}'.format(pressuremb) + 'mb', 10, 10, 240, 5)
    display.set_pen(white)
    display.text(describe_pressure(pressuremb), 10, 40, 240, 3)
        
    # and the humidity text
    display.set_pen(humidcolor)
    display.text('{:.0f}'.format(humidity) + '%', 10, 90, 240, 5)
    display.set_pen(white)
    display.text(describe_humidity(humidity), 10, 120, 240, 3)
        
    # and the temperature text
    display.set_pen(tempcolor)
    display.text('{:.0f}'.format(temperature) + '`c', 10, 170, 240, 5)
    display.set_pen(white)
    display.text(describe_temperature(temperature), 10, 200, 240, 3)

    if time_elapsed > 30:
        if min_temp is not None and max_temp is not None:
            if temperature < min_temp:
                min_temp = int(temperature)
            elif temperature > max_temp:
                max_temp = int(temperature)
        else:
            min_temp = int(temperature)
            max_temp = int(temperature)
            
    if min_temp is not None and max_temp is not None:
        min_string = ('{:.0f}'.format(min_temp))
        max_string = ('{:.0f}'.format(max_temp))
        range_string = (min_string) + ' - ' + (max_string)
    else:
        range_string = ""            
        
    display.set_pen(white)
    display.text(range_string, 10, 220, 240, 3)
           
    # time to update the display
    if time_elapsed < 1:
        temperature, pressure, humidity = bme.read()
        #temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read()
        display.set_pen(black)
        display.clear()
        display.update()
    else:
        display.update()
        utime.sleep(1)
        display.set_pen(black)
        display.clear()