Log UK's Hottest Days - Project

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

Even though you deleted the post I can read it by clicking the yellow pencil icon ;)

Is it located indoor or outdoor? I have a 3 display Pi based setup that graphs temperature, humidity, and pressure. It’s indoors. I see spikes when I open a window. Or inadvertently breath on the BME280.

Takes some time for posts to be taken right out of the system. I’ll put it back here:

11:25 600
0 34.52309 101019.1 37.27215 77341 31
1 33.40703 101015.1 29.87263 6570 4854
2 33.32549 101009.8 27.95653 5684 4929
3 33.97526 101005.2 27.31482 5862 4994
4 33.88352 101001.0 25.21584 5693 4993
5 34.24281 101000.2 23.62025 6052 4957
6 35.00214 100994.2 27.37363 5879 4988
7 35.35379 100983.8 25.61598 5888 5093
8 35.00979 100981.8 26.48405 5770 5129
9 36.04434 100971.6 23.46197 6035 5349
10 36.05708 100962.7 23.82424 5888 5642
11 36.66099 100952.4 22.25385 5764 6384
12 36.8521 100940.0 25.57943 6011 7191
13 36.88014 100952.8 26.18755 5879 8466
14 37.2063 100937.8 28.05451 5712 7844
15 37.57834 100927.6 20.48394 6157 7440
16 38.61036 100910.1 18.77336 5931 8116
17 38.33006 100899.9 21.71345 5908 7291
18 36.42911 100884.2 23.86287 5944 7145
19 38.08033 100880.9 23.63016 5994 9442
20 47.58565 100889.0 15.39025 5767 39105
21 45.95974 100878.7 14.71647 5981 12590
22 38.21793 100829.3 20.28673 5721 3942
23 37.68026 100815.3 22.5221 5928 3548
24 38.14914 100804.3 24.12731 5703 2784
25 37.66497 100801.9 24.30969 6045 2619
26 37.22414 100792.7 21.87789 5981 4585
27 37.52738 100787.5 21.84132 5988 4737
28 36.7196 100778.5 26.02818 6035 2140
29 38.697 100784.1 21.87634 6015 4650

It was outdoors, in the shade but I moved it, to keep it in the shade, (no Stevenson Screen available) and was near a large piece of hot concrete garden path.

Major problem if used with battery power. The initial file setup WRITE should have been an APPEND.

with open(fname, "w") as f: # Write - new file
    f.write(dt +" "+str(delaysecs)+"\n")

change to

with open(fname, "a") as f: # New file if it does not exist!
    f.write(dt +" "+str(delaysecs)+"\n")

If you do not do this when using autorun of main.py with battery power the file gets overwritten when you plug it in to retrieve the file. (Must have been the heat and rushing things.) You can edit out the unwanted file records once you have got the file somewhere safe.

Seems to work OK now. Ready for the next heatwave!

The temperatures do appear to be a bit higher than I expected.

1 Like

Cool, pun intended, =) I have a half dozen or so Pi and Pico weather setups. No logging of data, just displaying it. And nothing permanent outside. I have portable setups I take outside and use in the shade of my gazebo.
Data logging is on my to do list though. And I hope to have something permanent setup outside by the end of the summer.

I offset the temperature by about -3 degrees (-5 if I had the screen on) to get an air temperature / humidity reading that matched my commercial thermometer / hygrometer - they’re tracking pretty nicely now.

I bought a bunch of sensors recently to do this, one of them is the bme688. All on a breadboard on my desk at the moment (not outside). I’m running on an ESP8266.

Of the sensors I have, the bme688 seems to run hot and a ds18b20 is similar. An AM2320 runs around where I would expect (compared to other thermometer devices I have sitting on the desk). Reading, as I write, desk thermometer 28.8c, AM2320 is 28.4c, ds18b20 is 29.56c and bme688 is 29.42c. A TMP36 (from the Arduino starter pack) reads around 783mv (28.3c) but the ADC readings are way off and very unstable so I dumped it. I think the bme688 and ds18b20 are running about a degree hot.

Both bme688 and am2320 provide humidity readings that follow each other very well but the bme688 runs a consistent 3.5% high. Again, the am2320 matches the humidity reading on the same desk thermometer device I mentioned before.

I have the bme688 datasheet from Bosch - it’s a complex beast and probably needs more setup to get it to work properly rather then taking it out of the bag, connecting it up and running pretty-much the example program on it.

I also have a veml7700 lux sensor which is good, but I have nothing to compare it against.

The ESp8266 collects sensor readings and sends HTTP JSON reports over wi-fi to a logger which is a small python server providing scrape data for Prometheus. Prometheus scrapes that data and leads to graphs like this:

1 Like

Thank you Hel and John - very useful - I will use your corrections.

I wrote a piece some time ago comparing different temperature sensors. One of the other problems is heat capacity and the slow reaction times of different sensors. They all need suitable corrections.

You can find the piece here:
Testing Temperature Sensors - Which One for Me? : 15 Steps (with Pictures) - Instructables

Hi, I’ve just started playing with the Enviro+ Pack and found that the humidity reading is fairly far from what other sensors, of different nature, show for the same room.
So, temperature is OK with the offset you chose and pressure simply needs a conversion to HectoPascal to make it more friendly, to me at least.
However the humidity reading is a good 20% higher than what the other sensors say.
I then noticed that you used an approximation for the dewpoint, Td =T-(100-Hr)/5 , that is valid only for relative humidity in the 50%+ range.
Is there a specific reason for not choosing the less approximate formula, valid for a wider range of relative humidity :
Td =(112+0,9T)Ur0,125-112+0,1T – note that it should read “U to 0,125” but I didn’t manage to get it.
Thank you

That’s the dewpoint calculation we’ve used on previous enviro products, but I agree that it tends to make the relative humidity trend high - if you have an alternative calculation that works better we enthusiastically accept pull requests :)

I’m still playing with a formula that I’m told (I’m not an expert at all) it’s derived from the Bosen’s equation and that I quoted in my previous post. I’ll post the results if they are convincing me

1 Like

The Bosen formula gives me odd results and the corrected humidity assumes nonsense values. In the meantime I’ve a couple of questions.
The first is about the formula:
dewpoint = temperature - ((100 - humidity) / 5)
shouldn’t it be:
dewpoint = corrected_temperature - ((100 - humidity) / 5) ?
and then, where this formula:
corrected_humidity = 100 - (5 * (corrected_temperature - dewpoint))
is coming from?

There is the physics of measuring humidity - from before these sensors were invented. Interesting read if you have the time.
a-guide-to-the-measure-of-humidity-gpg103 (npl.co.uk)

Actually I didn’t want to dive into this subject but I’ll give it a try (ehm… I don’t know when) . Thanks for pointing me at this paper

I am a retired Electronic Technician. I was employed to maintain equipment at an airport. Down the hall was the weather office.

One big deal for pilots is the Dew Point.

They did all manner of things to get very accurate reading. And it was for the most part done the old school way. Web bulb and dry bulb thermometers etc. I was fascinated by the equipment. There was new electronic and old mechanical there. A barometer that recorded with ink on a paper drum for example. A glass ball (magnifying glass) that tracked the sun by burning a line / dot on a curved paper chart behind it.

They were always comparing the old way readings to the new electronic readings. The electronics, at that time were in trials. That was early 90’s if memory serves me. I started there in 88.