Presto weather station

I received my new Presto Sunday and have enjoyed playing it. I have had no problem with other codes but when I try to adapt an Enviro+ bme688.py code to display weather the display is blank. I2C functions are normal. This is what I am using…

“”"BME688 / BME680 demo

This demo will work for both the BME680 and BME688.
“”"
import time
from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE
from machine import I2C
from presto import Presto

I2C_PINS = {“id”: 0, “sda”: 40, “scl”: 41} # The I2C pins the QwSTPad is connected to
BRIGHTNESS = 1.0

i2c = I2C(**I2C_PINS)
bmp = BreakoutBME68X(i2c, address=0x77)

presto = Presto(ambient_light=True)
display = presto.display

WIDTH, HEIGHT = display.get_bounds()

setup background

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)

display.set_pen(BG)
display.clear()

def draw(temp_value, press_value, humid_value):
scaled_temp = int(temp_value + 40) # Range from -40 to +60 = 1-100
scaled_press = int((press_value - 87000) / ((108400 - 87000) / 100)) # Range 108400 - 87000 = 1 -100
scaled_humid = int(humid_value) # 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(temp_value), scaled_temp + 5, 80, scale=2)
display.set_pen(PRESS)
display.text(“PRESS: {:0.2f}Pa”.format(press_value), scaled_press + 5, 140, scale=2)
display.rectangle(0, 120, scaled_press, 60)
display.set_pen(HUMID)
display.text(“HUMID: {:0.2f}%”.format(humid_value), scaled_humid + 5, 200, scale=2)
display.rectangle(0, 180, scaled_humid, 60)
display.set_pen(TEXT)
display.text(“BME688 enviro Sensor”, 5, 10, scale=2)
display.update()

while True:
temperature, pressure, humidity, gas, status, _, _ = bmp.read()
draw(temperature, pressure, humidity)
heater = “Stable” if status & STATUS_HEATER_STABLE else “Unstable”
print(“{:0.2f}c, {:0.2f}Pa, {:0.2f}%, {:0.2f} Ohms, Heater: {}”.format(
temperature, pressure, humidity, gas, heater))
time.sleep(1.0)
I know I’m missing something, just can’t see it. Any and all help is greatly appreciated. Thanks

Try using very simple display.text(temp_value) statments first and then work on the formatting.

When posting code please click on the </> icon and paste the code in the blue hi-lighted area so we can see the indents…

1 Like

Thank you for your help. I reworked it all and managed to get this simple code going…

import time
from breakout_bme280 import BreakoutBME280
from pimoroni_i2c import PimoroniI2C
from presto import Presto

PINS_BREAKOUT_GARDEN = {"sda": 40, "scl": 41}
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}

i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
bme = BreakoutBME280(i2c)

# Setup for the Presto display
presto = Presto(ambient_light=True)
display = presto.display
WIDTH, HEIGHT = display.get_bounds()

# Couple of colours for use later
BLUE = display.create_pen(90, 100, 202)
WHITE = display.create_pen(200, 155, 55)


while True:

    # Clear the screen and use blue as the background colour
    display.set_pen(BLUE)
    display.clear()
    # Set the pen to a different colour otherwise we won't be able to see the text!
    display.set_pen(WHITE)
    
     # read the sensors
    temperature, pressure, humidity = bme.read()
    # pressure comes in pascals which is a reight long number, lets convert it to the more manageable hPa
    pressurehpa = pressure / 100
    
    # draw the text
    display.set_pen(WHITE)
    display.text("temperature:", 10, 10, 240, 3)
    display.set_pen(WHITE)
    display.text('{:.1f}'.format(temperature) + 'C', 10, 30, 240, 5)
    
    # and the pressure text
    display.text("pressure:", 10, 85, 240, 3)
    display.text('{:.0f}'.format(pressurehpa) + 'hPa', 10, 105, 240, 5)
    
     # and the humidity text
    display.text("humidity:", 10, 160, 240, 3)
    display.text('{:.0f}'.format(humidity) + '%', 10, 180, 240, 5)

    # Finally we update the screen with our changes :)
    presto.update()

while True:
    reading = bme.read()
    print(reading)
    time.sleep(1.0)
    
 

    # Finally we update the screen with our changes :)
    presto.update()

Thanks again

The sensor stick also has a light sensor which reads Lux. I’ve also got an AHT20 (temperature and relative humidity) so I’ve tested them as well. There temperature and hums readings are different. I find the AHT20 to be nearer to my NPL certified old school, Hg thermometer reading on my desktop!

You can stop the program by touching the screen. (The touch aspect of the screen is very accurate.) I’ve not done any on screen formatting, that is the fun part.

The Qw/STpad also works very well if you want ‘proper’ buttons.

# Sensor readings on Pimoroni Explorer
import time
from machine import Pin, I2C
from breakout_bme280 import BreakoutBME280
from breakout_ltr559 import BreakoutLTR559
import ahtx0
import math
from presto import Presto
'''
import network
import rp2
import requests
rp2.country("GB")
from secrets import WIFI_SSID, WIFI_PASSWORD
'''
# Setup for the Presto display
presto = Presto(full_res=True)
display = presto.display

WIDTH, HEIGHT = display.get_bounds()

touch = presto.touch # Activate touch

