bme680 - Environmental Sensor

Allows access to environmental data of card10’s surroundings.

If bsec_enable is set in card10.cfg, the proprietary Bosch BSEC library will be activated which offers the following extra functionality:

  • Manual temperature offset compensation

    The bsec_offset configuration allows to configure a static temperature offset. Please use a reference thermometer to determine the offset of your card10. If no offset is provided a default offset for a card10 which is connected to USB, has BLE active and is without a case is used.

  • A fixed measurement interval of 3 seconds

    This helps to stabilize the temperature of the card10.

  • An indoor air quality (IAQ) and equivalent CO2 estimation algorithm

    Please refer to the BSEC API documentation to get more information about how to interpret these estimates.

Note

Please keep in mind that the BME680 can not directly measure CO2. It measures Volatile Organic Compounds (VOCs). The BSEC library uses this measurement to compute an Indoor Air Quality (IAQ) indication. It also assumes that all VOCs in the air are from human breath and computes an equivalent CO2 (eCO2) value from this. Please be aware of these facts when judging the accuracy of the IAQ and eCO2 values. Some more information can be found in the BSEC API documentation.

Warning

For the BSEC library to properly work the card10 should be kept running for at least 10 hours at least once. This is needed as the BSEC library periodically writes calibration information about the sensor to the card10’s file system.

Please make sure to observe the IAQ accuracy field. It will tell you if the IAQ and eCO2 measurements are deemed “accurate” by the BSEC library. Your application should either inform the user about the current accuracy (e.g. by color coding) or simply not show any values if the accuracy is below 2.

Note

See also the BLE Environmental Sensing Service.

Example:

import bme680, time

with bme680.Bme680() as environment:
    while True:
        d = environment.get_data()

        print("Temperature:    {:10.2f} °C".format(d.temperature))
        print("Humidity:       {:10.2f} % r.h.".format(d.humidity))
        print("Pressure:       {:10.2f} hPa".format(d.pressure))
        print("Gas Resistance: {:10.2f} Ω".format(d.resistance))

        time.sleep(1)

You can use the return type of get_data() to decide if you want to use/display the additonal fields returned if BSEC is enabled.

if isinstance(d, bme680.BSECData):
    print("Air quality:    {:7d}".format(d.iaq))

Sensor Class

class bme680.Bme680[source]

BME680 4-in-1 environmental sensor.

Example:

import bme680

environment = bme680.Bme680()
print("Current temperature: {:4.1f} °C".format(environment.temperature()))

This class can also be used as a context-manager which will automatically deactivate the sensor on exit:

import bme680

with bme680.Bme680() as environment:
    print("H: {:4.1f}%".format(environment.humidity()))

# Sensor is off again, saving power

New in version 1.10.

get_data()[source]

Get all sensor data at once.

get_data() returns a namedtuple with the following fields:

  • temperature: Temperature in °C

  • humidity: Relative humidity

  • pressure: Barometric pressure in hPa

  • gas_resistance: Gas resistance in

If the Bosch BSEC library is enabled in card10.cfg, the following additional fields will be returned:

  • iaq: Indoor air quality indication

  • iaq_accuracy: Accuracy of indoor air quality

  • eco2: Equivalent CO2 content in ppm

If BSEC is enabled an instance of bme680.BSECData will be returned. If BSEC is not enabled an instance of bme680.Bme680Data will be returned.

Example:

import bme680

with bme680.Bme680() as environment:
    data = environment.get_data()

    print("T: {}".format(data.temperature))
    print("H: {}".format(data.humidity))
close()[source]

Stop/deinit the BME680.

If you no longer need measurements, you should call this function to save power.

temperature()[source]

Measure current temperature in °C.

Example:

environment = bme680.Bme680()
print(str(environment.temperature()))
humidity()[source]

Measure current relative humidity.

Example:

environment = bme680.Bme680()
print(str(environment.humidity()))
pressure()[source]

Measure current barometric pressure in hPa.

Example:

environment = bme680.Bme680()
print(str(environment.pressure()))
gas_resistance()[source]

Measure current gas resistance in .

Example:

environment = bme680.Bme680()
print(str(environment.gas_resistance()))
iaq()[source]

Retrieve indoor air quality as defined by the Bosch BSEC library.

BSEC needs to be enable in card10.cfg. Otherwise this method will raise an OSError exception.

Example:

environment = bme680.Bme680()
print(str(environment.iaq()))

New in version 1.17.

iaq_accuracy()[source]

Retrieve indoor air quality accuracy as defined by the Bosch BSEC library.

BSEC needs to be enable in card10.cfg. Otherwise this method will raise an OSError exception.

Example:

environment = bme680.Bme680()
print(str(environment.iaq_accuracy()))

New in version 1.17.

eco2()[source]

Retrieve equivalant CO2 as defined by the Bosch BSEC library.

BSEC needs to be enable in card10.cfg. Otherwise this method will raise an OSError exception.

Example:

environment = bme680.Bme680()
print(str(environment.eco2()))

New in version 1.17.

Deprecated Interface

The following functions should no longer be used directly. The only exist for compatibility as they were the old BME680 interface in previous firmware versions.

bme680.init()

Initialize the sensor.

Before being able to read data from the sensor, you have to call bme680.init().

New in version 1.4.

Deprecated since version 1.10: Use the bme680.Bme680 class instead.

bme680.get_data()

Perform a single measurement of environmental data.

Returns

Tuple containing temperature (°C), humidity (% r.h.), pressure (hPa) and gas resistance (Ohm).

New in version 1.4.

Deprecated since version 1.10: Use the bme680.Bme680 class instead.

bme680.deinit()

Deinitialize the sensor.

New in version 1.4.

Deprecated since version 1.10: Use the bme680.Bme680 class instead.