API for the BMP280 Digital Pressure Sensor.
More...
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.
while (shouldRun) {
cout <<
"Compensation Temperature: " << sensor.
getTemperature() <<
" C / " cout <<
"Pressure: " << sensor.
getPressure() <<
" Pa" << endl;
cout <<
"Computed Altitude: " << sensor.
getAltitude() <<
" m" << endl;
cout << endl;
upm_delay(1);
}
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
-
bus | I2C or SPI bus to use. |
addr | The I2C address for this device. Use -1 for SPI. |
cs | The gpio pin to use for the SPI Chip Select. Use -1 for I2C, or for SPI with a hardware controlled pin. |
- Exceptions
-
std::runtime_error | on failure. |
Update the internal stored values from sensor data.
- Exceptions
-
std::runtime_error | on failure. |
Return the chip ID.
- Returns
- The chip ID (BMP280_CHIPID).
Reset the sensor, as if by a power-on-reset.
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
-
fahrenheit | true to return data in Fahrenheit, false for Celicus. Celsius is the default. |
- Returns
- The temperature in degrees Celsius or Fahrenheit.
Return the current measured pressure in Pascals (Pa). update() must have been called prior to calling this method.
- Returns
- The pressure in Pascals (Pa).
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
-
seaLevelhPA | The pressure at sea level in hectoPascals (hPa). The default is 1013.25 hPA, (101325 Pa). |
- Returns
- The computed altitude in meters.
Return the current computed altitude in meters. update() must have been called prior to calling this method.
- Returns
- The computed altitude in meters.
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
-
mode | One of the BMP280_USAGE_MODE_T values. |
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
-
rate | One of the BMP280_OSRS_T_T values. |
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
-
rate | One of the BMP280_OSRS_P_T values. |
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
-
tsb | One of the BMP280_T_SB_T values. |
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
-
filter | One of the BMP280_FILTER_T values. |
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
-
mode | One of the BMP280_MODES_T values. |
const char* getModuleName |
( |
| ) |
|
|
inlinevirtual |
Returns name of module. This is the string in library name after libupm_
- Returns
- name of module
Implements IModuleStatus.
Return the value of the BMP280_REG_STATUS register.
- Returns
- Contents of the status register.
uint8_t readReg |
( |
uint8_t |
reg | ) |
|
|
protected |
Read a register.
- Parameters
-
- Returns
- The value of the register
int readRegs |
( |
uint8_t |
reg, |
|
|
uint8_t * |
buffer, |
|
|
int |
len |
|
) |
| |
|
protected |
Read contiguous registers into a buffer.
- Parameters
-
buffer | The buffer to store the results |
len | The number of registers to read |
- Returns
- The number of bytes read, or -1 on error
void writeReg |
( |
uint8_t |
reg, |
|
|
uint8_t |
val |
|
) |
| |
|
protected |
Write to a register
- Parameters
-
reg | The register to write to |
val | The value to write |
- Exceptions
-
std::runtime_error | on failure. |
The documentation for this class was generated from the following files: