Adafruit BME280 Library
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Adafruit_BME280 Class Reference

Class that stores state and functions for interacting with BME280 IC. More...

#include <Adafruit_BME280.h>

Classes

struct  config
 config register More...
 
struct  ctrl_hum
 ctrl_hum register More...
 
struct  ctrl_meas
 ctrl_meas register More...
 

Public Types

enum  sensor_sampling {
  SAMPLING_NONE = 0b000, SAMPLING_X1 = 0b001, SAMPLING_X2 = 0b010, SAMPLING_X4 = 0b011,
  SAMPLING_X8 = 0b100, SAMPLING_X16 = 0b101
}
 sampling rates
 
enum  sensor_mode { MODE_SLEEP = 0b00, MODE_FORCED = 0b01, MODE_NORMAL = 0b11 }
 power modes
 
enum  sensor_filter {
  FILTER_OFF = 0b000, FILTER_X2 = 0b001, FILTER_X4 = 0b010, FILTER_X8 = 0b011,
  FILTER_X16 = 0b100
}
 filter values
 
enum  standby_duration {
  STANDBY_MS_0_5 = 0b000, STANDBY_MS_10 = 0b110, STANDBY_MS_20 = 0b111, STANDBY_MS_62_5 = 0b001,
  STANDBY_MS_125 = 0b010, STANDBY_MS_250 = 0b011, STANDBY_MS_500 = 0b100, STANDBY_MS_1000 = 0b101
}
 standby duration in ms
 

Public Member Functions

 Adafruit_BME280 ()
 class constructor
 
 Adafruit_BME280 (int8_t cspin, SPIClass *theSPI=&SPI)
 class constructor if using hardware SPI More...
 
 Adafruit_BME280 (int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin)
 class constructor if using software SPI More...
 
bool begin (uint8_t addr=BME280_ADDRESS, TwoWire *theWire=&Wire)
 Initialise sensor with given parameters / settings. More...
 
bool init ()
 Initialise sensor with given parameters / settings. More...
 
void setSampling (sensor_mode mode=MODE_NORMAL, sensor_sampling tempSampling=SAMPLING_X16, sensor_sampling pressSampling=SAMPLING_X16, sensor_sampling humSampling=SAMPLING_X16, sensor_filter filter=FILTER_OFF, standby_duration duration=STANDBY_MS_0_5)
 setup sensor with given parameters / settings More...
 
bool takeForcedMeasurement (void)
 Take a new measurement (only possible in forced mode) More...
 
float readTemperature (void)
 Returns the temperature from the sensor. More...
 
float readPressure (void)
 Returns the pressure from the sensor. More...
 
float readHumidity (void)
 Returns the humidity from the sensor. More...
 
float readAltitude (float seaLevel)
 
float seaLevelForAltitude (float altitude, float pressure)
 
uint32_t sensorID (void)
 
float getTemperatureCompensation (void)
 
void setTemperatureCompensation (float)
 
Adafruit_Sensor * getTemperatureSensor (void)
 Gets an Adafruit Unified Sensor object for the temp sensor component. More...
 
Adafruit_Sensor * getPressureSensor (void)
 Gets an Adafruit Unified Sensor object for the pressure sensor component. More...
 
Adafruit_Sensor * getHumiditySensor (void)
 Gets an Adafruit Unified Sensor object for the humidity sensor component. More...
 

Protected Member Functions

void readCoefficients (void)
 Reads the factory-set coefficients.
 
bool isReadingCalibration (void)
 return true if chip is busy reading cal data More...
 
void write8 (byte reg, byte value)
 Writes an 8 bit value over I2C or SPI. More...
 
uint8_t read8 (byte reg)
 Reads an 8 bit value over I2C or SPI. More...
 
uint16_t read16 (byte reg)
 Reads a 16 bit value over I2C or SPI. More...
 
uint32_t read24 (byte reg)
 Reads a 24 bit value over I2C. More...
 
int16_t readS16 (byte reg)
 Reads a signed 16 bit value over I2C or SPI. More...
 
