Playing around with my Pico Enviro+

Enviro+_Capture

I started with the all enviro_all_basic.py, not much of that left now. It was a good starting point though.
I tweaked the descriptors and added color coding based on the values of what they were describing.
It’s plugged into Pimoroni Pico Lipo 16mb, thus the Battery % display.
When on USB Power it displays “Charging”

Pressing B turns the backlight of and leaves it running in the background.
Pressing A turns the backlight back on.
Pressing X resets the min Max temperature.

Next mod is to setup auto backlight based on background light level.

import time
from machine import ADC, Pin
from picographics import PicoGraphics, DISPLAY_ENVIRO_PLUS
from pimoroni import RGBLED, Button
from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE
from pimoroni_i2c import PimoroniI2C
from breakout_ltr559 import BreakoutLTR559

display = PicoGraphics(display=DISPLAY_ENVIRO_PLUS, rotate=90)
display.set_font("bitmap8")
WIDTH, HEIGHT = display.get_bounds()
BRIGHTNESS = 0.8

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

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

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

vsys = ADC(29)
charging = Pin(24, Pin.IN)
conversion_factor = 3 * 3.3 / 65535

full_battery = 4.2
empty_battery = 2.8

bme = BreakoutBME68X(i2c, address=0x77)
ltr = BreakoutLTR559(i2c)

t_color = display.create_pen(0,255,0)
h_color = display.create_pen(0,255,0)
p_color = display.create_pen(0,255,0)
l_color = display.create_pen(0,255,0)
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)
grey = display.create_pen(120,120,120)
violet = display.create_pen(255,0,255)
cyan = display.create_pen(0,255,255)
magenta = display.create_pen(200, 0, 200)

def describe_temperature(temperature):
    global t_color
    if temperature < -10:
        description = "Very Cold"
        t_color = white
    elif -10 <= temperature <= 0:
        description = "Cold"
        t_color = blue
    elif 0 < temperature <= 12:
        description = "Cool"
        t_color = yellow
    elif 12 < temperature <= 16:
        description = "OK"
        t_color = green
    elif 16 < temperature <= 24:
        description = "Warm"
        t_color = green      
    elif 24 < temperature <= 27:
        description = "Hot"
        t_color = orange
    elif temperature > 27:
        description = "Very Hot"
        t_color = red
    return description

def describe_humidity(humidity):
    global h_color
    if humidity < 30:
        description = "Low"
        h_color = red
    elif 30 <= humidity <= 60:
        description = "OK"
        h_color = green
    elif 60 < humidity < 80:
        description = "High"
        h_color = yellow
    elif humidity >= 80:
        description = "Very High"
        h_color = orange        
    return description

def describe_pressure(pressure):
    global p_color
    if pressure < 982:
        description = "Very Low"
        p_color = red
    elif 982 <= pressure < 1004:
        description = "Low"
        p_color = yellow
    elif 1004 <= pressure < 1026:
        description = "OK"
        p_color = green
    elif 1026 <= pressure < 1048:
        description = "High"
        p_color = blue
    elif pressure >= 1048:
        description = "Very High"
        p_color = orange
    return description

def describe_light(lux):
    #lux += 0.5
    global l_color
    if lux < 50:
        description = "Dark"
        l_color = magenta
    elif 50 <= lux < 100:
        description = "Dim"
        l_color = cyan
    elif 100 <= lux < 500:
        description = "Light"
        l_color = yellow
    elif lux >= 500:
        description = "Bright"
        l_color = white
    return description

min_temperature = 100.0
max_temperature = 0.0

led.set_rgb(0, 0, 0)
display.set_backlight(BRIGHTNESS)
display.set_pen(black)
display.update()

# the gas sensor gives a few weird readings to start, lets discard them
temperature, pressure, humidity, gas, status, _, _ = bme.read()
time.sleep(0.5)
temperature, pressure, humidity, gas, status, _, _ = bme.read()
time.sleep(0.5)

while True:
    
    voltage = vsys.read_u16() * conversion_factor
    percentage = 100 * ((voltage - empty_battery) / (full_battery - empty_battery))
    if percentage > 100:
        percentage = 100    

    if button_a.is_pressed:
        display.set_backlight(BRIGHTNESS)
        time.sleep(0.2)
    elif button_b.is_pressed:
        display.set_backlight(0)
        time.sleep(0.2)
    elif button_x.is_pressed:
        min_temperature = 100.0
        max_temperature = 0.0
        display.set_backlight(BRIGHTNESS)
        time.sleep(0.2)
    elif button_y.is_pressed:
        display.set_backlight(BRIGHTNESS)
        time.sleep(0.2)

    temperature, pressure, humidity, gas, status, _, _ = bme.read()
    heater = "Stable" if status & STATUS_HEATER_STABLE else "Unstable"
        
    temperature = round(temperature)
         
    if temperature >= max_temperature:
        max_temperature = temperature
    if temperature <= min_temperature:
        min_temperature = temperature

    pressure = pressure / 100
    pressure = round(pressure)
        
    ltr_reading = ltr.get_reading()
    lux = ltr_reading[BreakoutLTR559.LUX]
    prox = ltr_reading[BreakoutLTR559.PROXIMITY]
        
    if heater == "Stable" and ltr_reading is not None:
        led.set_rgb(0, 0, 0)

        display.set_pen(black)
        display.clear()
                    
        display.set_pen(white)
        display.text(f"{temperature:.0f}°C", 0, 0, WIDTH, scale=4)
            
        describe_temperature(temperature)
        display.set_pen(t_color)
        display.text(describe_temperature(temperature), 90, 0, WIDTH, scale=4) 

        display.set_pen(cyan)
        display.text(f"Min {min_temperature:.0f}", 0, 35, WIDTH, scale=3)
        display.set_pen(cyan)
        display.text(f"Max {max_temperature:.0f}", 125, 35, WIDTH, scale=3)

        display.set_pen(white)
        display.text(f"{humidity:.0f}% RH", 0, 75, WIDTH, scale=4)
        display.text(f"{pressure:.0f}mb", 0, 120, WIDTH, scale=4)
        display.text("Light", 0, 165, WIDTH, scale=4)
        #display.text(f"{lux:.0f} lux", 0, 180, WIDTH, scale=4)

        describe_humidity(humidity)
        display.set_pen(h_color)
        display.text(f"{describe_humidity(humidity)}", 125, 81, WIDTH, scale=3)
        display.set_pen(p_color)
        describe_pressure(pressure)
        display.text(f"{describe_pressure(pressure)}", 125, 126, WIDTH, scale=3)
        describe_light(lux)
        display.set_pen(l_color)
        display.text(f"{describe_light(lux)}", 125, 171, WIDTH, scale=3)
        
        display.set_pen(blue)
        if charging.value() == 1:         # if it's plugged into USB power...
            display.text("Charging", 50, 210, WIDTH, scale=4)
            
        else:
            
            if percentage >= 50:
                display.set_pen(green)
                display.text("Battery", 0, 210, WIDTH, scale=4)
                display.text('{:.0f}%'.format(percentage), 155, 210, WIDTH, scale=4)                
            elif 50 > percentage > 20:   
                display.set_pen(yellow)
                display.text("Battery", 0, 220, WIDTH, scale=3)
                display.text('{:.0f}%'.format(percentage), 155, 220, WIDTH, scale=3)
                
            elif percentage <= 20:    
                display.set_pen(red)
                display.text("Battery", 0, 220, WIDTH, scale=3)
                display.text('{:.0f}%'.format(percentage), 155, 220, WIDTH, scale=3)
 
        display.update()
        time.sleep(0.5)