BME280 Temperature/Pressure/Humidity Sensor

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

Example Usage

// Basic
auto bme280 = App.make_bme280_sensor("BME280 Temperature", "BME280 Pressure", "BME280 Humidity");

// Advanced settings
// set infinite impulse response filter, default is OFF.
bme280.bme280->set_iir_filter(sensor::BME280_IIR_FILTER_4X);
// set over value sampling, default is 16x
bme280.bme280->set_temperature_oversampling(sensor::BME280_OVERSAMPLING_16X);
bme280.bme280->set_humidity_oversampling(sensor::BME280_OVERSAMPLING_4X);
bme280.bme280->set_pressure_oversampling(sensor::BME280_OVERSAMPLING_16X);

See Application::make_bme280_sensor().

API Reference

class BME280Component : public PollingComponent, public I2CDevice

This class implements support for the BME280 Temperature+Pressure+Humidity i2c sensor.

Public Functions

BME280Component(I2CComponent *parent, const std::string &temperature_name, const std::string &pressure_name, const std::string &humidity_name, uint8_t address = 0x77, uint32_t update_interval = 15000)
void set_temperature_oversampling(BME280Oversampling temperature_over_sampling)

Set the oversampling value for the temperature sensor. Default is 16x.

void set_pressure_oversampling(BME280Oversampling pressure_over_sampling)

Set the oversampling value for the pressure sensor. Default is 16x.

void set_humidity_oversampling(BME280Oversampling humidity_over_sampling)

Set the oversampling value for the humidity sensor. Default is 16x.

void set_iir_filter(BME280IIRFilter iir_filter)

Set the IIR Filter used to increase accuracy, defaults to no IIR Filter.

BME280TemperatureSensor *get_temperature_sensor() const
BME280PressureSensor *get_pressure_sensor() const
BME280HumiditySensor *get_humidity_sensor() const
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()

Protected Types

enum ErrorCode

Values:

NONE = 0
COMMUNICATION_FAILED
WRONG_CHIP_ID

Protected Functions

float read_temperature_(int32_t *t_fine)

Read the temperature value and store the calculated ambient temperature in t_fine.

float read_pressure_(int32_t t_fine)

Read the pressure value in hPa using the provided t_fine value.

float read_humidity_(int32_t t_fine)

Read the humidity value in % using the provided t_fine value.

uint8_t read_u8(uint8_t register_)
uint16_t read_u16_le(uint8_t register_)
int16_t read_s16_le(uint8_t register_)

Protected Attributes

BME280CalibrationData calibration_
BME280Oversampling temperature_oversampling_ = {BME280_OVERSAMPLING_16X}
BME280Oversampling pressure_oversampling_ = {BME280_OVERSAMPLING_16X}
BME280Oversampling humidity_oversampling_ = {BME280_OVERSAMPLING_16X}
BME280IIRFilter iir_filter_ = {BME280_IIR_FILTER_OFF}
BME280TemperatureSensor *temperature_sensor_
BME280PressureSensor *pressure_sensor_
BME280HumiditySensor *humidity_sensor_
sensor::BME280Component::ErrorCode NONE
enum sensor::BME280Oversampling

Enum listing all Oversampling values for the BME280.

Oversampling basically means measuring a condition multiple times. Higher oversampling values therefore increase the time required to read sensor values but increase accuracy.

Values:

BME280_OVERSAMPLING_NONE = 0b000
BME280_OVERSAMPLING_1X = 0b001
BME280_OVERSAMPLING_2X = 0b010
BME280_OVERSAMPLING_4X = 0b011
BME280_OVERSAMPLING_8X = 0b100
BME280_OVERSAMPLING_16X = 0b101
enum sensor::BME280IIRFilter

Enum listing all Infinite Impulse Filter values for the BME280.

Higher values increase accuracy, but decrease response time.

Values:

BME280_IIR_FILTER_OFF = 0b000
BME280_IIR_FILTER_2X = 0b001
BME280_IIR_FILTER_4X = 0b010
BME280_IIR_FILTER_8X = 0b011
BME280_IIR_FILTER_16X = 0b100
using sensor::BME280TemperatureSensor = typedef sensor::EmptyPollingParentSensor<1, ICON_EMPTY, UNIT_C>
using sensor::BME280PressureSensor = typedef sensor::EmptyPollingParentSensor<1, ICON_GAUGE, UNIT_HPA>
using sensor::BME280HumiditySensor = typedef sensor::EmptyPollingParentSensor<1, ICON_WATER_PERCENT, UNIT_PERCENT>
struct BME280CalibrationData

Internal struct storing the calibration values of an BME280.

Public Members

uint16_t t1
int16_t t2
int16_t t3
uint16_t p1
int16_t p2
int16_t p3
int16_t p4
int16_t p5
int16_t p6
int16_t p7
int16_t p8
int16_t p9
uint8_t h1
int16_t h2
uint8_t h3
int16_t h4
int16_t h5
int8_t h6