Need Help: Pico weather station guide using the Pico Explorer

The examples are linked to from the product pages. It’s just bold text though and easy enough to miss. Hover your mouse over the bold text and any that are links will become underlined, and clickable. ;)

If you have a Raspberry Pi setup with a Monitor and keyboard you can run Thonny from it. I’m doing my PICO programing from my Pi400.

You can use Mu Editor with MicroPython. It will auto detect.

Code With Mu

Hi,
is the code available, that produces the output shown in the explorer product picture?
I didn’t find it anywhere.
Thnx
Thomas

Last time I had a look see it wasn’t there. I’m wanting to replicate it but don’t currently have the skills to do it.

Getting there - my next project.
Now I have a reliable BME280 driver to provide the values in MicroPython I’ll have a go at the graphics. However, the font used on the advert is not the one in the Explorer screen driver!

1 Like

I no longer have my Pico Explorer Base, but I do have a Pico Breakout Garden Base, BME280, and that display as a breakout. Running the code on that should be easy peasy.
Looking forward to what you come up with. =)

I’ve added a little MicroPython weather station example for Pico Explorer.

BME280 flavour
BME68x flavour

It doesn’t look exactly like the photo on the shop page (CircuitPython and DisplayIO are probably the way to go if you want icons and backgrounds) but it does have an optional Yorkshire mode :D

2 Likes

Just ran the BME688 version on my equivalent Breakout Garden setup. Just two minor edits for me. The PINS_BREAKOUT_GARDEN and changed hpa to mb.
Big thumbs up to @hel

1 Like

Haha - just peeked at the code for “Yorkshire mode” 😂

1 Like

I’m liking this a lot. On my PICO Breakout Garden Pack the display is standing up facing me. I have it sitting on my computer desk and plugged into my PC’s USB port. It’s only on when the PC is on, which works out very well for me. I have other similar Pi based weather displays about the house.
Long story made short, when I get up in the wee hours of the morning and fire up my PC its on and I can have a quick look see and decide if I’m going to turn the heat on now or wait till my wife gets up a few hours latter. And when I turn the PC off its off and the room is nice and dark again. My dogs bed is in this room and she likes it nice and dark at night.

I’ve added color options to the Humidity and Pressure readings. I also tweaked some settings to match what I use on other Weather setups I have here at home. The pressure bands mostly. For me its a BME688 on a Breakout Garden base. It shouldn’t be too hard to see what I did and modify your existing file if you wish.
I just built on top of Hel’s awesome code.

# This example lets you plug a BME680 or BME688 breakout into your Pico Explorer to make a little indoor weather station, with barometer style descriptions.

import utime

from breakout_bme68x import BreakoutBME68X
from pimoroni_i2c import PimoroniI2C

# Pico Explorer boilerplate
import picoexplorer as display
width = display.get_width()
height = display.get_height()
display_buffer = bytearray(width * height * 2)
display.init(display_buffer)

PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}

i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
bme = BreakoutBME68X(i2c)

# lets set up some pen colours to make drawing easier
tempcolour = display.create_pen(255, 255, 255)  # this colour will get changed in a bit
humidcolour = display.create_pen(255, 255, 255)  # this colour will get changed in a bit
presscolour = 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)


# converts the temperature into a barometer-type description and pen colour
def describe_temperature(temperature):
    global tempcolour
    if temperature < 0:
        description = "very cold"
        tempcolour = display.create_pen(0, 0, 255)
    elif 0 <= temperature < 20:
        description = "cold"
        tempcolour = display.create_pen(255, 255, 0)
    elif 13 <= temperature < 25:
        description = "temperate"
        tempcolour = display.create_pen(0, 255, 0)
    elif 25 <= temperature < 30:
        description = "hot"
        tempcolour = display.create_pen(255, 140, 0)
    elif temperature >= 30:
        description = "very hot"
        tempcolour = display.create_pen(255, 0, 0)
    else:
        description = ""
        tempcolour = display.create_pen(0, 0, 0)
    return description

