BME680 Environmental Sensor

This documentation includes installation guidelines and sample code for your hardware.

Python Library

Turta_BME680 library is responsible for communicating with BME680 sensor.

To install the library from the (PyPI) Python Package Index, enter the following command to the console.

pip install turta-iothat

Add the following statement to the top of your Python code.

from turta_iothat import Turta_BME680

Then, create an instance of the Turta_BME680 class.

bme680 = Turta_BME680.BME680Sensor()

Now you're ready to access the library by calling the bme680 instance.

Initialization

The library automatically initializes the required components when its instance is being created, so there is no need to do a manual initialization.

Basic Members

Read Temperature

Reads the temperature in Celsius.

float read_temperature()
  • Parameters

    • None

  • Returns

    • Float: Temperature reading.

Read Humidity

Reads the relative humidity.

float read_humidity()
  • Parameters

    • None

  • Returns

    • Float: Relative humidity reading.

Read Pressure

Reads the pressure in Pa.

float read_pressure()
  • Parameters

    • None

  • Returns

    • Float: Air pressure in Pa.

Read Altitude

Reads the altitude from the sea level in meters.

float read_altitude(meanSeaLevelPressureInBar)
  • Parameters

    • Float meanSeaLevelPressureInBar: Mean sea level pressure in bar.

  • Returns

    • Float: Altitude from the sea level.

Read Gas Resistance

Reads the gas resistance.

float read_gas_resistance()
  • Parameters

    • None

  • Returns

    • Float: Gas resistance in Ohms.

Samples

You can copy the example code from https://github.com/Turta-io/IoTHAT/tree/master/Samples/Raspbian/Python address, and then copy it to the Raspberry Pi. There is one example of this library.

BME680 Sample App

This application demonstrates temperature, humidity, pressure, altitude and gas resistance readings.

To run the example:

  1. Copy the library and sample code to a folder on the Raspberry Pi.

  2. Open terminal, and go to the folder you copied the codes.

  3. Run the sample with the following command:

python BME680SampleApp.py

Sample Code

BME680SampleApp.py
#! /usr/bin/python

import time
from turta_iothat import Turta_BME680
#Install IoT HAT library with "pip install turta-iothat"

#Variables
#Sea level pressure in bar
slp = 1000.0 #Update this from weather forecast to get precise altitude

#Initialize
bme680 = Turta_BME680.BME680Sensor()

try:
    while True:
        #Hint: To get temperature, pressure and humidity readings at the same time,
        #call BME680Sensor.read_tph() method.

        #Read & print temperature
        print("Temperature.....: " + str(round(bme680.read_temperature(), 1)) + "C")

        #Read & print humidity
        print("Humidity........: %" + str(round(bme680.read_humidity(), 1)) + "RH")

        #Read & print pressure
        print("Pressure........: " + str(round(bme680.read_pressure(), 1)) + "Pa")

        #Read & print altitude
        print("Altitude........: " + str(round(bme680.read_altitude(slp), 1)) + "m")

        #Read & print gas resistance
        print("Gas Resistance..: " + str(round(bme680.read_gas_resistance(), 1)) + "Ohms")

        #Rest a bit
        print("-----")
        time.sleep(10.0)

#Exit on CTRL+C
except KeyboardInterrupt:
    print('Bye.')

Result

When you run the sample, it prints sensor readings to the terminal. The example output should be like this:

Temperature.....: 25.0
Humidity........: 50.0
Pressure........: 1000.0
Altitude........: 100.0
Gas Resistance..: 100000.0
-----

To stop the Python script, just press CTRL + C.

Last updated