uint16_t read16_LE (byte reg)
 Reads a signed 16 bit little endian value over I2C or SPI. More...
 
int16_t readS16_LE (byte reg)
 Reads a signed little endian 16 bit value over I2C or SPI. More...
 

Protected Attributes

Adafruit_I2CDevice * i2c_dev = NULL
 Pointer to I2C bus interface.
 
Adafruit_SPIDevice * spi_dev = NULL
 Pointer to SPI bus interface.
 
Adafruit_BME280_Temptemp_sensor = NULL
 Adafruit_Sensor compat temperature sensor component.
 
Adafruit_BME280_Pressurepressure_sensor = NULL
 Adafruit_Sensor compat pressure sensor component.
 
Adafruit_BME280_Humidityhumidity_sensor = NULL
 Adafruit_Sensor compat humidity sensor component.
 
uint8_t _i2caddr
 I2C addr for the TwoWire interface.
 
int32_t _sensorID
 ID of the BME Sensor.
 
int32_t t_fine
 
int32_t t_fine_adjust = 0
 
bme280_calib_data _bme280_calib
 here calibration data is stored
 
config _configReg
 config register object
 
ctrl_meas _measReg
 measurement register object
 
ctrl_hum _humReg
 hum register object
 

Detailed Description

Class that stores state and functions for interacting with BME280 IC.

Constructor & Destructor Documentation

◆ Adafruit_BME280() [1/2]

Adafruit_BME280::Adafruit_BME280 ( int8_t  cspin,
SPIClass *  theSPI = &SPI 
)

class constructor if using hardware SPI

Parameters
cspinthe chip select pin to use
*theSPIoptional SPI object

◆ Adafruit_BME280() [2/2]

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

class constructor if using software SPI

Parameters
cspinthe chip select pin to use
mosipinthe MOSI pin to use
misopinthe MISO pin to use
sckpinthe SCK pin to use

Member Function Documentation

◆ begin()

bool Adafruit_BME280::begin ( uint8_t  addr = BME280_ADDRESS,
TwoWire *  theWire = &Wire 
)

Initialise sensor with given parameters / settings.

Parameters
addrthe I2C address the device can be found on
theWirethe I2C object to use, defaults to &Wire
Returns
true on success, false otherwise

◆ init()

bool Adafruit_BME280::init ( )

Initialise sensor with given parameters / settings.

Returns
true on success, false otherwise

◆ setSampling()

void Adafruit_BME280::setSampling ( sensor_mode  mode = MODE_NORMAL,
sensor_sampling  tempSampling = SAMPLING_X16,
sensor_sampling  pressSampling = SAMPLING_X16,
sensor_sampling  humSampling = SAMPLING_X16,
sensor_filter  filter = FILTER_OFF,
standby_duration  duration = STANDBY_MS_0_5 
)

setup sensor with given parameters / settings

This is simply a overload to the normal begin()-function, so SPI users don't get confused about the library requiring an address.

Parameters
modethe power mode to use for the sensor
tempSamplingthe temp samping rate to use
pressSamplingthe pressure sampling rate to use
humSamplingthe humidity sampling rate to use
filterthe filter mode to use
durationthe standby duration to use

◆ takeForcedMeasurement()

bool Adafruit_BME280::takeForcedMeasurement ( void  )

Take a new measurement (only possible in forced mode)

Returns
true in case of success else false

◆ readTemperature()

float Adafruit_BME280::readTemperature ( void  )

Returns the temperature from the sensor.

Returns
the temperature read from the device

◆ readPressure()

float Adafruit_BME280::readPressure ( void  )

Returns the pressure from the sensor.

Returns
the pressure value (in Pascal) read from the device

◆ readHumidity()

float Adafruit_BME280::readHumidity ( void  )

Returns the humidity from the sensor.

Returns
the humidity value read from the device

◆ readAltitude()

float Adafruit_BME280::readAltitude ( float  seaLevel)

Calculates the altitude (in meters) from the specified atmospheric pressure (in hPa), and sea-level pressure (in hPa).

Parameters
seaLevelSea-level pressure in hPa
Returns
the altitude value read from the device

