Saturday 3 April 2021

Pimoroni Enviro board

 The Pimoroni Enviro pHAT format board combines  a BME280 temperature, pressure and humidity sensor, LTR559 light and proximity sensor, a microphone and small colour LCD.

The Enviro board comes packed in a neatly printed anti-static bag (I was too excited to photograph it before opening it up)




Pimoroni have a Python library and a bunch of examples.


Assembly was easy, and a a pair of stand-offs secured the sandwich.

Here is an example program that displays the temperature, humidity, atmospheric pressure, lux level and the current time.

import ST7735
from PIL import Image, ImageDraw, ImageFont
from fonts.ttf import RobotoMedium as UserFont
from bme280 import BME280
import time
import datetime

import os

try:
    # Transitional fix for breaking change in LTR559
    from ltr559 import LTR559
    ltr559 = LTR559()
except ImportError:
    import ltr559

print("Starting")
bme280 = BME280()

display_angle = 270 # 90 for upside dow relative to screen print

# Set up the display
disp = ST7735.ST7735(
    port=0,
    cs=1,
    dc=9,
    backlight=12,
    rotation=display_angle,
    spi_speed_hz=10000000
)

# Initialize display.
disp.begin()

# Width and height to calculate text position.
WIDTH = disp.width
HEIGHT = disp.height

# Calculate text position
x = 5
y = 0

# Set up canvas and font
img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0))
draw = ImageDraw.Draw(img)
path = os.path.dirname(os.path.realpath(__file__))
font_size = 20
font = ImageFont.truetype(UserFont, font_size)
small_font = ImageFont.truetype(UserFont, 16)
large_font = ImageFont.truetype(UserFont, 38)

text_colour = (255, 255, 255)
back_colour = (0, 50, 170)

def display_data():
    temperature = bme280.get_temperature()
    pressure = bme280.get_pressure()
    humidity = bme280.get_humidity()
    lux = ltr559.get_lux()
    prox = ltr559.get_proximity()
    draw.rectangle((0, 0, WIDTH, HEIGHT), back_colour)
    draw.text((x, y), "{:04.1f}C".format(temperature), font=font, fill=text_colour)
    draw.text((x, y+25), "{:04.1f}%".format(humidity), font=font, fill=text_colour)
    draw.text((x, y+50), "{:4.0f}hPa".format(pressure), font=font, fill=text_colour)
    # alternating seconds flash the colon separator
    if int(time.time()) % 2 == 0:
        draw.text((x+60,y), datetime.datetime.now().strftime("%H:%M"),
                  font=large_font,fill=text_colour)
    else:
        draw.text((x+60,y), datetime.datetime.now().strftime("%H %M"),
                  font=large_font,fill=text_colour)
    draw.text((x+100,y+55),"{:05.02f}lx".format(lux), font=small_font,fill=text_colour)
    disp.display(img)

# Main loop
while True:
    #print(bme280.get_temperature())
    display_data()
    time.sleep(1)