Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
dingo27 Mobile
Published

Raspberry Pi BME680 Viewer

Readings from BME680 sensor are transferred to OLED display using Python and Raspberry Pi

IntermediateProtip1 hour5,967
Raspberry Pi BME680 Viewer

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
Whatever Raspberry is suitable for you...
×1
SH1106 OLED 128x64 module
A no name brand from Aliexpress, any 128x64 will do, as long as it has I2C
×1
Gravity: I2C BME680 Environmental Sensor
DFRobot Gravity: I2C BME680 Environmental Sensor
Any BME680 or 280 with I2C will do
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Story

Read more

Schematics

Schematic

Code

Untitled file

Python
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import sh1106
import time
import bme680
from PIL import ImageFont

try:
    sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
except IOError:
    sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY)

# These oversampling settings can be tweaked to
# change the balance between accuracy and noise in
# the data.

sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)

device = sh1106(i2c(port=1, address=0x3C), rotate = 2)

sensor.data.temperature = 0
sensor.data.pressure = 0
sensor.data.humidity = 0

#subprograms
def temp():
    return " %.2f C" \
        % (sensor.data.temperature)

def humi():
    return " %.2f %%" \
        % (sensor.data.humidity)

def pres():
    return "%.2f hPa" \
        % (sensor.data.pressure)

#main program
while True:
    '''
    if sensor.get_sensor_data():
        output = '{0:.2f} C,  {1:.2f} hPa,  {2:.3f} %RH'.format(
            sensor.data.temperature,
            sensor.data.pressure,
            sensor.data.humidity)
        print(output)
    '''    
    sensor.get_sensor_data()    

    with canvas(device) as draw:
        #draw.rectangle(device.bounding_box, outline="white", fill="black")
        draw.text((10, 5), "TEMP : ", fill="white")
        draw.text((50, 5), temp(), fill="white")
        
        draw.text((10, 25), "HUMI : ", fill="white")
        draw.text((50, 25), humi(), fill="white")

        draw.text((10, 45), "PRES : ", fill="white")
        draw.text((50, 45), pres(), fill="white")
        
        
    time.sleep(1)

Credits

dingo27 Mobile
4 projects • 6 followers
Just some working man with electronics as hobby in what is left of free time. Recently doing things exclusively with Python and Raspbery Pi
Contact

Comments

Please log in or sign up to comment.