ESPHome  2022.9.3
bme280.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace bme280 {
9 
12  uint16_t t1; // 0x88 - 0x89
13  int16_t t2; // 0x8A - 0x8B
14  int16_t t3; // 0x8C - 0x8D
15 
16  uint16_t p1; // 0x8E - 0x8F
17  int16_t p2; // 0x90 - 0x91
18  int16_t p3; // 0x92 - 0x93
19  int16_t p4; // 0x94 - 0x95
20  int16_t p5; // 0x96 - 0x97
21  int16_t p6; // 0x98 - 0x99
22  int16_t p7; // 0x9A - 0x9B
23  int16_t p8; // 0x9C - 0x9D
24  int16_t p9; // 0x9E - 0x9F
25 
26  uint8_t h1; // 0xA1
27  int16_t h2; // 0xE1 - 0xE2
28  uint8_t h3; // 0xE3
29  int16_t h4; // 0xE4 - 0xE5[3:0]
30  int16_t h5; // 0xE5[7:4] - 0xE6
31  int8_t h6; // 0xE7
32 };
33 
46 };
47 
58 };
59 
62  public:
63  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
64  void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
65  void set_humidity_sensor(sensor::Sensor *humidity_sensor) { humidity_sensor_ = humidity_sensor; }
66 
68  void set_temperature_oversampling(BME280Oversampling temperature_over_sampling);
70  void set_pressure_oversampling(BME280Oversampling pressure_over_sampling);
72  void set_humidity_oversampling(BME280Oversampling humidity_over_sampling);
74  void set_iir_filter(BME280IIRFilter iir_filter);
75 
76  // ========== INTERNAL METHODS ==========
77  // (In most use cases you won't need these)
78  void setup() override;
79  void dump_config() override;
80  float get_setup_priority() const override;
81  void update() override;
82 
83  protected:
85  float read_temperature_(const uint8_t *data, int32_t *t_fine);
87  float read_pressure_(const uint8_t *data, int32_t t_fine);
89  float read_humidity_(const uint8_t *data, int32_t t_fine);
90  uint8_t read_u8_(uint8_t a_register);
91  uint16_t read_u16_le_(uint8_t a_register);
92  int16_t read_s16_le_(uint8_t a_register);
93 
95  BME280Oversampling temperature_oversampling_{BME280_OVERSAMPLING_16X};
99  sensor::Sensor *temperature_sensor_{nullptr};
100  sensor::Sensor *pressure_sensor_{nullptr};
101  sensor::Sensor *humidity_sensor_{nullptr};
102  enum ErrorCode {
103  NONE = 0,
106  } error_code_{NONE};
107 };
108 
109 } // namespace bme280
110 } // namespace esphome
void setup()
Internal struct storing the calibration values of an BME280.
Definition: bme280.h:11
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition: bme280.h:65
This class simplifies creating components that periodically check a state.
Definition: component.h:266
This class implements support for the BME280 Temperature+Pressure+Humidity i2c sensor.
Definition: bme280.h:61
BME280Oversampling
Enum listing all Oversampling values for the BME280.
Definition: bme280.h:39
BME280IIRFilter
Enum listing all Infinite Impulse Filter values for the BME280.
Definition: bme280.h:52
Definition: a4988.cpp:4
void set_pressure_sensor(sensor::Sensor *pressure_sensor)
Definition: bme280.h:64
BME280CalibrationData calibration_
Definition: bme280.h:94
Base-class for all sensors.
Definition: sensor.h:48
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: bme280.h:63