Main BME680 class for the temperature / humidity / pressure sensor.
More...
#include <Zanshin_BME680.h>
Inherited by BME680.
|
| BME680_Class () |
|
| ~BME680_Class () |
|
bool | begin () |
|
bool | begin (const uint32_t i2cSpeed) |
|
bool | begin (const uint8_t chipSelect) |
|
bool | begin (const uint32_t i2cSpeed, const uint8_t i2cAddress) |
|
bool | begin (const uint8_t chipSelect, const uint8_t mosi, const uint8_t miso, const uint8_t sck) |
|
uint8_t | setOversampling (const uint8_t sensor, const uint8_t sampling=UINT8_MAX) const |
|
bool | setGas (uint16_t GasTemp, uint16_t GasMillis) const |
|
uint8_t | setIIRFilter (const uint8_t iirFilterSetting=UINT8_MAX) const |
|
uint8_t | getSensorData (int32_t &temp, int32_t &hum, int32_t &press, int32_t &gas, const bool waitSwitch=true) |
|
uint8_t | getI2CAddress () const |
|
void | reset () |
|
bool | measuring () const |
| true if currently measuring
|
|
void | triggerMeasurement () const |
| trigger a measurement
|
|
|
bool | commonInitialization () |
| Common initialization code.
|
|
uint8_t | readByte (const uint8_t addr) const |
| Read byte from register address.
|
|
uint8_t | readSensors (const bool waitSwitch) |
| read the registers in one burst
|
|
void | waitForReadings () const |
| Wait for readings to finish.
|
|
void | getCalibration () |
| Load calibration from registers.
|
|
template<typename T > |
uint8_t & | getData (const uint8_t addr, T &value) const |
|
template<typename T > |
uint8_t & | putData (const uint8_t addr, const T &value) const |
|
Main BME680 class for the temperature / humidity / pressure sensor.
◆ BME680_Class()
BME680_Class::BME680_Class |
( |
| ) |
|
Class constructor
Currently empty and unused
◆ ~BME680_Class()
BME680_Class::~BME680_Class |
( |
| ) |
|
Class destructor
Currently empty and unused
◆ begin() [1/5]
bool BME680_Class::begin |
( |
| ) |
|
starts communications with device (overloaded)
When called with no parameters the I2C protocol with I2C_STANDARD_MODE speed is selected. The I2C network is searched for the first BME680 device. return "true" if successful otherwise false
◆ begin() [2/5]
bool BME680_Class::begin |
( |
const uint32_t | i2cSpeed | ) |
|
starts communications with device (overloaded)
When called with a 32-bit parameter it is assumed that the I2C protocol is to be used and the speed setting is determined by the parameter.
- Parameters
-
[in] | i2cSpeed | I2C Speed value return "true" if successful otherwise false |
◆ begin() [3/5]
bool BME680_Class::begin |
( |
const uint32_t | i2cSpeed, |
|
|
const uint8_t | i2cAddress ) |
starts communications with device (overloaded)
When called with a 32-bit parameter it is assumed that the I2C protocol is to be used and the speed setting is determined by the parameter. If the i2cAddress is 0 then check both, otherwise check only only the specified address
- Parameters
-
[in] | i2cSpeed | I2C Speed value |
[in] | i2cAddress | I2C Address, use 0 to self-determine return "true" if successful otherwise false |
◆ begin() [4/5]
bool BME680_Class::begin |
( |
const uint8_t | chipSelect | ) |
|
starts communications with device (overloaded)
When called with a single 8-bit parameter is assumed that hardware SPI is to be used if the value is not 0x76 or 0x77, in which case it is assumed that it is the I2C addr
- Parameters
-
[in] | chipSelect | Arduino Pin number for the Slave-Select pin or the I2C address return "true" if successful otherwise false |
◆ begin() [5/5]
bool BME680_Class::begin |
( |
const uint8_t | chipSelect, |
|
|
const uint8_t | mosi, |
|
|
const uint8_t | miso, |
|
|
const uint8_t | sck ) |
starts communications with device (overloaded)
When called with 4 parameters then software SPI is assumed
- Parameters
-
[in] | chipSelect | Arduino Pin number for the Slave-Select pin |
[in] | mosi | Arduino Pin number for the Master-out-Slave-in pin |
[in] | miso | Arduino Pin number for the Master-in-Slave-out pin |
[in] | sck | Arduino Pin number for the System clock pin return "true" if successful otherwise false |
◆ commonInitialization()
bool BME680_Class::commonInitialization |
( |
| ) |
|
|
private |
Common initialization code.
Common BME680 initialization function
Called from all of the overloaded "begin()" functions once the communications protocol has been selected return "true" if successful otherwise false
◆ getCalibration()
void BME680_Class::getCalibration |
( |
| ) |
|
|
private |
Load calibration from registers.
reads the calibration register data into local variables for use in converting readings
The calibration registers are read into a temporary array and then parsed into the appropriate calibration variables, this was taken from the example BOSCH software and minimizes register reads, but makes it rather difficult to read. This will be redone for legibility at some point in the future param[in] addr Address of device return single byte read
◆ getData()
template<typename T >
uint8_t & BME680_Class::getData |
( |
const uint8_t | addr, |
|
|
T & | value ) const |
|
inlineprivate |
functions
Declare the getData and putData methods as template functions. All device I/O is done through these two functions regardless of whether I2C, hardware SPI or software SPI is being used. The two functions are designed so that only the address and a variable are passed in and the functions determine the size of the parameter variable and reads or writes that many bytes. So if a read is called using a character array[10] then 10 bytes are read, if called with a int8 then only one byte is read. The return value, if used, is the number of bytes read or written. Since this is implemented by using template function definitions, they need to be defined in this header file rather than in the c++ program library file. The "getData()" function is currently not used in the library directly, but the function "readByte()" is used which calls the getData(). The "putData()" is called directly in the code.
Template for reading from I2C or SPI using any data type
As a template it can support compile-time data type definitions
- Parameters
-
[in] | addr | Memory address |
[in] | value | Data Type "T" to read |
- Returns
- Size of data read in bytes
◆ getI2CAddress()
uint8_t BME680_Class::getI2CAddress |
( |
| ) |
const |
Returns the I2C address of the BME680 return I2C Address from private variables
◆ getSensorData()
uint8_t BME680_Class::getSensorData |
( |
int32_t & | temp, |
|
|
int32_t & | hum, |
|
|
int32_t & | press, |
|
|
int32_t & | gas, |
|
|
const bool | waitSwitch = true ) |
Returns the most recent temperature, humidity and pressure readings param[out] temp Temperature reading param[out] hum Humidity reading param[out] press Pressure reading param[out] gas Gas reading param[in] waitSwitch (Optional) When set will not return until reading is finished
◆ measuring()
bool BME680_Class::measuring |
( |
| ) |
const |
true if currently measuring
Returns whether the BME680 is currently measuring return "true" if a measurement is active, otherwise "false"
◆ putData()
template<typename T >
uint8_t & BME680_Class::putData |
( |
const uint8_t | addr, |
|
|
const T & | value ) const |
|
inlineprivate |
Template for writing to I2C or SPI using any data type
As a template it can support compile-time data type definitions
- Parameters
-
[in] | addr | Memory address |
[in] | value | Data Type "T" to write |
- Returns
- Size of data written in bytes
◆ readByte()
uint8_t BME680_Class::readByte |
( |
const uint8_t | addr | ) |
const |
|
private |
Read byte from register address.
Read a single byte from the given address
interlude function to the "getData()" function. This is called so that the return value is the byte of data that has just been read rather than the number of bytes read returned by "getData()" param[in] addr Address of device return single byte of read from addr
◆ readSensors()
uint8_t BME680_Class::readSensors |
( |
const bool | waitSwitch | ) |
|
|
private |
read the registers in one burst
reads all 4 sensor values from the registers in one operation and then proceeds to convert the raw temperature, pressure & humidity readings into standard metric units
The formula is written in the BME680's documentation but the math used below was taken from Adafruit's Adafruit_BME680_Library at https://github.com/adafruit/Adafruit_BME680. I think it can be refactored into more efficient code at some point in the future, but it does work correctly. param[in] waitSwitch (Optional) When set will not return until reading is finished
Lookup table for the possible gas range values
◆ reset()
void BME680_Class::reset |
( |
| ) |
|
◆ setGas()
bool BME680_Class::setGas |
( |
uint16_t | GasTemp, |
|
|
uint16_t | GasMillis ) const |
sets the gas measurement target temperature and heating time param[in] GasTemp Target temperature in Celsius param[in] GasMillis Milliseconds to turn on heater return Always returns "true"
◆ setIIRFilter()
uint8_t BME680_Class::setIIRFilter |
( |
const uint8_t | iirFilterSetting = UINT8_MAX | ) |
const |
Set or return the current IIR filter setting
When called with no parameters returns the current IIR Filter setting, otherwise when called with one parameter will set the IIR filter value and return the new setting param[in] iirFilterSetting New setting return IIR Filter setting
◆ setOversampling()
uint8_t BME680_Class::setOversampling |
( |
const uint8_t | sensor, |
|
|
const uint8_t | sampling = UINT8_MAX ) const |
sets the oversampling mode for the sensor
See enumerated "sensorTypes" for a list of values. Set to a valid oversampling rate as defined in the enumerated type oversamplingTypes. If either value is out of range or another error occurs then the return value is false. param[in] sensor Enumerated sensor type param[in] sampling Sampling rate from enumerated type return "true" if successful otherwise false
◆ triggerMeasurement()
void BME680_Class::triggerMeasurement |
( |
| ) |
const |
trigger a measurement
Trigger a new measurement on the BME680
◆ waitForReadings()
void BME680_Class::waitForReadings |
( |
| ) |
const |
|
private |
Wait for readings to finish.
Only returns once a measurement on the BME680 has completed
◆ _cs
uint8_t BME680_Class::_cs |
|
private |
◆ _G1
◆ _G2
int16_t BME680_Class::_G2 |
|
private |
◆ _G3
◆ _Gas
int32_t BME680_Class::_Gas |
|
private |
signed 32bit configuration vars
◆ _H1
uint16_t BME680_Class::_H1 |
|
private |
◆ _H2
uint16_t BME680_Class::_H2 |
|
private |
◆ _H3
◆ _H4
◆ _H5
◆ _H6
uint8_t BME680_Class::_H6 |
|
private |
◆ _H7
◆ _Humidity
int32_t BME680_Class::_Humidity |
|
private |
◆ _I2CAddress
uint8_t BME680_Class::_I2CAddress = 0 |
|
private |
Default is I2C address is unknown.
◆ _I2CSpeed
uint16_t BME680_Class::_I2CSpeed = 0 |
|
private |
Default is I2C speed is unknown.
◆ _miso
uint8_t BME680_Class::_miso |
|
private |
Hardware and software SPI pins.
◆ _mosi
uint8_t BME680_Class::_mosi |
|
private |
◆ _P1
uint16_t BME680_Class::_P1 |
|
private |
unsigned 16bit configuration vars
◆ _P10
uint8_t BME680_Class::_P10 |
|
private |
◆ _P2
int16_t BME680_Class::_P2 |
|
private |
◆ _P3
◆ _P4
int16_t BME680_Class::_P4 |
|
private |
◆ _P5
int16_t BME680_Class::_P5 |
|
private |
◆ _P6
◆ _P7
◆ _P8
int16_t BME680_Class::_P8 |
|
private |
◆ _P9
int16_t BME680_Class::_P9 |
|
private |
signed 16bit configuration vars
◆ _Pressure
int32_t BME680_Class::_Pressure |
|
private |
◆ _res_heat
int8_t BME680_Class::_res_heat |
|
private |
◆ _res_heat_range
uint8_t BME680_Class::_res_heat_range |
|
private |
unsigned configuration vars
◆ _rng_sw_err
int8_t BME680_Class::_rng_sw_err |
|
private |
signed configuration vars
◆ _sck
uint8_t BME680_Class::_sck |
|
private |
◆ _T1
uint16_t BME680_Class::_T1 |
|
private |
◆ _T2
int16_t BME680_Class::_T2 |
|
private |
◆ _T3
◆ _Temperature
int32_t BME680_Class::_Temperature |
|
private |
◆ _tfine
int32_t BME680_Class::_tfine |
|
private |
The documentation for this class was generated from the following files: