Need Help: Pico weather station guide using the Pico Explorer

/ new user here, I hope this is the right place for this post /

Hello,
Since I can’t seem to find one, I would like to create a guide to help new Pico Explorer users create a weather station with their Pico Explorer. Similar to the one on the Pico Explorer Pimoroni shop page:

However, I’m not quite sure where to start myself. What I’m looking for is a basic guide to the OLED display and I think I can work it out from there. There is a decent demo for getting a temperature readout on the Explorer’s display, but not one for the display itself.

Any help would be greatly appreciated.

This might help, @Tonygo2 is a member of this forum.
Raspberry Pi Pico & Pico Explorer Workout : 15 Steps - Instructables
Pimoroni Pico Display Workout : 3 Steps - Instructables

Hi Jason
The graphics are the easy bit with MicroPython if you follow my guides. The problem is with the sensors and lack of driver modules. You can easily read temperatures with a DS18B20

import machine, onewire, ds18x20, time

ds_pin = machine.Pin(1)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))

roms = ds_sensor.scan()
print('Found DS devices: ', roms)

while True:
  ds_sensor.convert_temp()
  time.sleep_ms(750)
  for rom in roms:
    print(rom)
    print(ds_sensor.read_temp(rom))
  time.sleep(5)

which might get you started.

You might find my Pico review helpful in understanding some of the current problems:
Raspberry Pi Pico - Review | element14 | RoadTests & Reviews

Thanks Tony, I’ll be getting into this too. Once my Pico Explorer arrives, which should be any day now. I should have it early next week, it’s coming by snail mail.

Thanks Tony! I’ll look into each of your guides.

Took me a couple of long nights to troubleshoot then completely give up on Thonny. Running anything in the 3.3 range crashes my Mac Pro, 3.1 will start but then crash as soon as I open the preferences window??? Any way, I’ve given up and am using VS Code which is not as simple as Thonny, but does work. Not sure how well I can write a guide without Thonny working :(

I also found the examples on the Pimoroni Github page…not sure how I missed that in my Googling the first time around.

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.