# converts pressure into barometer-type description
def describe_pressure(pressure):
    global presscolour
    if pressure < 982:
        description = "storm"
        presscolour = display.create_pen(255, 0, 0)
    elif 982 <= pressure < 1004:
        description = "rain"
        presscolour = display.create_pen(255, 255, 0)
    elif 1004 <= pressure < 1026:
        description = "change"
        presscolour = display.create_pen(0, 255, 0)
    elif 1026 <= pressure < 1048:
        description = "fair"
        presscolour = display.create_pen(0, 0, 255)
    elif pressure >= 1048:
        description = "dry"
        presscolour = display.create_pen(255, 140, 0)
    else:
        description = ""
        presscolour = display.create_pen(0, 0, 0)
    return description


# converts humidity into good/bad description
def describe_humidity(humidity):
    global humidcolour
    if humidity < 30:
        description = "dry"
        humidcolour = display.create_pen(255, 0, 0)
    elif 30 <= humidity <= 60:
        description = "good"
        humidcolour = display.create_pen(0, 255, 0)
    elif humidity > 60:
        description = "humid"
        humidcolour = display.create_pen(255, 140, 0)
    return description


while True:
    # read the sensors
    temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read()

    # pressure comes in pascals which is a reight long number, lets convert it to the more manageable hPa
    pressurehpa = 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 temperature text
    display.set_pen(white)
    display.text("temperature:", 10, 10, 240, 3)
    display.set_pen(tempcolour)
    display.text('{:.1f}'.format(temperature) + 'C', 10, 30, 240, 5)
    display.set_pen(white)
    display.text(describe_temperature(temperature), 10, 60, 240, 3)

    # and the pressure text
    display.set_pen(white)
    display.text("pressure:", 10, 90, 240, 3)
    display.set_pen(presscolour)
    display.text('{:.0f}'.format(pressurehpa) + 'mb', 10, 110, 240, 5)
    display.set_pen(white)
    display.text(describe_pressure(pressurehpa), 10, 140, 240, 3)

    # and the humidity text
    display.set_pen(white)
    display.text("humidity:", 10, 170, 240, 3)
    display.set_pen(humidcolour)
    display.text('{:.0f}'.format(humidity) + '%', 10, 190, 240, 5)
    display.set_pen(white)
    display.text(describe_humidity(humidity), 10, 220, 240, 3)

    # time to update the display
    display.update()

    # waits for 1 second and clears to black
    utime.sleep(1)
    display.set_pen(black)
    display.clear()
1 Like

You can do the backgrounds and photographs in MicroPython on an Explorer. It just requires a bit of file conversion before you Blit the screen buffer.

Met this little guy in Sri Lanka!

This is how to do it.
I just followed the instructions here and adjusted the code to my own requirements:

http://www.penguintutor.com/program…/picodisplayanimations

You take a JPG photograph, crop to screen shape, reduce the pixel count to those of your screen and save as PNG. I used Photoshop but free GIMP will do the job.

In Python convert the PNG to a 2-byte colour RAW without the A information.

Use rshell to copy the RAW file to the Pico and push the data from the file into the screen buffer.

It is rather slow but the end result is vivid.

1 Like

Here we have gradient a background, icons and lower case letters using Micropython. Just needed a bit of time and thought. The icons are easy to re-position. Hope you like it.

Having a bit of trouble with high temperature and and lower pressure readings from the BME280 at the moment - using @Hel’s code ?? May try a different driver.

Will write up as an Instructable when I’ve finished it.

2 Likes

@Tonygo2 I kind of like that nice clean look. I’m not knocking Hel’s code, a lot of this is personal choice, so options on how you go are nice.
I kept the original file and just removed the captions. Remarked them out for now, easy to put back in latter if i change my mind. ; ) And the descriptors only show up if things are outside the normal range.

@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!).