upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Member Functions | Protected Attributes

API for the BMP280 Digital Pressure Sensor. More...

Detailed Description

The BMP280 is an absolute barometric pressure sensor especially designed for mobile applications. The sensor module is housed in an extremely compact 8-pin metal-lid LGA package with a footprint of only 2.0 * 2.5 mm2 and 0.95 mm package height. Its small dimensions and its low power consumption of 2.7 uA @1Hz allow the implementation in battery driven devices such as mobile phones, GPS modules or watches.

As the successor to the widely adopted BMP180, the BMP280 delivers high performance in all applications that require precise pressure measurement. The BMP280 operates at lower noise, supports new filter modes and an SPI interface within a footprint 63% smaller than the BMP180.

// Instantiate a BMP280 instance using default i2c bus and address
upm::BMP280 sensor;
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
// BMP280(0, -1, 10);
while (shouldRun) {
// update our values from the sensor
sensor.update();
// we show both C and F for temperature
cout << "Compensation Temperature: " << sensor.getTemperature() << " C / "
<< sensor.getTemperature(true) << " F" << endl;
cout << "Pressure: " << sensor.getPressure() << " Pa" << endl;
cout << "Computed Altitude: " << sensor.getAltitude() << " m" << endl;
cout << endl;
upm_delay(1);
}

Public Member Functions

 BMP280 (int bus=BMP280_DEFAULT_I2C_BUS, int addr=BMP280_DEFAULT_ADDR, int cs=-1)
 
virtual ~BMP280 ()
 
virtual void update ()
 
uint8_t getChipID ()
 
void reset ()
 
float getTemperature (bool fahrenheit=false)
 
float getPressure ()
 
void setSeaLevelPreassure (float seaLevelhPA=1013.25)
 
float getAltitude ()
 
virtual void setUsageMode (BMP280_USAGE_MODE_T mode)
 
void setOversampleRateTemperature (BMP280_OSRS_T_T rate)
 
void setOversampleRatePressure (BMP280_OSRS_P_T rate)
 
void setTimerStandby (BMP280_T_SB_T tsb)
 
void setFilter (BMP280_FILTER_T filter)
 
void setMeasureMode (BMP280_MODES_T mode)
 
const char * getModuleName ()
 
int getTemperatureCelsius ()
 
int getPressurePa ()
 

Protected Member Functions

uint8_t getStatus ()
 
uint8_t readReg (uint8_t reg)
 
int readRegs (uint8_t reg, uint8_t *buffer, int len)
 
void writeReg (uint8_t reg, uint8_t val)
 

Protected Attributes

bmp280_context m_bmp280
 

Constructor & Destructor Documentation

BMP280 ( int  bus = BMP280_DEFAULT_I2C_BUS,
int  addr = BMP280_DEFAULT_ADDR,
int  cs = -1 
)

BMP280 constructor.

This driver supports both the BMP280 and the BME280. The BME280 adds a humidity sensor. The device type is detected automatically by querying the chip id register.

This device can support both I2C and SPI. For SPI, set the addr to -1, and specify a positive integer representing the Chip Select (CS) pin for the cs argument. If you are using a hardware CS pin, then you can connect the proper pin to the hardware CS pin on your MCU and supply -1 for cs. The default operating mode is I2C.

Parameters
busI2C or SPI bus to use.
addrThe I2C address for this device. Use -1 for SPI.
csThe gpio pin to use for the SPI Chip Select. Use -1 for I2C, or for SPI with a hardware controlled pin.
Exceptions
std::runtime_erroron failure.

Here is the caller graph for this function:

~BMP280 ( )
virtual

BMP280 Destructor.

Here is the call graph for this function:

Member Function Documentation

void update ( void  )
virtual

Update the internal stored values from sensor data.

Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

uint8_t getChipID ( )

Return the chip ID.

Returns
The chip ID (BMP280_CHIPID).

Here is the call graph for this function:

void reset ( )

Reset the sensor, as if by a power-on-reset.

Here is the call graph for this function:

float getTemperature ( bool  fahrenheit = false)

Return the current measured temperature. Note, this is not ambient temperature - this is the temperature used to fine tune the pressure measurement. update() must have been called prior to calling this method.

