Adafruit BME680 Library
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Adafruit_BME680 Class Reference

#include <Adafruit_BME680.h>

Public Member Functions

 Adafruit_BME680 (int8_t cspin=-1)
 Instantiates sensor with Hardware SPI or I2C. More...
 
 Adafruit_BME680 (int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin)
 Instantiates sensor with Software (bit-bang) SPI. More...
 
bool begin (uint8_t addr=BME680_DEFAULT_ADDRESS, bool initSettings=true)
 Initializes the sensor. More...
 
float readTemperature (void)
 Performs a reading and returns the ambient temperature. More...
 
float readPressure (void)
 Performs a reading and returns the barometric pressure. More...
 
float readHumidity (void)
 Performs a reading and returns the relative humidity. More...
 
uint32_t readGas (void)
 Calculates the resistance of the MOX gas sensor. More...
 
float readAltitude (float seaLevel)
 Calculates the altitude (in meters). More...
 
bool setTemperatureOversampling (uint8_t os)
 Setter for Temperature oversampling. More...
 
bool setPressureOversampling (uint8_t os)
 Setter for Pressure oversampling. More...
 
bool setHumidityOversampling (uint8_t os)
 Setter for Humidity oversampling. More...
 
bool setIIRFilterSize (uint8_t fs)
 Setter for IIR filter. More...
 
bool setGasHeater (uint16_t heaterTemp, uint16_t heaterTime)
 Enable and configure gas reading + heater. More...
 
bool performReading (void)
 Perform a reading in blocking mode. More...
 
unsigned long beginReading (void)
 Begin an asynchronous reading. More...
 
bool endReading (void)
 End an asynchronous reading. More...
 
int remainingReadingMillis (void)
 Get remaining time for an asynchronous reading. More...
 

Public Attributes

float temperature
 Temperature (Celsius) assigned after calling performReading() or endReading()
 
uint32_t pressure
 Pressure (Pascals) assigned after calling performReading() or endReading()
 
float humidity
 Humidity (RH %) assigned after calling performReading() or endReading()
 
uint32_t gas_resistance
 Gas resistor (ohms) assigned after calling performReading() or endReading()
 

Static Public Attributes

static constexpr int reading_not_started = -1
 Value returned by remainingReadingMillis indicating no asynchronous reading has been initiated by beginReading.
 
static constexpr int reading_complete = 0
 Value returned by remainingReadingMillis indicating asynchronous reading is complete and calling endReading will not block.
 

Detailed Description

Adafruit_BME680 Class for both I2C and SPI usage. Wraps the Bosch library for Arduino usage

Constructor & Destructor Documentation

◆ Adafruit_BME680() [1/2]

Adafruit_BME680::Adafruit_BME680 ( int8_t  cspin = -1)

Instantiates sensor with Hardware SPI or I2C.

Parameters
cspinSPI chip select. If not passed in, I2C will be used

◆ Adafruit_BME680() [2/2]

Adafruit_BME680::Adafruit_BME680 ( int8_t  cspin,
int8_t  mosipin,
int8_t  misopin,
int8_t  sckpin 
)

Instantiates sensor with Software (bit-bang) SPI.

Parameters
cspinSPI chip select
mosipinSPI MOSI (Data from microcontroller to sensor)
misopinSPI MISO (Data to microcontroller from sensor)
sckpinSPI Clock

Member Function Documentation

◆ begin()

