BME680 Temperature/Pressure/Humidity/Gas Sensor

The BME680 sensor allows you to use your BME680 i2c-enabled temperature+pressure+humidity+gas sensor with esphomelib (datasheet, adafruit). It requires i2c to be setup to work.

Example Usage

// Basic
auto bme680 = App.make_bme680_sensor("BME680 Temperature",
                                     "BME680 Pressure",
                                     "BME680 Humidity",
                                     "BME680 Gas Resistance");

// default is no iir filter
bme680.bme680->set_iir_filter(sensor::BME680_IIR_FILTER_15X);
// set heater to 200°C for 100ms, default is off
bme680.bme680->set_heater(200, 100);

See Application::make_bme680_sensor().

API Reference

class BME680Component : public PollingComponent, public I2CDevice

Public Functions

BME680Component(I2CComponent *parent, const std::string &temperature_name, const std::string &pressure_name, const std::string &humidity_name, const std::string &gas_resistance_name, uint8_t address = 0x76, uint32_t update_interval = 15000)
void set_temperature_oversampling(BME680Oversampling temperature_oversampling)

Set the temperature oversampling value. Defaults to 16X.

void set_pressure_oversampling(BME680Oversampling pressure_oversampling)

Set the pressure oversampling value. Defaults to 16X.

void set_humidity_oversampling(BME680Oversampling humidity_oversampling)

Set the humidity oversampling value. Defaults to 16X.

void set_iir_filter(BME680IIRFilter iir_filter)

Set the IIR Filter value. Defaults to no IIR Filter.

void set_heater(uint16_t heater_temperature, uint16_t heater_duration)

Set how the internal heater should operate.

By default, the heater is off. If you want to to have more reliable humidity and Gas Resistance values, you can however setup the heater with this method.

Parameters
  • heater_temperature: The temperature of the heater in °C.
  • heater_duration: The duration in ms that the heater should turn on for when measuring.

void setup()

Where the component’s initialization should happen.

Analogous to Arduino’s setup(). This method is guaranteed to only be called once. Defaults to doing nothing.

void dump_config()
float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

Return
The setup priority of this component

void update()
BME680TemperatureSensor *get_temperature_sensor() const
BME680PressureSensor *get_pressure_sensor() const
BME680HumiditySensor *get_humidity_sensor() const
BME680GasResistanceSensor *get_gas_resistance_sensor() const

Protected Functions

uint8_t calc_heater_resistance_(uint16_t temperature)

Calculate the heater resistance value to send to the BME680 register.

uint8_t calc_heater_duration_(uint16_t duration)

Calculate the heater duration value to send to the BME680 register.

void read_data_()

Read data from the BME680 and publish results.

float calc_temperature_(uint32_t raw_temperature)

Calculate the temperature in °C using the provided raw ADC value.

float calc_pressure_(uint32_t raw_pressure)

Calculate the pressure in hPa using the provided raw ADC value.

float calc_humidity_(uint16_t raw_humidity)

Calculate the relative humidity in % using the provided raw ADC value.

uint32_t calc_gas_resistance_(uint16_t raw_gas, uint8_t range)

Calculate the gas resistance in Ω using the provided raw ADC value.

uint32_t calc_meas_duration_()

Calculate how long the sensor will take until we can retrieve data.

Protected Attributes

BME680CalibrationData calibration_
BME680Oversampling temperature_oversampling_ = {BME680_OVERSAMPLING_16X}
BME680Oversampling pressure_oversampling_ = {BME680_OVERSAMPLING_16X}
BME680Oversampling humidity_oversampling_ = {BME680_OVERSAMPLING_16X}
BME680IIRFilter iir_filter_ = {BME680_IIR_FILTER_OFF}
uint16_t heater_temperature_ = {320}
uint16_t heater_duration_ = {150}
BME680TemperatureSensor *temperature_sensor_
BME680PressureSensor *pressure_sensor_
BME680HumiditySensor *humidity_sensor_
BME680GasResistanceSensor *gas_resistance_sensor_
enum sensor::BME680Oversampling

Enum listing all oversampling options for the BME680.

Values:

BME680_OVERSAMPLING_NONE = 0b000
BME680_OVERSAMPLING_1X = 0b001
BME680_OVERSAMPLING_2X = 0b010
BME680_OVERSAMPLING_4X = 0b011
BME680_OVERSAMPLING_8X = 0b100
BME680_OVERSAMPLING_16X = 0b101
enum sensor::BME680IIRFilter

Enum listing all IIR Filter options for the BME680.

Values:

BME680_IIR_FILTER_OFF = 0b000
BME680_IIR_FILTER_1X = 0b001
BME680_IIR_FILTER_3X = 0b010
BME680_IIR_FILTER_7X = 0b011
BME680_IIR_FILTER_15X = 0b100
BME680_IIR_FILTER_31X = 0b101
BME680_IIR_FILTER_63X = 0b110
BME680_IIR_FILTER_127X = 0b111
using sensor::BME680TemperatureSensor = typedef sensor::EmptyPollingParentSensor<1, ICON_EMPTY, UNIT_C>
using sensor::BME680PressureSensor = typedef sensor::EmptyPollingParentSensor<1, ICON_GAUGE, UNIT_HPA>
using sensor::BME680HumiditySensor = typedef sensor::EmptyPollingParentSensor<1, ICON_WATER_PERCENT, UNIT_PERCENT>
using sensor::BME680GasResistanceSensor = typedef sensor::EmptyPollingParentSensor<1, ICON_GAS_CYLINDER, UNIT_OHM>
struct BME680CalibrationData

Struct for storing calibration data for the BME680.

Public Members

uint16_t t1
uint16_t t2
uint8_t t3
uint16_t p1
int16_t p2
int8_t p3
int16_t p4
int16_t p5
int8_t p6
int8_t p7
int16_t p8
int16_t p9
int8_t p10
uint16_t h1
uint16_t h2
int8_t h3
int8_t h4
int8_t h5
uint8_t h6
int8_t h7
int8_t gh1
int16_t gh2
int8_t gh3
uint8_t res_heat_range
uint8_t res_heat_val
uint8_t range_sw_err
float tfine
uint8_t ambient_temperature