BME280 and BME680 easyC Library 1.0.0
This is a library for the BME 280 and BME680 easyC board.
Loading...
Searching...
No Matches
BME280_Class Class Reference

BME280 Class definition. More...

#include <BME280.h>

Inherited by BME280.

Public Member Functions

 BME280_Class ()
 Empty & unused class constructor.
 
 ~BME280_Class ()
 Empty & unused class destructor.
 
bool begin ()
 
bool begin (const uint32_t i2cSpeed)
 
bool begin (const uint8_t chipSelect)
 
bool begin (const uint8_t chipSelect, const uint8_t mosi, const uint8_t miso, const uint8_t sck)
 
uint8_t mode (const uint8_t operatingMode=UINT8_MAX)
 
bool setOversampling (const uint8_t sensor, const uint8_t sampling)
 
uint8_t getOversampling (const uint8_t sensor, const bool actual=false)
 
uint8_t iirFilter (const uint8_t iirFilterSetting=UINT8_MAX)
 
uint8_t inactiveTime (const uint8_t inactiveTimeSetting=UINT8_MAX)
 
uint32_t measurementTime (const uint8_t measureTimeSetting=1)
 
void getSensorData (int32_t &temp, int32_t &hum, int32_t &press)
 
void reset ()
 

Private Member Functions

uint8_t readByte (const uint8_t addr)
 
void readSensors ()
 
void getCalibration ()
 
template<typename T >
uint8_t & getData (const uint8_t addr, T &value)
 
template<typename T >
uint8_t & putData (const uint8_t addr, const T &value)
 

Private Attributes

bool _TransmissionStatus = false
 I2C communications status.
 
uint8_t _I2CAddress = 0
 Default is no I2C address known.
 
uint8_t _cs
 
uint8_t _sck
 
uint8_t _mosi
 
uint8_t _miso
 Hardware and software SPI pins for SPI.
 
uint8_t _cal_dig_H1
 
uint8_t _cal_dig_H3
 Calibration variables.
 
int8_t _cal_dig_H6 = 0
 Calibration variables.
 
uint16_t _cal_dig_T1
 
uint16_t _cal_dig_P1
 Calibration variables.
 
int16_t _cal_dig_T2
 
int16_t _cal_dig_T3
 
int16_t _cal_dig_P2
 
int16_t _cal_dig_P3
 
int16_t _cal_dig_P4
 
int16_t _cal_dig_P5
 
int16_t _cal_dig_P6
 
int16_t _cal_dig_P7
 
int16_t _cal_dig_P8
 
int16_t _cal_dig_P9
 
int16_t _cal_dig_H2
 
int16_t _cal_dig_H4
 
int16_t _cal_dig_H5
 Calibration variables.
 
uint8_t _mode = UINT8_MAX
 Last mode set.
 
int32_t _tfine
 
int32_t _Temperature
 
int32_t _Pressure
 
int32_t _Humidity
 Sensor global variables.
 

Detailed Description

BME280 Class definition.

BME280 Class forward declarations for methods and public/private variable declarations

Constructor & Destructor Documentation

◆ BME280_Class()

BME280_Class::BME280_Class ( )

Empty & unused class constructor.

◆ ~BME280_Class()

BME280_Class::~BME280_Class ( )

Empty & unused class destructor.

Member Function Documentation

◆ begin() [1/4]

bool BME280_Class::begin ( )

Begin method to start I2C communications

