Thanks for helping @alphanumeric @hel
Below is the code.
pico + uf2 v.1.19
Breakout Garden Base
1.54" breakout LCD 240X240
BME688 4in1 breakout sensor
'''
pimoroni-pico-v1.19.0-micropython
pico breakout garden base
1.54" 240x240 color LCD breakout
BME6884in1 breakout
'''
import utime
import picographics
from breakout_bme68x import BreakoutBME68X
from pimoroni_i2c import PimoroniI2C
from picographics import PicoGraphics, DISPLAY_LCD_240X240, PEN_RGB332
display = PicoGraphics(display=DISPLAY_LCD_240X240, rotate=0, pen_type=PEN_RGB332)
display.set_backlight(0.5)
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
bme = BreakoutBME68X(i2c)
grey = display.create_pen(120, 120, 120)
violet = display.create_pen(255, 0, 255)
# lets set up some pen colors to make drawing easier
tempcolor = display.create_pen(0, 255, 0) # this colour will get changed in a bit
humidcolor = display.create_pen(0, 255, 0) # this colour will get changed in a bit
presscolor = display.create_pen(0, 255, 0) # 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 description and pen colour
def describe_temperature(temperature):
global tempcolor
if temperature < 0:
description = "very cold"
tempcolor = blue
elif 0 <= temperature < 12:
description = "cold"
tempcolor = yellow
elif 12 <= temperature < 17:
description = "cool"
tempcolor = green
elif 17 <= temperature < 25:
description = "warm"
tempcolor = green
elif 25 <= temperature < 30:
description = "hot"
tempcolor = orange
elif temperature >= 30:
description = "very hot"
tempcolor = red
else:
description = ""
tempcolor = black
return description
min_temp = None
max_temp = None
# converts humidity into good/bad description and pen color
def describe_humidity(humidity):
global humidcolor
if humidity < 30:
description = "low dry"
humidcolor = orange
elif 30 <= humidity < 61:
description = "ok"
humidcolor = green
elif 61 <= humidity < 81:
description = "high"
humidcolor = yellow
elif humidity >= 81:
description = "very high"
humidcolor = red
else:
description = ""
humidcolor = black
return description
# converts pressure into barometer-type description and pen color
def describe_pressure(pressure):
global presscolor
if pressure < 982:
description = "very low"
presscolor = red
elif 982 <= pressure < 1004:
description = "low"
presscolor = yellow
elif 1004 <= pressure < 1026:
description = "unsettled"
presscolor = green
elif 1026 <= pressure < 1048:
description = "high"
presscolor = blue
elif pressure >= 1048:
description = "very high"
presscolor = orange
else:
description = ""
presscolor = black
return description
start_time = utime.time()
while True:
time_elapsed = utime.time() - start_time
# read the sensors
temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read()
# convert pressure to mb
pressuremb = pressure / 100
# draw a barometer
display.set_pen(grey)
display.circle(200, 190, 20)
display.rectangle(190, 14, 23, 160)
display.set_pen(presscolor)
display.circle(200, 190, 10)
barometerheight = int((pressuremb - 960) * 1.4)
if barometerheight > 150:
barometerheight = 150
if barometerheight < 1:
barometerheight = 1
display.rectangle(196, 60 + 120 - barometerheight, 10, barometerheight)
# drawing the pressure reading
display.set_pen(presscolor)
display.text('{:.0f}'.format(pressuremb) + 'mb', 10, 140, 240, 5)
display.set_pen(white)
display.text(describe_pressure(pressuremb), 10, 170, 240, 3)
display.set_pen(white)
# and the humidity reading
display.set_pen(humidcolor)
display.text('{:.0f}'.format(int(humidity)) + '%', 10, 85, 240, 5)
display.set_pen(white)
display.text(describe_humidity(int(humidity)), 10, 115, 240, 3)
# and the temperature reading
display.set_pen(tempcolor)
display.text('{:.1f}'.format(temperature) + '`c', 10, 10, 240, 5)
display.set_pen(white)
display.text(describe_temperature(temperature), 10, 40, 240, 3)
# and the min max temperature readings
if time_elapsed > 15:
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, 60, 240, 3)
# time to update the display
display.update()
utime.sleep(1)
display.set_pen(black)
display.clear()