ESPHome 2025.5.0
Loading...
Searching...
No Matches
bme280_base.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome {
7namespace bme280_base {
8
11 uint16_t t1; // 0x88 - 0x89
12 int16_t t2; // 0x8A - 0x8B
13 int16_t t3; // 0x8C - 0x8D
14
15 uint16_t p1; // 0x8E - 0x8F
16 int16_t p2; // 0x90 - 0x91
17 int16_t p3; // 0x92 - 0x93
18 int16_t p4; // 0x94 - 0x95
19 int16_t p5; // 0x96 - 0x97
20 int16_t p6; // 0x98 - 0x99
21 int16_t p7; // 0x9A - 0x9B
22 int16_t p8; // 0x9C - 0x9D
23 int16_t p9; // 0x9E - 0x9F
24
25 uint8_t h1; // 0xA1
26 int16_t h2; // 0xE1 - 0xE2
27 uint8_t h3; // 0xE3
28 int16_t h4; // 0xE4 - 0xE5[3:0]
29 int16_t h5; // 0xE5[7:4] - 0xE6
30 int8_t h6; // 0xE7
31};
32
46
58
61 public:
62 void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
63 void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
64 void set_humidity_sensor(sensor::Sensor *humidity_sensor) { humidity_sensor_ = humidity_sensor; }
65
67 void set_temperature_oversampling(BME280Oversampling temperature_over_sampling);
69 void set_pressure_oversampling(BME280Oversampling pressure_over_sampling);
71 void set_humidity_oversampling(BME280Oversampling humidity_over_sampling);
73 void set_iir_filter(BME280IIRFilter iir_filter);
74
75 // ========== INTERNAL METHODS ==========
76 // (In most use cases you won't need these)
77 void setup() override;
78 void dump_config() override;
79 float get_setup_priority() const override;
80 void update() override;
81
82 protected:
84 float read_temperature_(const uint8_t *data, int32_t *t_fine);
86 float read_pressure_(const uint8_t *data, int32_t t_fine);
88 float read_humidity_(const uint8_t *data, int32_t t_fine);
89 uint8_t read_u8_(uint8_t a_register);
90 uint16_t read_u16_le_(uint8_t a_register);
91 int16_t read_s16_le_(uint8_t a_register);
92
93 virtual bool read_byte(uint8_t a_register, uint8_t *data) = 0;
94 virtual bool write_byte(uint8_t a_register, uint8_t data) = 0;
95 virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
96 virtual bool read_byte_16(uint8_t a_register, uint16_t *data) = 0;
97
111};
112
113} // namespace bme280_base
114} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:301
This class implements support for the BME280 Temperature+Pressure+Humidity sensor.
Definition bme280_base.h:60
uint8_t read_u8_(uint8_t a_register)
void set_pressure_sensor(sensor::Sensor *pressure_sensor)
Definition bme280_base.h:63
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:64
virtual bool read_byte_16(uint8_t a_register, uint16_t *data)=0
BME280CalibrationData calibration_
Definition bme280_base.h:98
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:99
void set_pressure_oversampling(BME280Oversampling pressure_over_sampling)
Set the oversampling value for the pressure sensor. Default is 16x.
BME280Oversampling humidity_oversampling_
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:62
float get_setup_priority() const override
BME280Oversampling pressure_oversampling_
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:57
BME280Oversampling
Enum listing all Oversampling values for the BME280.
Definition bme280_base.h:38
BME280IIRFilter
Enum listing all Infinite Impulse Filter values for the BME280.
Definition bme280_base.h:51
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:301
Internal struct storing the calibration values of an BME280.
Definition bme280_base.h:10