Just built a small project to log the weather with Pico enviro+ for the hottest times in UK.
Just wrote it this morning so first real test is live.
I’m using a Pico Lipo 16 on the back of the board to do the work and log the data.
Hope someone finds it useful.
Tony
# Enviro Plus logging
# Tony Goodhew 18th July 2022
import time
import machine
from picographics import PicoGraphics, DISPLAY_ENVIRO_PLUS
from pimoroni import RGBLED
from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE
from pimoroni_i2c import PimoroniI2C
from breakout_ltr559 import BreakoutLTR559
from pimoroni import Button
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
WIDTH = 240
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
bmp = BreakoutBME68X(i2c, address=0x77)
ltr = BreakoutLTR559(i2c)
display = PicoGraphics(display=DISPLAY_ENVIRO_PLUS)
display.set_backlight(1.0)
led = RGBLED(6, 7, 10, invert=True) # seting pins for the RGB led
led.set_rgb(0,0,0)
button_a = Button(12, invert=True)
button_b = Button(13, invert=True)
button_x = Button(14, invert=True)
button_y = Button(15, invert=True)
# setup background
BG = display.create_pen(0, 0, 0)
TEXT = display.create_pen(255, 255, 255)
TEXT2 = display.create_pen(255, 0, 0)
LUX = display.create_pen(255, 255, 0)
display.set_pen(BG)
display.clear()
dt = "11:21" # Start time
fname = dt + ".txt" # File name
delaysecs = 600 # 10 minute interval
print("temperature, pressure, humidity, int(gas), light \n")
with open(fname, "w") as f: # Write - new file
f.write(dt +" "+str(delaysecs)+"\n")
maxx = -999
count = -1
running = True
now = time.time()
print(now)
future = now + delaysecs
while running:
now = time.time()
future = now + delaysecs
display.set_pen(BG)
display.clear()
display.update()
count = count + 1
temperature, pressure, humidity, gas, status, _, _ = bmp.read()
reading = ltr.get_reading()
light = reading[BreakoutLTR559.LUX]
print(temperature, pressure, humidity, int(gas), light)
dstring = str(count) +" "+ str(temperature) +" " + str(pressure) +" " + str(humidity) +" " + str(int(gas)) +" " + str(light) +"\n"
with open(fname, "a") as f: # Append
f.write(dstring)
if temperature > maxx:
maxx = temperature
max_count = count
display.set_pen(TEXT)
display.text(str(count),5,25,WIDTH - 10, 2)
display.text(str(temperature),5,45,WIDTH - 10, 2)
display.update()
while time.time() < future:
if button_y.is_pressed:
running = False
future = 0 # Break out of delay
display.set_pen(BG)
display.clear()
display.update()
# After button pressed
display.set_pen(BG)
display.clear()
display.update()
display.set_pen(TEXT2)
display.text(str(maxx),5,5,WIDTH - 10, 2)
display.text(str(max_count),5,25,WIDTH - 10, 2)
display.update()
'''
with open(fname, "r") as f:
print("Printing lines in file: Method #1\n")
line = f.readline()
while line != '': # NOT EOF
print(line)
line = f.readline()
with open(fname, "r") as f:
lines = f.readlines()
print("Printing lines in file: Method #2")
for line in lines:
print(line)
'''
print("Done")
Saved as main.py and running from a USB power pack - phone charger. Its sitting in the shade and currently showing 33 degrees.
Have fun