Parameters
fahrenheittrue to return data in Fahrenheit, false for Celicus. Celsius is the default.
Returns
The temperature in degrees Celsius or Fahrenheit.

Here is the call graph for this function:

Here is the caller graph for this function:

float getPressure ( )

Return the current measured pressure in Pascals (Pa). update() must have been called prior to calling this method.

Returns
The pressure in Pascals (Pa).

Here is the call graph for this function:

Here is the caller graph for this function:

void setSeaLevelPreassure ( float  seaLevelhPA = 1013.25)

Set the pressure at sea level in hecto-Pascals (hPA). This value is used to compute the altitude based on the pressure. At driver initialization time, this value is set to 1013.25 hPA.

Parameters
seaLevelhPAThe pressure at sea level in hectoPascals (hPa). The default is 1013.25 hPA, (101325 Pa).
Returns
The computed altitude in meters.

Here is the call graph for this function:

float getAltitude ( )

Return the current computed altitude in meters. update() must have been called prior to calling this method.

Returns
The computed altitude in meters.

Here is the call graph for this function:

void setUsageMode ( BMP280_USAGE_MODE_T  mode)
virtual

Set a general usage mode. This function can be used to configure the filters and oversampling for a particular use case. These setting are documented in the BMP280 datasheet. The default mode set in the constructor is USAGE_MODE_INDOOR_NAV, the highest resolution mode.

Parameters
modeOne of the BMP280_USAGE_MODE_T values.

Here is the call graph for this function:

void setOversampleRateTemperature ( BMP280_OSRS_T_T  rate)

Set the temperature sensor oversampling parameter. See the data sheet for details. This value can be automatically set to a suitable value by using one of the predefined modes for setUsageMode().

Parameters
rateOne of the BMP280_OSRS_T_T values.

Here is the call graph for this function:

void setOversampleRatePressure ( BMP280_OSRS_P_T  rate)

Set the pressure sensor oversampling parameter. See the data sheet for details. This value can be automatically set to a suitable value by using one of the predefined modes for setUsageMode().

Parameters
rateOne of the BMP280_OSRS_P_T values.

Here is the call graph for this function:

void setTimerStandby ( BMP280_T_SB_T  tsb)

Set the timer standby value. When in NORMAL operating mode, this timer governs how long the chip will wait before performing a measurement. See the data sheet for details.

Parameters
tsbOne of the BMP280_T_SB_T values.

Here is the call graph for this function:

void setFilter ( BMP280_FILTER_T  filter)

Set the IIR filtering parameter. See the data sheet for details. This value can be automatically set to a suitable value by using one of the predefined modes for setUsageMode().

Parameters
filterOne of the BMP280_FILTER_T values.

Here is the call graph for this function:

void setMeasureMode ( BMP280_MODES_T  mode)

Set the default measuring mode. Basic values are forced, sleep, and normal. See the data sheet for details. This value can be automatically set to a suitable value by using one of the predefined modes for setUsageMode().

Parameters
modeOne of the BMP280_MODES_T values.

Here is the call graph for this function:

const char* getModuleName ( )
inlinevirtual

Returns name of module. This is the string in library name after libupm_

Returns
name of module

Implements IModuleStatus.

Here is the call graph for this function:

uint8_t getStatus ( )
protected

Return the value of the BMP280_REG_STATUS register.

Returns
Contents of the status register.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t readReg ( uint8_t  reg)
protected

Read a register.

Parameters
regThe register to read
Returns
The value of the register

Here is the call graph for this function:

Here is the caller graph for this function:

int readRegs ( uint8_t  reg,
uint8_t *  buffer,
int  len 
)
protected

Read contiguous registers into a buffer.

Parameters
bufferThe buffer to store the results
lenThe number of registers to read
Returns
The number of bytes read, or -1 on error

Here is the call graph for this function:

Here is the caller graph for this function:

void writeReg ( uint8_t  reg,
uint8_t  val 
)
protected

Write to a register

Parameters
regThe register to write to
valThe value to write
Exceptions
std::runtime_erroron failure.

Here is the call graph for this function:

Here is the caller graph for this function:

Inheritance diagram for BMP280:
Inheritance graph
[legend]
Collaboration diagram for BMP280:
Collaboration graph
[legend]

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