Pico Enviro+ Pack Micropython drivers

I’ve just ordered a Pico Enviro+ Pack and cannot find the Micropython drivers or examples for the sensors.
Can someone tell me where to find them?
Thanks

I’m guessing the individual sensors will be fine with the existing drivers (BME688, LTR-559) and the screen will talk to the new PicoGraphics stuff.

They probably wanted to announce it before pushing explicit examples for it into github though :)

What he said. You’ll just have to figure out what pins were used for i2c and SPI.
I added a BME280 to my Tufty for weather info. My py file just uses Pico Graphics and the Micro Python library that’s already in the Pimoroni uf2 file.

Where can I download the Micropython drivers for BME688 and LTR-559?

They are included in the Pimoroni uf2 file. Other than soldering on my BME280, all I had to do was save my micro python file to my Tufty. Same deal with my weather station Pico Lipo setup. All the required libraries were in the custom Pimoroni uf2 file.

This maybe what your looking for, example file wise?
pimoroni-pico/micropython/examples/pico_enviro at main · pimoroni/pimoroni-pico (github.com)

1 Like

Thanks - that’s what I wanted. Just waiting for the post now.

I downloaded the BME680 example. I’m in the process of editing it to run with a BME280 on my Tufty. That’s the plan anyway. I want to see if I can get it to work and display the graphs.

Ahh, I’m always caught out by the micropython examples being under micropython and not examples :-)

I can’t get that example to work with my BME280?
Pressure always reads 71421.22Pa? Temp and Humidity are fine though?

EDIT: I got it to work, I needed to add a time sleep. The BME280 wasn’t getting a chance to update. It was being polled to quickly it seems. Also switched the Pa to mb for pressure. And switched the order to temp, humidity then pressure. Not the graph I was hoping for but usable anyway.

'''
Pimoroni Tufty 2040
BME280
'''
import utime
import picographics

from breakout_bme280 import BreakoutBME280
from pimoroni_i2c import PimoroniI2C

from picographics import PicoGraphics, DISPLAY_TUFTY_2040, PEN_RGB332

display = PicoGraphics(display=DISPLAY_TUFTY_2040, rotate=180, pen_type=PEN_RGB332)
display.set_backlight(1.0)
display.set_font("bitmap8") 

PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)

bme = BreakoutBME280(i2c,0x77)

BG = display.create_pen(0, 0, 0)
TEXT = display.create_pen(255, 255, 255)
TEMP = display.create_pen(255, 0, 0)
PRESS = display.create_pen(255, 255, 0)
HUMID = display.create_pen(0, 255, 0)

start_time = utime.time()

display.set_pen(BG)
display.clear()


def draw_graph(temp_value, press_value, humid_value):
    scaled_temp = int(temperature + 40)  # Range from -40 to +60 = 1-100
    scaled_press = int((pressure - 87000) / ((108400 - 87000) / 100))  # Range 108400 - 87000 = 1 -100
    scaled_humid = int(humidity)  # Range 1 - 100
    display.set_pen(BG)
    display.clear()
    display.set_pen(TEMP)
    display.rectangle(0, 60, scaled_temp, 60)
    display.text("TEMP: {:0.2f}c".format(temperature), scaled_temp + 5, 80, scale=2)
    display.set_pen(PRESS)
    display.text("PRESS: {:0.2f}mb".format(pressuremb), scaled_press + 5, 200, scale=2)
    display.rectangle(0, 180, scaled_press, 60)
    display.set_pen(HUMID)
    display.text("HUMID: {:0.2f}%".format(humidity), scaled_humid + 5, 140, scale=2)
    display.rectangle(0, 120, scaled_humid, 60)
    display.set_pen(TEXT)
    display.text("BME280 Enviro Sensor", 5, 10, scale=2)
    display.update()


while True:

    temperature, pressure, humidity = bme.read() 
    pressuremb = pressure / 100      
    draw_graph(temperature, pressure, humidity)
    print("{:0.2f}c, {:0.2f}mb, {:0.2f}%".format(
        temperature, pressuremb, humidity))
    utime.sleep (1)

Kevin’s doing some nifty stuff with little graphs and MicroPython at the moment - might be worth taking a look if you’ve not seen that already! - https://twitter.com/kevsmac/status/1539251210947010562

I think we sent him home with a Pico Enviro+ Pack yesterday, so maybe we’ll see some videos about it soon :)

Something like this, is what I’m interested in.