bool Adafruit_BME680::begin ( uint8_t  addr = BME680_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.

Parameters
addrOptional parameter for the I2C address of BME680. Default is 0x77
initSettingsOptional parameter for initializing the sensor settings. Default is true.
Returns
True on sensor initialization success. False on failure.

◆ readTemperature()

float Adafruit_BME680::readTemperature ( void  )

Performs a reading and returns the ambient temperature.

Returns
Temperature in degrees Centigrade

◆ readPressure()

float Adafruit_BME680::readPressure ( void  )

Performs a reading and returns the barometric pressure.

Returns
Barometic pressure in Pascals

◆ readHumidity()

float Adafruit_BME680::readHumidity ( void  )

Performs a reading and returns the relative humidity.

Returns
Relative humidity as floating point

◆ readGas()

uint32_t Adafruit_BME680::readGas ( void  )

Calculates the resistance of the MOX gas sensor.

Returns
Resistance in Ohms

◆ readAltitude()

float Adafruit_BME680::readAltitude ( float  seaLevel)

Calculates the altitude (in meters).

Reads the current atmostpheric pressure (in hPa) from the sensor and calculates via the provided sea-level pressure (in hPa).

Parameters
seaLevelSea-level pressure in hPa
Returns
Altitude in meters

◆ setTemperatureOversampling()

bool Adafruit_BME680::setTemperatureOversampling ( uint8_t  oversample)

Setter for Temperature oversampling.

Parameters
oversampleOversampling setting, can be BME680_OS_NONE (turn off Temperature reading), BME680_OS_1X, BME680_OS_2X, BME680_OS_4X, BME680_OS_8X or BME680_OS_16X
Returns
True on success, False on failure

◆ setPressureOversampling()

bool Adafruit_BME680::setPressureOversampling ( uint8_t  oversample)

Setter for Pressure oversampling.

Parameters
oversampleOversampling setting, can be BME680_OS_NONE (turn off Pressure reading), BME680_OS_1X, BME680_OS_2X, BME680_OS_4X, BME680_OS_8X or BME680_OS_16X
Returns
True on success, False on failure

◆ setHumidityOversampling()

bool Adafruit_BME680::setHumidityOversampling ( uint8_t  oversample)

Setter for Humidity oversampling.

Parameters
oversampleOversampling setting, can be BME680_OS_NONE (turn off Humidity reading), BME680_OS_1X, BME680_OS_2X, BME680_OS_4X, BME680_OS_8X or BME680_OS_16X
Returns
True on success, False on failure

◆ setIIRFilterSize()

bool Adafruit_BME680::setIIRFilterSize ( uint8_t  filtersize)

Setter for IIR filter.

Parameters
filtersizeSize of the filter (in samples). Can be BME680_FILTER_SIZE_0 (no filtering), BME680_FILTER_SIZE_1, BME680_FILTER_SIZE_3, BME680_FILTER_SIZE_7, BME680_FILTER_SIZE_15, BME680_FILTER_SIZE_31, BME680_FILTER_SIZE_63, BME680_FILTER_SIZE_127
Returns
True on success, False on failure

◆ setGasHeater()

bool Adafruit_BME680::setGasHeater ( uint16_t  heaterTemp,
uint16_t  heaterTime 
)

Enable and configure gas reading + heater.

Parameters
heaterTempDesired temperature in degrees Centigrade
heaterTimeTime to keep heater on in milliseconds
Returns
True on success, False on failure

◆ performReading()

bool Adafruit_BME680::performReading ( void  )

Perform a reading in blocking mode.

Performs a full reading of all 4 sensors in the BME680.

Assigns the internal Adafruit_BME680::temperature, Adafruit_BME680::pressure, Adafruit_BME680::humidity and Adafruit_BME680::gas_resistance member variables

Returns
True on success, False on failure

◆ beginReading()

unsigned long Adafruit_BME680::beginReading ( void  )

Begin an asynchronous reading.

Returns
When the reading would be ready as absolute time in millis().

◆ endReading()

bool Adafruit_BME680::endReading ( void  )

End an asynchronous reading.

Returns
Whether success.

If the asynchronous reading is still in progress, block until it ends. If no asynchronous reading has started, this is equivalent to performReading().

◆ remainingReadingMillis()

int Adafruit_BME680::remainingReadingMillis ( void  )

Get remaining time for an asynchronous reading.

Returns
Remaining millis until endReading will not block if invoked.

If the asynchronous reading is still in progress, how many millis until its completion. If the asynchronous reading is completed, 0. If no asynchronous reading has started, -1 or Adafruit_BME680::reading_not_started.

Does not block.


The documentation for this class was generated from the following files: