ESPHome  2024.11.2
bme680.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace bme680 {
9 
20 };
21 
30 };
31 
34  uint16_t t1;
35  uint16_t t2;
36  uint8_t t3;
37 
38  uint16_t p1;
39  int16_t p2;
40  int8_t p3;
41  int16_t p4;
42  int16_t p5;
43  int8_t p6;
44  int8_t p7;
45  int16_t p8;
46  int16_t p9;
47  int8_t p10;
48 
49  uint16_t h1;
50  uint16_t h2;
51  int8_t h3;
52  int8_t h4;
53  int8_t h5;
54  uint8_t h6;
55  int8_t h7;
56 
57  int8_t gh1;
58  int16_t gh2;
59  int8_t gh3;
60 
61  uint8_t res_heat_range;
62  int8_t res_heat_val;
63  int8_t range_sw_err;
64 
65  float tfine;
67 };
68 
70  public:
72  void set_temperature_oversampling(BME680Oversampling temperature_oversampling);
74  void set_pressure_oversampling(BME680Oversampling pressure_oversampling);
76  void set_humidity_oversampling(BME680Oversampling humidity_oversampling);
78  void set_iir_filter(BME680IIRFilter iir_filter);
79 
80  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
81  void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
82  void set_humidity_sensor(sensor::Sensor *humidity_sensor) { humidity_sensor_ = humidity_sensor; }
83  void set_gas_resistance_sensor(sensor::Sensor *gas_resistance_sensor) {
84  gas_resistance_sensor_ = gas_resistance_sensor;
85  }
86 
96  void set_heater(uint16_t heater_temperature, uint16_t heater_duration);
97 
98  // ========== INTERNAL METHODS ==========
99  // (In most use cases you won't need these)
100  void setup() override;
101  void dump_config() override;
102  float get_setup_priority() const override;
103  void update() override;
104 
105  protected:
107  uint8_t calc_heater_resistance_(uint16_t temperature);
109  uint8_t calc_heater_duration_(uint16_t duration);
111  void read_data_();
112 
114  float calc_temperature_(uint32_t raw_temperature);
116  float calc_pressure_(uint32_t raw_pressure);
118  float calc_humidity_(uint16_t raw_humidity);
120  float calc_gas_resistance_(uint16_t raw_gas, uint8_t range);
122  uint32_t calc_meas_duration_();
123 
125  BME680Oversampling temperature_oversampling_{BME680_OVERSAMPLING_16X};
129  uint16_t heater_temperature_{320};
130  uint16_t heater_duration_{150};
131 
132  sensor::Sensor *temperature_sensor_{nullptr};
133  sensor::Sensor *pressure_sensor_{nullptr};
134  sensor::Sensor *humidity_sensor_{nullptr};
135  sensor::Sensor *gas_resistance_sensor_{nullptr};
136 };
137 
138 } // namespace bme680
139 } // namespace esphome
void setup()
BME680CalibrationData calibration_
Definition: bme680.h:124
BME680IIRFilter
Enum listing all IIR Filter options for the BME680.
Definition: bme680.h:11
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition: bme680.h:82
void set_pressure_sensor(sensor::Sensor *pressure_sensor)
Definition: bme680.h:81
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: bme680.h:80
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_gas_resistance_sensor(sensor::Sensor *gas_resistance_sensor)
Definition: bme680.h:83
uint16_t temperature
Definition: sun_gtil2.cpp:26
BME680Oversampling
Enum listing all oversampling options for the BME680.
Definition: bme680.h:23
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
Struct for storing calibration data for the BME680.
Definition: bme680.h:33
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133