ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
bme280_base.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome::bme280_base {
7
10 uint16_t t1; // 0x88 - 0x89
11 int16_t t2; // 0x8A - 0x8B
12 int16_t t3; // 0x8C - 0x8D
13
14 uint16_t p1; // 0x8E - 0x8F
15 int16_t p2; // 0x90 - 0x91
16 int16_t p3; // 0x92 - 0x93
17 int16_t p4; // 0x94 - 0x95
18 int16_t p5; // 0x96 - 0x97
19 int16_t p6; // 0x98 - 0x99
20 int16_t p7; // 0x9A - 0x9B
21 int16_t p8; // 0x9C - 0x9D
22 int16_t p9; // 0x9E - 0x9F
23
24 uint8_t h1; // 0xA1
25 int16_t h2; // 0xE1 - 0xE2
26 uint8_t h3; // 0xE3
27 int16_t h4; // 0xE4 - 0xE5[3:0]
28 int16_t h5; // 0xE5[7:4] - 0xE6
29 int8_t h6; // 0xE7
30};
31
45
57
60 public:
61 void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
62 void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
63 void set_humidity_sensor(sensor::Sensor *humidity_sensor) { humidity_sensor_ = humidity_sensor; }
64
66 void set_temperature_oversampling(BME280Oversampling temperature_over_sampling);
68 void set_pressure_oversampling(BME280Oversampling pressure_over_sampling);
70 void set_humidity_oversampling(BME280Oversampling humidity_over_sampling);
72 void set_iir_filter(BME280IIRFilter iir_filter);
73
74 // ========== INTERNAL METHODS ==========
75 // (In most use cases you won't need these)
76 void setup() override;
77 void dump_config() override;
78 void update() override;
79
80 protected:
82 float read_temperature_(const uint8_t *data, int32_t *t_fine);
84 float read_pressure_(const uint8_t *data, int32_t t_fine);
86 float read_humidity_(const uint8_t *data, int32_t t_fine);
87 uint8_t read_u8_(uint8_t a_register);
88 uint16_t read_u16_le_(uint8_t a_register);
89 int16_t read_s16_le_(uint8_t a_register);
90
91 virtual bool read_byte(uint8_t a_register, uint8_t *data) = 0;
92 virtual bool write_byte(uint8_t a_register, uint8_t data) = 0;
93 virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
94 virtual bool read_byte_16(uint8_t a_register, uint16_t *data) = 0;
95
109};
110
111} // namespace esphome::bme280_base
This class simplifies creating components that periodically check a state.
Definition component.h:585
This class implements support for the BME280 Temperature+Pressure+Humidity sensor.
Definition bme280_base.h:59
uint8_t read_u8_(uint8_t a_register)
void set_pressure_sensor(sensor::Sensor *pressure_sensor)
Definition bme280_base.h:62
int16_t read_s16_le_(uint8_t a_register)
float read_humidity_(const uint8_t *data, int32_t t_fine)
Read the humidity value in % using the provided t_fine value.
virtual bool read_byte(uint8_t a_register, uint8_t *data)=0
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition bme280_base.h:63
virtual bool read_byte_16(uint8_t a_register, uint16_t *data)=0
BME280CalibrationData calibration_
Definition bme280_base.h:96
virtual bool write_byte(uint8_t a_register, uint8_t data)=0
void set_iir_filter(BME280IIRFilter iir_filter)
Set the IIR Filter used to increase accuracy, defaults to no IIR Filter.
void set_humidity_oversampling(BME280Oversampling humidity_over_sampling)
Set the oversampling value for the humidity sensor. Default is 16x.
BME280Oversampling temperature_oversampling_
Definition bme280_base.h:97
void set_pressure_oversampling(BME280Oversampling pressure_over_sampling)
Set the oversampling value for the pressure sensor. Default is 16x.
BME280Oversampling humidity_oversampling_
Definition bme280_base.h:99
float read_pressure_(const uint8_t *data, int32_t t_fine)
Read the pressure value in hPa using the provided t_fine value.
enum esphome::bme280_base::BME280Component::ErrorCode NONE
void set_temperature_oversampling(BME280Oversampling temperature_over_sampling)
Set the oversampling value for the temperature sensor. Default is 16x.
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition bme280_base.h:61
BME280Oversampling pressure_oversampling_
Definition bme280_base.h:98
uint16_t read_u16_le_(uint8_t a_register)
virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len)=0
float read_temperature_(const uint8_t *data, int32_t *t_fine)
Read the temperature value and store the calculated ambient temperature in t_fine.
Base-class for all sensors.
Definition sensor.h:47
BME280Oversampling
Enum listing all Oversampling values for the BME280.
Definition bme280_base.h:37
BME280IIRFilter
Enum listing all Infinite Impulse Filter values for the BME280.
Definition bme280_base.h:50
const void size_t len
Definition hal.h:64
Internal struct storing the calibration values of an BME280.
Definition bme280_base.h:9