Adafruit BME680 Library
Adafruit_BME680.h
Go to the documentation of this file.
1 
24 #ifndef __BME680_H__
25 #define __BME680_H__
26 
27 #include "Arduino.h"
28 
29 #include "bme68x.h"
30 #include <Adafruit_I2CDevice.h>
31 #include <Adafruit_SPIDevice.h>
32 #include <Adafruit_Sensor.h>
33 #include <Wire.h>
34 
35 #define BME68X_DEFAULT_ADDRESS (0x77)
36 #define BME68X_DEFAULT_SPIFREQ (1000000)
37 
38 #define BME680_OS_16X BME68X_OS_16X
39 #define BME680_OS_8X BME68X_OS_8X
40 #define BME680_OS_4X BME68X_OS_4X
41 #define BME680_OS_2X BME68X_OS_2X
42 #define BME680_OS_1X BME68X_OS_1X
43 #define BME680_OS_NONE BME68X_OS_NONE
44 
45 #define BME680_FILTER_SIZE_127 \
46  BME68X_FILTER_SIZE_127
47 #define BME680_FILTER_SIZE_63 \
48  BME68X_FILTER_SIZE_63
49 #define BME680_FILTER_SIZE_31 \
50  BME68X_FILTER_SIZE_31
51 #define BME680_FILTER_SIZE_15 \
52  BME68X_FILTER_SIZE_15
53 #define BME680_FILTER_SIZE_7 \
54  BME68X_FILTER_SIZE_7
55 #define BME680_FILTER_SIZE_3 \
56  BME68X_FILTER_SIZE_3
57 #define BME680_FILTER_SIZE_1 \
58  BME68X_FILTER_SIZE_1
59 #define BME680_FILTER_SIZE_0 \
60  BME68X_FILTER_OFF
61 
62 
66 public:
69  static constexpr int reading_not_started = -1;
72  static constexpr int reading_complete = 0;
73 
74  Adafruit_BME680(TwoWire *theWire = &Wire);
75  Adafruit_BME680(int8_t cspin, SPIClass *theSPI = &SPI);
76  Adafruit_BME680(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);
77 
78  bool begin(uint8_t addr = BME68X_DEFAULT_ADDRESS, bool initSettings = true);
79  float readTemperature();
80  float readPressure();
81  float readHumidity();
82  uint32_t readGas();
83  float readAltitude(float seaLevel);
84 
85  bool setTemperatureOversampling(uint8_t os);
86  bool setPressureOversampling(uint8_t os);
87  bool setHumidityOversampling(uint8_t os);
88  bool setIIRFilterSize(uint8_t fs);
89  bool setGasHeater(uint16_t heaterTemp, uint16_t heaterTime);
90  bool setODR(uint8_t odr);
91 
92  // Perform a reading in blocking mode.
93  bool performReading();
94 
95  uint32_t beginReading();
96 
97  bool endReading();
98 
100 
103  float temperature;
106  uint32_t pressure;
109  float humidity;
112  uint32_t gas_resistance;
113 
114 private:
115  Adafruit_I2CDevice *_i2cdev = NULL;
116  Adafruit_SPIDevice *_spidev = NULL;
117  TwoWire *_wire = NULL;
118 
119  int32_t _sensorID;
120  uint32_t _meas_start = 0;
121  uint16_t _meas_period = 0;
122 
123  struct bme68x_dev gas_sensor;
124  struct bme68x_conf gas_conf;
125  struct bme68x_heatr_conf gas_heatr_conf;
126 };
127 
128 #endif
bool setIIRFilterSize(uint8_t fs)
Setter for IIR filter.
Definition: Adafruit_BME680.cpp:535
bool begin(uint8_t addr=BME68X_DEFAULT_ADDRESS, bool initSettings=true)
Initializes the sensor Hardware ss initialized, verifies it is in the I2C or SPI bus, then reads calibration data in preparation for sensor reads.
Definition: Adafruit_BME680.cpp:100
bool setTemperatureOversampling(uint8_t os)
Setter for Temperature oversampling.
Definition: Adafruit_BME680.cpp:468
uint32_t beginReading()
Begin an asynchronous reading.
Definition: Adafruit_BME680.cpp:296
float readTemperature()
Performs a reading and returns the ambient temperature.
Definition: Adafruit_BME680.cpp:232
bool performReading()
Performs a full reading of all 4 sensors in the BME680. Assigns the internal Adafruit_BME680::tempera...
Definition: Adafruit_BME680.cpp:291
bool setGasHeater(uint16_t heaterTemp, uint16_t heaterTime)
Enable and configure gas reading + heater.
Definition: Adafruit_BME680.cpp:417
Definition: Adafruit_BME680.h:65
float readAltitude(float seaLevel)
Calculates the altitude (in meters). Reads the current atmostpheric pressure (in hPa) from the sensor...
Definition: Adafruit_BME680.cpp:272
bool setODR(uint8_t odr)
Setter for Output Data Rate.
Definition: Adafruit_BME680.cpp:445
bool setHumidityOversampling(uint8_t os)
Setter for Humidity oversampling.
Definition: Adafruit_BME680.cpp:490
#define BME68X_DEFAULT_ADDRESS
The default I2C address.
Definition: Adafruit_BME680.h:35
Adafruit_BME680(TwoWire *theWire=&Wire)
Instantiates sensor with i2c.
Definition: Adafruit_BME680.cpp:53
uint32_t readGas()
Calculates the resistance of the MOX gas sensor.
Definition: Adafruit_BME680.cpp:259
static constexpr int reading_not_started
Definition: Adafruit_BME680.h:69
float humidity
Definition: Adafruit_BME680.h:109
static constexpr int reading_complete
Definition: Adafruit_BME680.h:72
float readPressure()
Performs a reading and returns the barometric pressure.
Definition: Adafruit_BME680.cpp:241
float readHumidity()
Performs a reading and returns the relative humidity.
Definition: Adafruit_BME680.cpp:250
float temperature
Definition: Adafruit_BME680.h:103
bool setPressureOversampling(uint8_t os)
Setter for Pressure oversampling.
Definition: Adafruit_BME680.cpp:512
uint32_t gas_resistance
Definition: Adafruit_BME680.h:112
uint32_t pressure
Definition: Adafruit_BME680.h:106
int remainingReadingMillis()
Get remaining time for an asynchronous reading. If the asynchronous reading is still in progress...
Definition: Adafruit_BME680.cpp:400
bool endReading()
End an asynchronous reading. If the asynchronous reading is still in progress, block until it ends...
Definition: Adafruit_BME680.cpp:331