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()
8 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

Thanks for sharing the code
I have been searching for something to display the the atmospheric data from BME280 to the OLED Runs perfectly

Just need to find something to deal with the serial data from a windspeed and direction device to run concurrently with the BME280. With all the GPIO pins used with the picodev adaptor I guess a usb serial converter is what I should be looking for?

Hi Robert,

Another option is that you could solder headers to the top of your PiicoDev adapter and use Pins 14 and 15 for a UART connection.

1 Like

Ive decided to try a RS232 serial to USB adaptor. I have been using this successfully to communicate the wind sensor (Vaisala WS425) and my Windows XP PC, using PuTTY as the terminal program

The serial adaptor plugged to a Raspberry pi USB port shows as ttyUSB0 in the dev directory
I have loaded Pyserial since it was already available. I have tried, unsuccessfully, using “typical” codes to send and receive data. I have edited the serial parameters including the correct baudrate, stop bits etc

If you have any info on methods to send and receive RS232 data, can you point me in the right direction, please

2 Likes

Hi Robert,

It might be worth doing a quick sanity check to make sure the Pi is handling the serial correctly, if you install PuTTY on the Pi are you able to get that working?

If you dont have any luck there, it might be worth giving an RS232 to UART converter a go: Adafruit RS232 Pal - Two Channel UART to RS-232 Level Shifters - MAX3232E | Buy in Australia | ADA5987 | Core Electronics
Then take the outputs into the connectors ontop of the PiicoDev HAT.

Let us know how you go!
Liam

2 Likes

I had given up on pySerial and PuTTY to communicate with my serial device. Both installed OK but would not work

Tried Minicom and after configuring it to the ttyUSB0 port the serial adaptor is connect to, it worked straight off, returning the data string and even logging it to file with the option of timestamping.

2 Likes