Display PiicoDev Atmospheric Sensor data on PiicoDev OLED Display Module

This project displays the data from a PiicoDev Atmospheric Sensor (BME280) on both a PiicoDev OLED Display Module (128x64) SSD1306 and terminal i.e temperature, pressure and relative humidity. It takes a reading every 60 seconds but here is the really neat part - it takes the reading exactly on the minute. The date/time the reading is taken is displayed at the top. Note on the OLED display the seconds scroll off the screen but not to worry because we know it is β€œ00”.

Wish I could show you a photo but it looks like this.

2022-02-13 11:59:00
22.0 degC
1007.3 hPa
64.0 %RH

As well as loading the libraries the files font-pet-me-128.dat and PiicoDev_Unified.py are required in the project directory.

When the code runs do not be surprised if nothing displays immediately. The code is waiting for the minute to tick over.

# This project displays the data from a PiicoDev Atmospheric Sensor (BME280)
# on both a PiicoDev OLED Display Module (128x64) SSD1306 and terminal
# Courtesy Chris Barlow

from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_SSD1306 import *
from datetime import datetime
from time import sleep

display = create_PiicoDev_SSD1306()

BME280Sensor = PiicoDev_BME280(t_mode=2, p_mode=5, h_mode=1, iir=2)

while True:
    today = datetime.now()
    delay = 60.0 - (today.second + (today.microsecond/1000000))
    sleep(delay) # wait for new minute
    today = datetime.now()
    today_str = today.strftime("%Y-%m-%d %H:%M:%S")    
    
    BME280Temp, presPa, humRH = BME280Sensor.values()
    pres_hPa = presPa / 100
    # Print the data on the terminal
    print(today_str)
    print(str("{:.2f}".format(BME280Temp) + " degC"))
    print(str("{:.1f}".format(pres_hPa) + " hPa"))
    print(str("{:.1f}".format(humRH) + " %RH"))
    print("----------")
    
    # Print the data on the display
    display.fill(0)
    display.text(today_str, 0,0, 1)
    display.text(str("{:.1f}".format(BME280Temp) + " degC"), 0,16, 1)
    display.text(str("{:.1f}".format(pres_hPa) + " hPa"), 0,32, 1)
    display.text(str("{:.1f}".format(humRH) + " %RH"), 0,48, 1)
    display.show()
7 Likes

Hey Fractal,

You should be able to post photos with your Discourse permissions. If you attempt to paste one in the text field in your reply does it upload correctly? Or do you get a warning about it? If so, please let us know and I’ll make sure you’re able to get it uploaded :smile:

Thanks for sharing your Python for it!

3 Likes

Hi Bryce

I was not sure if you could post photos and I did not try. Will look for my macro lens and give it a go.

4 Likes