I don’t have the skills to do it myself though. =(

This is what I ended up with on my Tufty after tinkering with the Pico Enviro Example.

1 Like

Light level graphing on Tufty 2040

# Tufty Light graph on Tufty 2040
# Tony Goodhew 28th June 2022
# Uses a fixed length FIFO buffer for current display points
from machine import ADC, Pin
import utime
from pimoroni import Button

from picographics import PicoGraphics, DISPLAY_TUFTY_2040
# Setup display
display = PicoGraphics(display=DISPLAY_TUFTY_2040)
display.set_backlight(1.0)

# Setup buttons
button_b = Button(8, invert=False)
button_c = Button(9, invert=False)

# Create some colours
white = display.create_pen(200, 200, 255)
black = display.create_pen(0, 0, 0)
red = display.create_pen(255, 0, 0)
blue = display.create_pen(0 ,0, 255)
yellow = display.create_pen(255, 255 ,0)
green = display.create_pen(0, 255,0)

# Setup light sensor
lux_pwr = Pin(27, Pin.OUT)
lux_pwr.value(1) # Turn on power!
lux = ADC(26)

# Expose LUX sensor to max and min light levels
display.set_pen(black)
display.clear()
display.set_pen(green)
display.text("Expose LUX sensor to max and min light levels and then press button B",20,50,280)
display.update()

maxx = 0
total = 0
count = 0
running = True
while running:
    if button_b.is_pressed:
        running = False
    reading = lux.read_u16()
    if reading > maxx: maxx = reading
    total = total + reading
    count = count + 1
    utime.sleep(0.02)
print(maxx, total/count)
maxx = int(maxx * 1.1)
minn = 400
r =maxx-minn

display.set_pen(black)
display.clear()
display.set_pen(red)
display.text("Press button C to halt",20,50,280)
display.update()
utime.sleep(1.5)

# Create graph FIFO buffer for graph points
list = [] # List of light values
for i in range(320): # width of screen
    list.append(-99) # off screen value - not plotted
    
display.set_pen(red)
display.text("Light level graph",70,5)
display.set_clip(0, 20, 320, 220) # Protect heading
running = True
while running:
    if button_c.is_pressed:
        running = False
    percent = int( (lux.read_u16() - minn) *100 /r)
#    print(percent)
    out = list.pop(0)       # Remove first element of queue
    list.append(percent)    # Add new queue element on end of queue  
    display.set_pen(black)
    display.rectangle(0, 20, 320, 220)
    display.set_pen(green)  # Graphing pen colour
    for i in range(320):
        display.pixel(i, int((150-list[i])*1.5))
    display.update()

# Tidy-up
lux_pwr.value(0) # Turn off power to sensor!
display.set_pen(black)
display.remove_clip()
display.clear()
display.update()

Give it a try
Cover the sensor and then shine a bright torch at the sensor before you press the button.

1 Like

Thanks Tony, I will definitely be giving that a try.

Should be easy to convert to Pico Enviro+.
I’ve been having a problem with the RGB LED. The BLUE component appears to stuck on pale blue. I cannot change its intensity or turn it off.

If you have a pico enviro+ please see if yours is working as we would expect.

# This example shows you a simple, non-interrupt way of reading Pico Enviro's buttons with a loop that checks to see if buttons are pressed.
# Modified by Tony Goodhew 2 2022 to show BLUE stuck on pale blue
import time
from pimoroni import Button
from picographics import PicoGraphics, DISPLAY_ENVIRO_PLUS
from pimoroni import RGBLED
display = PicoGraphics(display=DISPLAY_ENVIRO_PLUS)

button_a = Button(12, invert=True)
button_b = Button(13, invert=True)
button_x = Button(14, invert=True)
button_y = Button(15, invert=True)


WHITE = display.create_pen(255, 255, 255)
BLACK = display.create_pen(0, 0, 0)
TEAL = display.create_pen(0, 255, 255)
MAGENTA = display.create_pen(255, 0, 255)
YELLOW = display.create_pen(255, 255, 0)
RED = display.create_pen(255, 0, 0)
GREEN = display.create_pen(0, 255, 0)
BLUE = display.create_pen(0, 0, 255)

led = RGBLED(6, 7, 8, invert=True)  # setting pins for the RGB led
led.set_rgb(0,0,0)

WIDTH, HEIGHT = display.get_bounds()

while True:
    if button_a.is_pressed:                               # if a button press is detected then...
        display.set_pen(BLACK)                            # set pen to black
        display.clear()                                   # clear display to the pen colour
        display.set_pen(RED)                            # change the pen colour
        display.text("Button A pressed LED RED and pale blue", 10, 10, WIDTH - 10, 3)  # display some text on the screen
        display.update()                                 # update the display
        led.set_rgb(100, 0, 0)
        time.sleep(1)                                    # pause for a sec

    elif button_b.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(BLUE)
        display.text("Button B pressed LED BLUE but too pale", 10, 10, WIDTH - 10, 3)
        display.update()
        led.set_rgb(0, 0,100)
        time.sleep(1)

    elif button_x.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(GREEN)
        display.text("Button X pressed LED GREEN with pale blue", 10, 10, WIDTH - 10, 3)
        display.update()
        led.set_rgb(0, 100, 0)
        time.sleep(1)

    elif button_y.is_pressed:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(WHITE)
        display.text("Button Y pressed LED OFF BUT IT IS BLUE", 10, 10, WIDTH - 10, 3)
        display.update()
        led.set_rgb(0, 0, 0)
        time.sleep(1)

    else:
        display.set_pen(BLACK)
        display.clear()
        display.set_pen(RED)
        display.text("Press any button!", 10, 10, WIDTH, 3)
        display.update()

    time.sleep(0.1)  # this number is how frequently the pico checks for button presses


Stuckblue sm

No Pico Enviro, just a Tufty and Display Pack.
The LED is working OK on my Display Pack with the code I’ve tried so far.
I’ve had a similar issue on a RGB Keypad. One LED had one color always on at a low intensity. I ended up getting it replaced.

@Tonygo2 Just plugged in an Enviro+ Pack and got the same with the always on blue element - looks like the examples have the wrong LED pins, it should be:

led = RGBLED(6, 7, 10, invert=True)

not

led = RGBLED(6, 7, 8, invert=True)

I’ll fix the examples, sorry about that!

Thank you - That is a FIX!
Sorry for delay in testing - I’ve been away.

1 Like