◆ seaLevelForAltitude()

float Adafruit_BME280::seaLevelForAltitude ( float  altitude,
float  atmospheric 
)

Calculates the pressure at sea level (in hPa) from the specified altitude (in meters), and atmospheric pressure (in hPa).

Parameters
altitudeAltitude in meters
atmosphericAtmospheric pressure in hPa
Returns
the pressure at sea level (in hPa) from the specified altitude

◆ sensorID()

uint32_t Adafruit_BME280::sensorID ( void  )

Returns Sensor ID found by init() for diagnostics

Returns
Sensor ID 0x60 for BME280, 0x56, 0x57, 0x58 BMP280

◆ getTemperatureCompensation()

float Adafruit_BME280::getTemperatureCompensation ( void  )

Returns the current temperature compensation value in degrees Celsius

Returns
the current temperature compensation value in degrees Celsius

◆ setTemperatureCompensation()

void Adafruit_BME280::setTemperatureCompensation ( float  adjustment)

Sets a value to be added to each temperature reading. This adjusted temperature is used in pressure and humidity readings.

Parameters
adjustmentValue to be added to each temperature reading in Celsius

◆ getTemperatureSensor()

Adafruit_Sensor * Adafruit_BME280::getTemperatureSensor ( void  )

Gets an Adafruit Unified Sensor object for the temp sensor component.

Returns
Adafruit_Sensor pointer to temperature sensor

◆ getPressureSensor()

Adafruit_Sensor * Adafruit_BME280::getPressureSensor ( void  )

Gets an Adafruit Unified Sensor object for the pressure sensor component.

Returns
Adafruit_Sensor pointer to pressure sensor

◆ getHumiditySensor()

Adafruit_Sensor * Adafruit_BME280::getHumiditySensor ( void  )

Gets an Adafruit Unified Sensor object for the humidity sensor component.

Returns
Adafruit_Sensor pointer to humidity sensor

◆ isReadingCalibration()

bool Adafruit_BME280::isReadingCalibration ( void  )
protected

return true if chip is busy reading cal data

Returns
true if reading calibration, false otherwise

◆ write8()

void Adafruit_BME280::write8 ( byte  reg,
byte  value 
)
protected

Writes an 8 bit value over I2C or SPI.

Parameters
regthe register address to write to
valuethe value to write to the register

◆ read8()

uint8_t Adafruit_BME280::read8 ( byte  reg)
protected

Reads an 8 bit value over I2C or SPI.

Parameters
regthe register address to read from
Returns
the data byte read from the device

◆ read16()

uint16_t Adafruit_BME280::read16 ( byte  reg)
protected

Reads a 16 bit value over I2C or SPI.

Parameters
regthe register address to read from
Returns
the 16 bit data value read from the device

◆ read24()

uint32_t Adafruit_BME280::read24 ( byte  reg)
protected

Reads a 24 bit value over I2C.

Parameters
regthe register address to read from
Returns
the 24 bit data value read from the device

◆ readS16()

int16_t Adafruit_BME280::readS16 ( byte  reg)
protected

Reads a signed 16 bit value over I2C or SPI.

Parameters
regthe register address to read from
Returns
the 16 bit data value read from the device

◆ read16_LE()

uint16_t Adafruit_BME280::read16_LE ( byte  reg)
protected

Reads a signed 16 bit little endian value over I2C or SPI.

Parameters
regthe register address to read from
Returns
the 16 bit data value read from the device

◆ readS16_LE()

int16_t Adafruit_BME280::readS16_LE ( byte  reg)
protected

Reads a signed little endian 16 bit value over I2C or SPI.

Parameters
regthe register address to read from
Returns
the 16 bit data value read from the device

Member Data Documentation

◆ t_fine

int32_t Adafruit_BME280::t_fine
protected

temperature with high resolution, stored as an attribute as this is used for temperature compensation reading humidity and pressure

◆ t_fine_adjust

int32_t Adafruit_BME280::t_fine_adjust = 0
protected

add to compensate temp readings and in turn to pressure and humidity readings


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