# Create some colours
BLUE = display.create_pen(20,0,255)
WHITE = display.create_pen(255, 255, 255)
RED = display.create_pen(255,0,0)
ORANGE = display.create_pen(245, 165, 4)
GREEN = display.create_pen(0,255,0)
PINK = display.create_pen(250, 125, 180)
CYAN = display.create_pen(0,255,255)
MAGENTA = display.create_pen(255,0,255)
BLACK = display.create_pen(0, 0, 0)
YELLOW = display.create_pen(255, 255, 0)

# A few procedures to be used later
def wait(z): # delay a while
    time.sleep(z)
    
def clean(): # Clear the screen to Black
    display.set_pen(BLACK)
    display.clear()
    presto.update()

clean()
i2c = I2C(id=0,scl=Pin(41), sda=Pin(40)) # PESTO

# Check sensors connected
try:
    bme = BreakoutBME280(i2c, address=0x76)
    ltr = BreakoutLTR559(i2c)
    aht20 = ahtx0.AHT20(i2c)
except RuntimeError:
    print("Multi-Sensor Stick or AHT20 missing")

touch = presto.touch # Activate touch

display.set_font("bitmap8") # Change the font
clean()

display.set_pen(RED)
display.text("Presto Sensors",40,120,460,8)
display.set_pen(YELLOW)
display.text("BME280, TR559, AHT20",40,320,460,4)
presto.update()
# Wake up lux sensor
prox, a, b, c, d, e, lux = ltr.get_reading()
time.sleep(1.0)

# Main loop

while True:
    prox, a, b, c, d, e, lux = ltr.get_reading()
    lux = int(lux)
    
    print("\nAHT20")
    print("Temperature: %0.2f C" % aht20.temperature)
    print("Humidity: %0.2f %%" % aht20.relative_humidity)

    # read the sensors
    temperature, pressure, humidity = bme.read()
    temp = round(temperature,2)

    # Convert pressure to hPa
    pressurehpa = int(pressure / 100)
    touch.poll()
    if touch.state:
        break
    
    print("\nBME280")

    print("Temperature: "+str(temp)+" C")
    print("Humidity: "+str(int(humidity)) +" %")
    print("Pressure: "+str(pressurehpa)+" hPa")

    print("\nLTR559\n"+str(lux),"LUX")
    print("\n====================")

    time.sleep(1)
    touch.poll()
    if touch.state:
        break
clean()
presto.update()

Sample output:

====================

AHT20
Temperature: 17.01 C
Humidity: 63.50 %

BME280
Temperature: 17.6 C
Humidity: 59 %
Pressure: 1008 hPa

LTR559
9 LUX

====================
1 Like

Thank you for your help. I went with an Adafruit BME688 I had on hand and added more color options to change things up. I really do like this display and will work on adding it to my Home Assistant setup soon. Thanks again.

My final version before I work on more…

import time
from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE
from pimoroni_i2c import PimoroniI2C
from presto import Presto


PINS_BREAKOUT_GARDEN = {"sda": 40, "scl": 41}

i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
bme = BreakoutBME68X(i2c, address=0x77)

# Setup for the Presto display
presto = Presto(ambient_light=True)
display = presto.display
WIDTH, HEIGHT = display.get_bounds()

# Create some colours
BLUE = display.create_pen(20,0,255)
WHITE = display.create_pen(255, 255, 255)
RED = display.create_pen(255,0,0)
ORANGE = display.create_pen(245, 165, 4)
GREEN = display.create_pen(0,255,0)
PINK = display.create_pen(250, 125, 180)
CYAN = display.create_pen(0,255,255)
MAGENTA = display.create_pen(255,0,255)
BLACK = display.create_pen(0, 0, 0)
YELLOW = display.create_pen(255, 255, 0)


while True:

    # Clear the screen and use blue as the background colour
    display.set_pen(BLUE)
    display.clear()
    # Set the pen to a different colour otherwise we won't be able to see the text!
    display.set_pen(YELLOW)
    
     # read the sensors
    temperature, pressure, humidity, gas, status, _, _ = bme.read()
    # pressure comes in pascals which is a reight long number, lets convert it to the more manageable hPa
    pressurehpa = pressure / 100
    temperature = temperature * 9/5 + 32
    gas = gas / 1000
    
    display.set_font("bitmap8") # Change the font
    
                     
    # draw the text
    display.set_pen(ORANGE)
    display.text("temperature:", 10, 10, 240, 2)
    display.set_pen(YELLOW)
    display.text('{:.1f}'.format(temperature) + ' °F', 10, 30, 240, 3)
    
    # and the pressure text
    display.set_pen(ORANGE)
    display.text("pressure:", 10, 60, 240, 2)
    display.set_pen(YELLOW)
    display.text('{:.0f}'.format(pressurehpa) + ' hPA', 10, 80, 240, 3)
    
     # and the humidity text
    display.set_pen(ORANGE) 
    display.text("humidity:", 10, 110, 240, 2)
    display.set_pen(YELLOW)
    display.text('{:.0f}'.format(humidity) + ' %', 10, 130, 240, 3)
    
    display.set_pen(MAGENTA)
    display.text("Weather Station", 80, 210, 240, 1)
    display.text("Muddy Creek Customs", 70, 220, 240, 1)
    
    display.set_pen(ORANGE)
    display.text("gas:", 10, 160, 240,2)
    display.set_pen(RED)
    display.text('{:.0f}'.format(gas) + ' K ohms', 10, 180, 240, 3)

    # Finally we update the screen with our changes :)
    presto.update()

while True:
    reading = bme.read()
    print(reading)
    time.sleep(1.0)
    
 

    # Finally we update the screen with our changes :)
    presto.update()