7 static const char *
const TAG =
"bmp085.sensor";
9 static const uint8_t BMP085_ADDRESS = 0x77;
10 static const uint8_t BMP085_REGISTER_AC1_H = 0xAA;
11 static const uint8_t BMP085_REGISTER_CONTROL = 0xF4;
12 static const uint8_t BMP085_REGISTER_DATA_MSB = 0xF6;
13 static const uint8_t BMP085_CONTROL_MODE_TEMPERATURE = 0x2E;
14 static const uint8_t BMP085_CONTROL_MODE_PRESSURE_3 = 0xF4;
17 if (!this->
set_mode_(BMP085_CONTROL_MODE_TEMPERATURE))
23 ESP_LOGCONFIG(TAG,
"Setting up BMP085...");
25 if (!this->
read_bytes(BMP085_REGISTER_AC1_H, data, 22)) {
37 this->
calibration_.
b1 = ((data[12] & 0xFF) << 8) | (data[13] & 0xFF);
38 this->
calibration_.
b2 = ((data[14] & 0xFF) << 8) | (data[15] & 0xFF);
39 this->
calibration_.
mb = ((data[16] & 0xFF) << 8) | (data[17] & 0xFF);
40 this->
calibration_.
mc = ((data[18] & 0xFF) << 8) | (data[19] & 0xFF);
41 this->
calibration_.
md = ((data[20] & 0xFF) << 8) | (data[21] & 0xFF);
44 ESP_LOGCONFIG(TAG,
"BMP085:");
47 ESP_LOGE(TAG,
"Connection with BMP085 failed!");
49 LOG_UPDATE_INTERVAL(
this);
52 LOG_SENSOR(
" ",
"Pressure", this->
pressure_);
58 if (!this->
read_bytes(BMP085_REGISTER_DATA_MSB, buffer, 2)) {
63 int32_t ut = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
65 ESP_LOGW(TAG,
"Invalid temperature!");
71 double c6 = this->calibration_.ac6;
75 double a = c5 * (ut - c6);
76 float temp = a + (mc / (a + md));
79 ESP_LOGD(TAG,
"Got Temperature=%.1f °C", temp);
84 if (!this->
set_mode_(BMP085_CONTROL_MODE_PRESSURE_3)) {
93 if (!this->
read_bytes(BMP085_REGISTER_DATA_MSB, buffer, 3)) {
98 uint32_t value = (uint32_t(buffer[0]) << 16) | (uint32_t(buffer[1]) << 8) | uint32_t(buffer[0]);
99 if ((value >> 5) == 0) {
100 ESP_LOGW(TAG,
"Invalid pressure!");
107 double b1 = pow(160.0, 2.0) * pow(2.0, -30.0) * this->
calibration_.
b1;
110 double x2 = pow(160.0, 2.0) * pow(2.0, -25.0) * this->
calibration_.
b2;
111 double y0 = c4 * pow(2.0, 15.0);
114 double p0 = (3791.0 - 8.0) / 1600.0;
115 double p1 = 1.0 - 7357.0 * pow(2, -20);
116 double p2 = 3038.0 * 100.0 * pow(2, -36);
118 double p = value / 256.0;
120 double x = (x2 * s * s) + (x1 * s) + x0;
121 double y = (y2 * s * s) + (y1 * s) + y0;
122 double z = (p -
x) / y;
123 float pressure = (p2 * z * z) + (p1 * z) + p0;
125 ESP_LOGD(TAG,
"Got Pressure=%.1f hPa", pressure);
132 ESP_LOGV(TAG,
"Setting mode to 0x%02X...", mode);
133 return this->
write_byte(BMP085_REGISTER_CONTROL, mode);
const float DATA
For components that import data from directly connected sensors like DHT.
void status_set_warning(const char *message="unspecified")
sensor::Sensor * temperature_
void setup() override
Setup the sensor and test for a connection.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
CalibrationData calibration_
void update() override
Schedule temperature+pressure readings.
sensor::Sensor * pressure_
void status_clear_warning()
void dump_config() override
BedjetMode mode
BedJet operating mode.
void publish_state(float state)
Publish a new state to the front-end.
bool set_mode_(uint8_t mode)
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
float get_setup_priority() const override
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
void read_pressure_()
Internal method to read the pressure from the component after it has been scheduled.
void read_temperature_()
Internal method to read the temperature from the component after it has been scheduled.