10static constexpr uint32_t DATA_TIMEOUT_ID = 0;
12static const uint8_t BMP280_REGISTER_STATUS = 0xF3;
13static const uint8_t BMP280_REGISTER_CONTROL = 0xF4;
14static const uint8_t BMP280_REGISTER_CONFIG = 0xF5;
15static const uint8_t BMP280_REGISTER_PRESSUREDATA = 0xF7;
16static const uint8_t BMP280_REGISTER_TEMPDATA = 0xFA;
17static const uint8_t BMP280_REGISTER_RESET = 0xE0;
19static const uint8_t BMP280_MODE_FORCED = 0b01;
20static const uint8_t BMP280_SOFT_RESET = 0xB6;
21static const uint8_t BMP280_STATUS_IM_UPDATE = 0b01;
23inline uint16_t
combine_bytes(uint8_t msb, uint8_t lsb) {
return ((msb & 0xFF) << 8) | (lsb & 0xFF); }
26 switch (oversampling) {
74 if (chip_id != 0x58) {
75 this->
mark_failed(LOG_STR(
"Wrong chip ID or no response"));
80 if (!this->
bmp_write_byte(BMP280_REGISTER_RESET, BMP280_SOFT_RESET)) {
90 this->
mark_failed(LOG_STR(
"Error reading status register"));
93 }
while ((
status & BMP280_STATUS_IM_UPDATE) && (--retry));
94 if (
status & BMP280_STATUS_IM_UPDATE) {
114 uint8_t config_register = 0;
115 if (!this->
bmp_read_byte(BMP280_REGISTER_CONFIG, &config_register)) {
119 config_register &= ~0b11111100;
120 config_register |= 0b000 << 5;
121 config_register |= (this->
iir_filter_ & 0b111) << 2;
122 if (!this->
bmp_write_byte(BMP280_REGISTER_CONFIG, config_register)) {
128 ESP_LOGCONFIG(TAG,
"BMP280:");
129 ESP_LOGCONFIG(TAG,
" IIR Filter: %s", iir_filter_to_str(this->
iir_filter_));
130 LOG_UPDATE_INTERVAL(
this);
142 ESP_LOGV(TAG,
"Sending conversion request");
143 uint8_t meas_value = 0;
160 ESP_LOGW(TAG,
"Invalid temperature");
179 ESP_LOGV(TAG,
"Read temperature data, raw: %02X %02X %02X", data[0], data[1], data[2]);
182 if (adc == 0x80000) {
191 int32_t var1 = (((adc >> 3) - (t1 << 1)) * t2) >> 11;
192 int32_t var2 = (((((adc >> 4) - t1) * ((adc >> 4) - t1)) >> 12) * t3) >> 14;
193 *t_fine = var1 + var2;
205 if (adc == 0x80000) {
219 int64_t var1, var2, p;
220 var1 = int64_t(t_fine) - 128000;
221 var2 = var1 * var1 * p6;
222 var2 = var2 + ((var1 * p5) << 17);
223 var2 = var2 + (p4 << 35);
224 var1 = ((var1 * var1 * p3) >> 8) + ((var1 * p2) << 12);
225 var1 = ((int64_t(1) << 47) + var1) * p1 >> 33;
231 p = (((p << 31) - var2) * 3125) / var1;
232 var1 = (p9 * (p >> 13) * (p >> 13)) >> 25;
233 var2 = (p8 * p) >> 19;
235 p = ((p + var1 + var2) >> 8) + (p7 << 4);
236 return (p / 256.0f) / 100.0f;
void mark_failed()
Mark this component as failed.
void status_set_warning()
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void status_clear_warning()
virtual bool bmp_write_byte(uint8_t a_register, uint8_t data)=0
virtual bool bmp_read_byte_16_le(uint8_t a_register, uint16_t *data)=0
uint8_t read_u8_(uint8_t a_register)
virtual bool bmp_read_bytes(uint8_t a_register, uint8_t *data, size_t len)=0
uint16_t read_u16_le_(uint8_t a_register)
void dump_config() override
int16_t read_s16_le_(uint8_t a_register)
float read_pressure_(int32_t t_fine)
Read the pressure value in hPa using the provided t_fine value.
BMP280IIRFilter iir_filter_
sensor::Sensor * temperature_sensor_
BMP280Oversampling pressure_oversampling_
virtual bool bmp_read_byte(uint8_t a_register, uint8_t *data)=0
float read_temperature_(int32_t *t_fine)
Read the temperature value and store the calculated ambient temperature in t_fine.
void set_pressure_oversampling(BMP280Oversampling pressure_over_sampling)
Set the oversampling value for the pressure sensor. Default is 16x.
BMP280Oversampling temperature_oversampling_
void set_temperature_oversampling(BMP280Oversampling temperature_over_sampling)
Set the oversampling value for the temperature sensor. Default is 16x.
sensor::Sensor * pressure_sensor_
BMP280CalibrationData calibration_
void publish_state(float state)
Publish a new state to the front-end.
const char * iir_filter_to_str(BME280IIRFilter filter)
uint16_t combine_bytes(uint8_t msb, uint8_t lsb)
BMP280IIRFilter
Enum listing all Infinite Impulse Filter values for the BMP280.
ESPHOME_LOG_TAG(TAG, "bmp280.sensor")
BMP280Oversampling
Enum listing all Oversampling values for the BMP280.
@ BMP280_OVERSAMPLING_16X
@ BMP280_OVERSAMPLING_NONE
uint8_t oversampling_to_time(BMP280Oversampling over_sampling)
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
void HOT delay(uint32_t ms)