5#define BMP280_ERROR_WRONG_CHIP_ID "Wrong chip ID or no response"
9static const char *
const TAG =
"bmp280.sensor";
11static const uint8_t BMP280_REGISTER_STATUS = 0xF3;
12static const uint8_t BMP280_REGISTER_CONTROL = 0xF4;
13static const uint8_t BMP280_REGISTER_CONFIG = 0xF5;
14static const uint8_t BMP280_REGISTER_PRESSUREDATA = 0xF7;
15static const uint8_t BMP280_REGISTER_TEMPDATA = 0xFA;
16static const uint8_t BMP280_REGISTER_RESET = 0xE0;
18static const uint8_t BMP280_MODE_FORCED = 0b01;
19static const uint8_t BMP280_SOFT_RESET = 0xB6;
20static const uint8_t BMP280_STATUS_IM_UPDATE = 0b01;
22inline uint16_t
combine_bytes(uint8_t msb, uint8_t lsb) {
return ((msb & 0xFF) << 8) | (lsb & 0xFF); }
25 switch (oversampling) {
75 if (chip_id != 0x58) {
77 this->
mark_failed(LOG_STR(BMP280_ERROR_WRONG_CHIP_ID));
82 if (!this->
bmp_write_byte(BMP280_REGISTER_RESET, BMP280_SOFT_RESET)) {
92 this->
mark_failed(LOG_STR(
"Error reading status register"));
95 }
while ((
status & BMP280_STATUS_IM_UPDATE) && (--retry));
96 if (
status & BMP280_STATUS_IM_UPDATE) {
116 uint8_t config_register = 0;
117 if (!this->
bmp_read_byte(BMP280_REGISTER_CONFIG, &config_register)) {
121 config_register &= ~0b11111100;
122 config_register |= 0b000 << 5;
123 config_register |= (this->
iir_filter_ & 0b111) << 2;
124 if (!this->
bmp_write_byte(BMP280_REGISTER_CONFIG, config_register)) {
130 ESP_LOGCONFIG(TAG,
"BMP280:");
131 switch (this->error_code_) {
133 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
136 ESP_LOGE(TAG, BMP280_ERROR_WRONG_CHIP_ID);
142 ESP_LOGCONFIG(TAG,
" IIR Filter: %s", iir_filter_to_str(this->
iir_filter_));
143 LOG_UPDATE_INTERVAL(
this);
155 ESP_LOGV(TAG,
"Sending conversion request");
156 uint8_t meas_value = 0;
173 ESP_LOGW(TAG,
"Invalid temperature");
192 ESP_LOGV(TAG,
"Read temperature data, raw: %02X %02X %02X", data[0], data[1], data[2]);
193 int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF);
195 if (adc == 0x80000) {
204 int32_t var1 = (((adc >> 3) - (t1 << 1)) * t2) >> 11;
205 int32_t var2 = (((((adc >> 4) - t1) * ((adc >> 4) - t1)) >> 12) * t3) >> 14;
206 *t_fine = var1 + var2;
216 int32_t adc = ((data[0] & 0xFF) << 16) | ((data[1] & 0xFF) << 8) | (data[2] & 0xFF);
218 if (adc == 0x80000) {
232 int64_t var1, var2, p;
233 var1 = int64_t(t_fine) - 128000;
234 var2 = var1 * var1 * p6;
235 var2 = var2 + ((var1 * p5) << 17);
236 var2 = var2 + (p4 << 35);
237 var1 = ((var1 * var1 * p3) >> 8) + ((var1 * p2) << 12);
238 var1 = ((int64_t(1) << 47) + var1) * p1 >> 33;
244 p = (((p << 31) - var2) * 3125) / var1;
245 var1 = (p9 * (p >> 13) * (p >> 13)) >> 25;
246 var2 = (p8 * p) >> 19;
248 p = ((p + var1 + var2) >> 8) + (p7 << 4);
249 return (p / 256.0f) / 100.0f;
266 return (data >> 8) | (data << 8);
void mark_failed()
Mark this component as failed.
void status_set_warning()
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void status_clear_warning()
virtual bool bmp_write_byte(uint8_t a_register, uint8_t data)=0
enum esphome::bmp280_base::BMP280Component::ErrorCode NONE
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
virtual bool bmp_read_byte_16(uint8_t a_register, uint16_t *data)=0
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 set_iir_filter(BMP280IIRFilter iir_filter)
Set the IIR Filter used to increase accuracy, defaults to no IIR Filter.
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.
BMP280Oversampling
Enum listing all Oversampling values for the BMP280.
@ BMP280_OVERSAMPLING_16X
@ BMP280_OVERSAMPLING_NONE
uint8_t oversampling_to_time(BMP280Oversampling over_sampling)
void HOT delay(uint32_t ms)