It is overloaded to allow for 3 different connection types to be used - I2C, Hardware SPI and Software SPI. When called with no parameters the I2C mode is enabled and the I2C bus is scanned for the first BME280 (typically at 0x76 or 0x77 unless an I2C expander is used to remap the address.

Returns
returns "true" when the class initialized correctly

◆ begin() [2/4]

bool BME280_Class::begin ( const uint32_t i2cSpeed)

Begin method to start I2C communications

It is overloaded to allow for 3 different connection types to be used - I2C, Hardware SPI and Software SPI. When called with no parameters the I2C mode is enabled and the I2C bus is scanned for the first BME280 (typically at 0x76 or 0x77 unless an I2C expander is used to remap the address.

Parameters
[in]i2cSpeedI2C speed rate in baud
Returns
returns "true" when the class initialized correctly

◆ begin() [3/4]

bool BME280_Class::begin ( const uint8_t chipSelect)

Begin method to start hardware SPI communications

It is overloaded to allow for 3 different connection types to be used - I2C, Hardware SPI and Software SPI. When called with no parameters the I2C mode is enabled and the I2C bus is scanned for the first BME280 (typically at 0x76 or 0x77 unless an I2C expander is used to remap the address.

Parameters
[in]chipSelectHardware SPI CS chip
Returns
returns "true" when the class initialized correctly

◆ begin() [4/4]

bool BME280_Class::begin ( const uint8_t chipSelect,
const uint8_t mosi,
const uint8_t miso,
const uint8_t sck )

Begin method to start software SPI communications

It is overloaded to allow for 3 different connection types to be used - I2C, Hardware SPI and Software SPI. When called with no parameters the I2C mode is enabled and the I2C bus is scanned for the first BME280 (typically at 0x76 or 0x77 unless an I2C expander is used to remap the address.

Parameters
[in]chipSelectHardware SPI CS chip
[in]mosiMaster-Out Slave-In pin
[in]misoMaster-In Slave-Out pin
[in]sckSystem Clock
Returns
returns "true" when the class initialized correctly

◆ getCalibration()

void BME280_Class::getCalibration ( )
private

reads the calibration register data into local variables for use in converting readings

◆ getData()

template<typename T >
uint8_t & BME280_Class::getData ( const uint8_t addr,
T & value )
inlineprivate

Template function for reading from the I2C or SPI bus

As a template it supports compile-time data type definitions

Parameters
[in]addrMemory address
[in]valueData Type "T" to read
Returns
Size of data read

◆ getOversampling()

uint8_t BME280_Class::getOversampling ( const uint8_t sensor,
const bool actual = false )

retrieves the oversampling value for the sensor

see enumerated sensorTypes for list of values.

Parameters
[in]sensorWhich sensor to retrieve
[in]actualreturn the actual value if set, otherwise return the raw value
Returns
return value

◆ getSensorData()

void BME280_Class::getSensorData ( int32_t & temp,
int32_t & hum,
int32_t & press )

returns the most recent temperature, humidity and pressure readings

Parameters
[out]temptemperature value from device
[out]humhumidity value from device
[out]presspressure value from device

◆ iirFilter()

uint8_t BME280_Class::iirFilter ( const uint8_t iirFilterSetting = UINT8_MAX)

Set iir filter

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

Parameters
[in]iirFilterSettingSet iir
Returns
Inactive time time

◆ inactiveTime()

uint8_t BME280_Class::inactiveTime ( const uint8_t inactiveTimeSetting = UINT8_MAX)

Return the inactive time setting

when called with no parameters returns the current inactive time setting, otherwise uses the parameter to set the inactive time

Parameters
[in]inactiveTimeSetting
Returns
inactive time setting

◆ measurementTime()

uint32_t BME280_Class::measurementTime ( const uint8_t measureTimeSetting = 1)

returns the time in microseconds for a measurement cycle with the current settings

A cycle includes a temperature, pressure and humidity reading plus the wait time

Parameters
[in]measureTimeSetting
Returns
measurement cycle time

◆ mode()

uint8_t BME280_Class::mode ( const uint8_t operatingMode = UINT8_MAX)

sets the current mode bits or returns the current value if the parameter isn't used

Parameters
[in]operatingModeDevice operating mode to set
Returns
new mode

◆ putData()

template<typename T >
uint8_t & BME280_Class::putData ( const uint8_t addr,
const T & value )
inlineprivate

Template for writing to the I2C or SPI bus

As a template it can support compile-time data type definitions

Parameters
[in]addrMemory address
[in]valueData Type "T" to read
Returns
Size of data written

◆ readByte()

uint8_t BME280_Class::readByte ( const uint8_t addr)
private

interlude function to the getData() function. Reads 1 byte from the given address

Parameters
[in]addrAddress to read data from
Returns
returns byte of data read

◆ readSensors()

void BME280_Class::readSensors ( )
private

reads all 3 sensor values from the registers

Read all 3 in one operation and then proceeds to convert the raw temperature, pressure and humidity readings into standard metric units in the BME280's documentation but the math used below was taken from Adafruit's Adafruit_BME280_Library at https://github.com/adafruit/Adafruit_BME280_Library. I think it can be refactored into more efficient code at some point in the future, but it does work correctly

◆ reset()

void BME280_Class::reset ( )

performs a device reset, as if it were powered down and back up again

◆ setOversampling()

bool BME280_Class::setOversampling ( const uint8_t sensor,
const uint8_t sampling )

sets the oversampling mode for the sensor

see enumerated sensorTypes for 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.

Parameters
[in]sensorWhich sensor to set
[in]samplingSampling rate
Returns
Always returns "true"

Member Data Documentation

◆ _cal_dig_H1

uint8_t BME280_Class::_cal_dig_H1
private

◆ _cal_dig_H2

int16_t BME280_Class::_cal_dig_H2
private

◆ _cal_dig_H3

uint8_t BME280_Class::_cal_dig_H3
private

Calibration variables.

◆ _cal_dig_H4

int16_t BME280_Class::_cal_dig_H4
private

◆ _cal_dig_H5

int16_t BME280_Class::_cal_dig_H5
private

Calibration variables.

◆ _cal_dig_H6

int8_t BME280_Class::_cal_dig_H6 = 0
private

Calibration variables.

◆ _cal_dig_P1

uint16_t BME280_Class::_cal_dig_P1
private

Calibration variables.

◆ _cal_dig_P2

int16_t BME280_Class::_cal_dig_P2
private

◆ _cal_dig_P3

int16_t BME280_Class::_cal_dig_P3
private

◆ _cal_dig_P4

int16_t BME280_Class::_cal_dig_P4
private

◆ _cal_dig_P5

int16_t BME280_Class::_cal_dig_P5
private

◆ _cal_dig_P6

int16_t BME280_Class::_cal_dig_P6
private

◆ _cal_dig_P7

int16_t BME280_Class::_cal_dig_P7
private

◆ _cal_dig_P8

int16_t BME280_Class::_cal_dig_P8
private

◆ _cal_dig_P9

int16_t BME280_Class::_cal_dig_P9
private

◆ _cal_dig_T1

uint16_t BME280_Class::_cal_dig_T1
private

◆ _cal_dig_T2

int16_t BME280_Class::_cal_dig_T2
private

◆ _cal_dig_T3

int16_t BME280_Class::_cal_dig_T3
private

◆ _cs

uint8_t BME280_Class::_cs
private

◆ _Humidity

int32_t BME280_Class::_Humidity
private

Sensor global variables.

◆ _I2CAddress

uint8_t BME280_Class::_I2CAddress = 0
private

Default is no I2C address known.

◆ _miso

uint8_t BME280_Class::_miso
private

Hardware and software SPI pins for SPI.

◆ _mode

uint8_t BME280_Class::_mode = UINT8_MAX
private

Last mode set.

◆ _mosi

uint8_t BME280_Class::_mosi
private

◆ _Pressure

int32_t BME280_Class::_Pressure
private

◆ _sck

uint8_t BME280_Class::_sck
private

◆ _Temperature

int32_t BME280_Class::_Temperature
private

◆ _tfine

int32_t BME280_Class::_tfine
private

◆ _TransmissionStatus

bool BME280_Class::_TransmissionStatus = false
private

I2C communications status.


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