adafruit_bme680

CircuitPython library for BME680 temperature, pressure and humidity sensor.

  • Author(s): Limor Fried, William Garber, many others

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_bme680.Adafruit_BME680(*, refresh_rate: int = 10)[source]

Driver from BME680 air quality sensor

Parameters:

refresh_rate (int) – Maximum number of readings per second. Faster property reads will be from the previous reading.

property altitude: float

The altitude based on current pressure vs the sea level pressure (sea_level_pressure) - which you must enter ahead of time)

property filter_size: int

The filter size for the built in IIR filter

property gas: int

The gas resistance in ohms

property humidity: float

The relative humidity in RH %

property humidity_oversample: int

The oversampling for humidity sensor

property pressure: float

The barometric pressure in hectoPascals

property pressure_oversample: int

The oversampling for pressure sensor

property relative_humidity: float

The relative humidity in RH %

sea_level_pressure

Pressure in hectoPascals at sea level. Used to calibrate altitude.

set_gas_heater(heater_temp: int, heater_time: int) bool[source]

Enable and configure gas reading + heater (None disables) :param heater_temp: Desired temperature in degrees Centigrade :param heater_time: Time to keep heater on in milliseconds :return: True on success, False on failure

property temperature: float

The compensated temperature in degrees Celsius.

property temperature_oversample: int

The oversampling for temperature sensor

class adafruit_bme680.Adafruit_BME680_I2C(i2c: I2C, address: int = 119, debug: bool = False, *, refresh_rate: int = 10)[source]

Driver for I2C connected BME680.

Parameters:
  • i2c (I2C) – The I2C bus the BME680 is connected to.

  • address (int) – I2C device address. Defaults to 0x77

  • debug (bool) – Print debug statements when True. Defaults to False

  • refresh_rate (int) – Maximum number of readings per second. Faster property reads will be from the previous reading.

Quickstart: Importing and using the BME680

Here is an example of using the BMP680_I2C class. First you will need to import the libraries to use the sensor

import board
import adafruit_bme680

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()   # uses board.SCL and board.SDA
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)

You need to setup the pressure at sea level

bme680.sea_level_pressure = 1013.25

Now you have access to the temperature, gas, relative_humidity, pressure and altitude attributes

temperature = bme680.temperature
gas = bme680.gas
relative_humidity = bme680.relative_humidity
pressure = bme680.pressure
altitude = bme680.altitude
class adafruit_bme680.Adafruit_BME680_SPI(spi: SPI, cs: DigitalInOut, baudrate: int = 100000, debug: bool = False, *, refresh_rate: int = 10)[source]

Driver for SPI connected BME680.

Parameters:
  • spi (SPI) – SPI device

  • cs (DigitalInOut) – Chip Select

  • debug (bool) – Print debug statements when True. Defaults to False

  • baudrate (int) – Clock rate, default is 100000

  • refresh_rate (int) – Maximum number of readings per second. Faster property reads will be from the previous reading.

Quickstart: Importing and using the BME680

Here is an example of using the BMP680_SPI class. First you will need to import the libraries to use the sensor

import board
from digitalio import DigitalInOut, Direction
import adafruit_bme680

Once this is done you can define your board.SPI object and define your sensor object

cs = digitalio.DigitalInOut(board.D10)
spi = board.SPI()
bme680 = adafruit_bme680.Adafruit_BME680_SPI(spi, cs)

You need to setup the pressure at sea level

bme680.sea_level_pressure = 1013.25

Now you have access to the temperature, gas, relative_humidity, pressure and altitude attributes

temperature = bme680.temperature
gas = bme680.gas
relative_humidity = bme680.relative_humidity
pressure = bme680.pressure
altitude = bme680.altitude
adafruit_bme680.bme_set_bits(reg_data, bitname_msk, bitname_pos, data)[source]

Macro to set bits data2 = data << bitname_pos set masked bits from data2 in reg_data

adafruit_bme680.bme_set_bits_pos_0(reg_data, bitname_msk, data)[source]

Macro to set bits starting from position 0 set masked bits from data in reg_data

adafruit_bme680.delay_microseconds(nusec)[source]

HELP must be same as dev->delay_us