upm
0.8.0
Sensor/Actuator repository for libmraa (v1.1.1)
|
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 μA @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.
Public Types | |
enum | BMP280_REGS_T : uint8_t { REG_CALIB00 = 0x88, REG_CALIB01 = 0x89, REG_CALIB02 = 0x8a, REG_CALIB03 = 0x8b, REG_CALIB04 = 0x8c, REG_CALIB05 = 0x8d, REG_CALIB06 = 0x8e, REG_CALIB07 = 0x8f, REG_CALIB08 = 0x90, REG_CALIB09 = 0x91, REG_CALIB10 = 0x92, REG_CALIB11 = 0x93, REG_CALIB12 = 0x94, REG_CALIB13 = 0x95, REG_CALIB14 = 0x96, REG_CALIB15 = 0x97, REG_CALIB16 = 0x98, REG_CALIB17 = 0x99, REG_CALIB18 = 0x9a, REG_CALIB19 = 0x9b, REG_CALIB20 = 0x9c, REG_CALIB21 = 0x9d, REG_CALIB22 = 0x9e, REG_CALIB23 = 0x9f, REG_CALIB24 = 0xa0, REG_CALIB25 = 0xa1, REG_CHIPID = 0xd0, REG_RESET = 0xe0, REG_STATUS = 0xf3, REG_CTRL_MEAS = 0xf4, REG_CONFIG = 0xf5, REG_PRESSURE_MSB = 0xf7, REG_PRESSURE_LSB = 0xf8, REG_PRESSURE_XLSB = 0xf9, REG_TEMPERATURE_MSB = 0xfa, REG_TEMPERATURE_LSB = 0xfb, REG_TEMPERATURE_XLSB = 0xfc } |
enum | CONFIG_BITS_T { CONFIG_SPI3W_EN = 0x01, CONFIG_FILTER0 = 0x04, CONFIG_FILTER1 = 0x08, CONFIG_FILTER2 = 0x10, _CONFIG_FILTER_MASK = 7, _CONFIG_FILTER_SHIFT = 2, CONFIG_T_SB0 = 0x20, CONFIG_T_SB1 = 0x40, CONFIG_T_SB2 = 0x80, _CONFIG_T_SB_MASK = 7, _CONFIG_T_SB_SHIFT = 5 } |
enum | FILTER_T { FILTER_OFF = 0, FILTER_2 = 1, FILTER_4 = 2, FILTER_8 = 3, FILTER_16 = 4 } |
enum | T_SB_T { T_SB_0_5 = 0, T_SB_62_5 = 1, T_SB_125 = 2, T_SB_250 = 3, T_SB_500 = 4, T_SB_1000 = 5, T_SB_2000 = 6, T_SB_4000 = 7 } |
enum | CTRL_MEAS_T { CTRL_MEAS_MODE0 = 0x01, CTRL_MEAS_MODE1 = 0x02, _CTRL_MEAS_MODE_MASK = 3, _CTRL_MEAS_MODE_SHIFT = 0, CTRL_MEAS_OSRS_P0 = 0x04, CTRL_MEAS_OSRS_P1 = 0x08, CTRL_MEAS_OSRS_P2 = 0x10, _CTRL_MEAS_OSRS_P_MASK = 7, _CTRL_MEAS_OSRS_P_SHIFT = 2, CTRL_MEAS_OSRS_T0 = 0x04, CTRL_MEAS_OSRS_T1 = 0x08, CTRL_MEAS_OSRS_T2 = 0x10, _CTRL_MEAS_OSRS_T_MASK = 7, _CTRL_MEAS_OSRS_T_SHIFT = 5 } |
enum | MODES_T { MODE_SLEEP = 0, MODE_FORCED = 1, MODE_NORMAL = 3 } |
enum | OSRS_P_T { OSRS_P_SKIPPED = 0, OSRS_P_OVERSAMPLING_1 = 1, OSRS_P_OVERSAMPLING_2 = 2, OSRS_P_OVERSAMPLING_4 = 3, OSRS_P_OVERSAMPLING_8 = 4, OSRS_P_OVERSAMPLING_16 = 5 } |
enum | OSRS_T_T { OSRS_T_SKIPPED = 0, OSRS_T_OVERSAMPLING_1 = 1, OSRS_T_OVERSAMPLING_2 = 2, OSRS_T_OVERSAMPLING_4 = 3, OSRS_T_OVERSAMPLING_8 = 4, OSRS_T_OVERSAMPLING_16 = 5 } |
enum | STATUS_T { STATUS_IM_UPDATE = 0x01, STATUS_MEASURING = 0x08 } |
enum | USAGE_MODE_T { USAGE_MODE_HANDHELD_LOW_POWER = 0, USAGE_MODE_HANDHELD_DYNAMIC = 1, USAGE_MODE_WEATHER_MONITOR = 2, USAGE_MODE_FLOOR_CHG_DETECT = 3, USAGE_MODE_DROP_DETECT = 4, USAGE_MODE_INDOOR_NAV = 5 } |
Public Member Functions | |
BMP280 (int bus=BMP280_DEFAULT_I2C_BUS, int addr=BMP280_DEFAULT_ADDR, int cs=-1, uint8_t theChipID=BMP280_DEFAULT_CHIPID) | |
virtual | ~BMP280 () |
virtual void | update () |
uint8_t | getChipID () |
void | reset () |
float | getTemperature (bool fahrenheit=false) |
float | getPressure () |
float | getAltitude (float seaLevelhPA=1013.25) |
virtual void | setUsageMode (USAGE_MODE_T mode) |
void | setOversampleRateTemperature (OSRS_T_T rate) |
void | setOversampleRatePressure (OSRS_P_T rate) |
void | setTimerStandby (T_SB_T tsb) |
void | setFilter (FILTER_T filter) |
void | setMeasureMode (MODES_T mode) |
const char * | getModuleName () |
int | getTemperatureCelsius () |
int | getPressurePa () |
Data Fields | |
const uint8_t | BMP280_RESET_BYTE = 0xb6 |
const int | CALIBRATION_BYTES = 26 |
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) |
void | clearData () |
virtual void | readCalibrationData () |
void | csOn () |
void | csOff () |
Protected Attributes | |
mraa::I2c * | m_i2c |
mraa::Spi * | m_spi |
mraa::Gpio * | m_gpioCS |
uint8_t | m_addr |
float | m_temperature |
float | m_pressure |
int32_t | m_t_fine |
MODES_T | m_mode |
enum BMP280_REGS_T : uint8_t |
BMP280 registers
enum CONFIG_BITS_T |
REG_CONFIG bits
enum FILTER_T |
FILTER values (samples to reach >= 75% of step response)
enum T_SB_T |
T_SB values (timer standby)
enum CTRL_MEAS_T |
REG_CTRL_MEAS bits
enum MODES_T |
CTRL_MEAS_MODE values
enum OSRS_P_T |
CTRL_MEAS_OSRS_P values
enum OSRS_T_T |
CTRL_MEAS_OSRS_T values
enum STATUS_T |
REG_STATUS bits
enum USAGE_MODE_T |
USAGE_MODE values. This is a fake specification to configure the various knobs based on their typical use modes, as recommended by Bosch.
BMP280 | ( | int | bus = BMP280_DEFAULT_I2C_BUS , |
int | addr = BMP280_DEFAULT_ADDR , |
||
int | cs = -1 , |
||
uint8_t | theChipID = BMP280_DEFAULT_CHIPID |
||
) |
BMP280 constructor.
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.
bus | I2C or SPI bus to use. |
address | The address for this device. -1 for SPI. |
cs | The gpio pin to use for the SPI Chip Select. -1 for I2C or for SPI with a hardware controlled pin. |
theChipID | The chip ID to use for validation |
|
virtual |
Update the internal stored values from sensor data.
Reimplemented in BME280.
uint8_t getChipID | ( | ) |
Return the chip ID.
void reset | ( | ) |
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.
fahrenheit | true to return data in Fahrenheit, false for Celicus. Celsius is the default. |
float getPressure | ( | ) |
Return the current measured pressure in Pascals (Pa). update() must have been called prior to calling this method.
float getAltitude | ( | float | seaLevelhPA = 1013.25 | ) |
Return the current computed altitude in meters. update() must have been called prior to calling this method.
seaLevelhPA | The pressure at sea level in hectoPascals (hPa). The default is 1013.25 hPA, (101325 Pa). |
|
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 contructor is USAGE_MODE_INDOOR_NAV, the highest resolution mode.
mode | One of the USAGE_MODE_T values. |
Reimplemented in BME280.
void setOversampleRateTemperature | ( | 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().
mode | One of the OSRS_T_T values. |
void setOversampleRatePressure | ( | 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().
mode | One of the OSRS_P_T values. |
void setTimerStandby | ( | 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.
mode | One of the T_SB_T values. |
void setFilter | ( | 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().
mode | One of the FILTER_T values. |
void setMeasureMode | ( | 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().
mode | One of the MODES_T values. |
|
inlinevirtual |
Returns name of module. This is the string in library name after libupm_
Implements IModuleStatus.
|
protected |
Read a register.
reg | The register to read |
|
protected |
Read contiguous registers into a buffer.
buffer | The buffer to store the results |
len | The number of registers to read |
|
protected |
Write to a register
reg | The register to write to |
val | The value to write |