This is a mbed 5.2 Release

Dependencies:   USBDevice

Fork of mbed-os-test by Jerry Bradshaw

Embed: (wiki syntax)

« Back to documentation index

BMP280 Class Reference

Bosch BMP280 Digital Pressure Sensor. More...

#include <BMP280.h>

Data Structures

union  bmp280_config_reg
 CONFIG_REG (0xF5) More...
union  bmp280_ctrl_meas
 CTRL_MEAS (0xF4) More...
union  bmp280_status
 STATUS (0xF3) More...

Public Member Functions

 BMP280 (PinName sda, PinName scl, int slaveAddress)
 BMP280 constructor.
 BMP280 (I2C *i2c, int slaveAddress)
 BMP280 constructor.
int writeReg (char reg, char value)
 Write a device register.
int readReg (char reg, char *value)
 Read a device register.
 BMP280 (PinName sda, PinName scl)
 BMP280 constructor.
 BMP280 (I2C *i2c)
 BMP280 constructor.
 ~BMP280 (void)
 BMP280 destructor.
int init (bmp280_osrs_P_t Osrs_p, bmp280_osrs_T_t Osrs_t, bmp280_FILT_t Filter, bmp280_MODE_t Mode, bmp280_TSB_t T_sb)
 This initializes the BMP280.
int ReadCompData (float *Temp_degC, float *Press_Pa)
 The BMP280 has 2 modes.
int reg_write (char reg, char value)
 This function allows writing to a register.
int reg_read (char reg, char *value, char number)
 This function allows writing to a register.
void Reset (void)
 Performs a soft reset on the BMP280.
int Detect (void)
 Detects if the BMP280 is present.
float compensate_T_float (int32_t adc_T)
 Performs calculations on the raw temperature data to convert to.
float compensate_P_float (int32_t adc_P)
 Performs calculations on the raw pressure data to convert to.
int Sleep (void)
 Puts the BMP280 in low power Sleep mode.
int ReadCompDataRaw (char *bmp280_rawData)
 This reads the raw BMP280 data.
int ReadCompDataRaw2 (char *bmp280_rawData)
 This reads the raw BMP280 data uses the Bosch algorithm to get the data.
void ToFloat (char *bmp280_rawData, float *Temp_degC, float *Press_Pa)
 This converts the raw BMP280 data to couble based on Bosch's algorithm.
float ToFahrenheit (float temperature)
 converts to Farenhite from Centigrade
int ReadId (void)
 Reads a unique ID from the register.

Data Fields

char bmp280_temp_xlsb
 TEMP_XLSB (0xFC)
char bmp280_temp_lsb
 TEMP_LSB (0xFB)
char bmp280_temp_msb
 TEMP_MSB (0xFA)
char bmp280_press_xlsb
 PRESS_XLSB (0xF9)
char bmp280_press_lsb
 PRESS_LSB (0xF8)
char bmp280_press_msb
 PRESS_MSB (0xF7)
char bmp280_reset
 RESET (0xE0)
char bmp280_id
 ID (0xD0)
char bmp280_Calib [26]
 calib25... calib00 (0xA1...0x88)

Detailed Description

Bosch BMP280 Digital Pressure Sensor.

Definition at line 102 of file BMP280.h.


Constructor & Destructor Documentation

BMP280 ( PinName  sda,
PinName  scl,
int  slaveAddress 
)

BMP280 constructor.

Parameters:
sdambed pin to use for SDA line of I2C interface.
sclmbed pin to use for SCL line of I2C interface.
slaveAddressSlave Address of the device.

Definition at line 39 of file BMP280.cpp.

BMP280 ( I2C *  i2c,
int  slaveAddress 
)

BMP280 constructor.

Parameters:
i2cI2C object to use.
slaveAddressSlave Address of the device.

Definition at line 45 of file BMP280.cpp.

BMP280 ( PinName  sda,
PinName  scl 
)

BMP280 constructor.

Parameters:
sdambed pin to use for SDA line of I2C interface.
sclmbed pin to use for SCL line of I2C interface.
BMP280 ( I2C *  i2c )

BMP280 constructor.

Parameters:
i2cI2C object to use.
~BMP280 ( void   )

BMP280 destructor.

Definition at line 55 of file BMP280.cpp.


Member Function Documentation

float compensate_P_float ( int32_t  adc_P )

Performs calculations on the raw pressure data to convert to.

pressure in Pascal, based on Bosch's algorithm

Parameters:
adc_PRaw Press ADC value, Global dig_P1, dig_P2,..., dig_P9
Returns:
The Pressure in Pascals

Definition at line 277 of file BMP280.cpp.

float compensate_T_float ( int32_t  adc_T )

Performs calculations on the raw temperature data to convert to.

temperature in deg C, based on Bosch's algorithm

Parameters:
RawTemp ADC value, Global dig_T1, dig_T2, dig_T3
Returns:
The Temperature in deg C

Definition at line 260 of file BMP280.cpp.

int Detect ( void   )

Detects if the BMP280 is present.

Parameters:
none
Returns:
1 for found, 0 for not found, -1 for comm error

Definition at line 240 of file BMP280.cpp.

int init ( BMP280::bmp280_osrs_P_t  Osrs_p,
BMP280::bmp280_osrs_T_t  Osrs_t,
BMP280::bmp280_FILT_t  Filter,
BMP280::bmp280_MODE_t  Mode,
BMP280::bmp280_TSB_t  T_sb 
)

This initializes the BMP280.

The BMP280 has 2 modes. FORCED mode and NORMAL mode. FORCED Mode gives more control to the processor as the processor sends out the Mode to initiate a conversion and a data is sent out then. NORMAL mode is initialized once and it just runs and sends out data at a programmed timed interval. (In this example the main() will set this to Normal function)

Parameters:
Osrs_p-Pressure oversampling
Osrs_t-Temperature oversampling
Filter-Filter Settings
Mode-Power Modes
T_sb-Standby time (used with Normal mode)
dig_T1,dig_T2,dig_T3-Coeffs used for temp conversion - GLOBAL variables (output)
dig_P1,....,dig_P9-Coeffs used for press conversion - GLOBAL variables (output)
Returns:
0-if no error. A non-zero value indicates an error.

Definition at line 62 of file BMP280.cpp.

int ReadCompData ( float *  Temp_degC,
float *  Press_Pa 
)

The BMP280 has 2 modes.

FORCED mode and NORMAL mode. FORCED Mode gives more control to the processor as the processor sends out the Mode to initiate a conversion and a data is sent out then. NORMAL mode is initialized once and it just runs and sends out data at a programmed timed interval. (In this example the main() will set this to Normal function)

Parameters:
*Temp_degC- Pointer to temperature (result in deg C)
*Press_Pa- Pointer to pressure (resul in Pascal)
Returns:
0-if no error. A non-zero value indicates an error.

Definition at line 185 of file BMP280.cpp.

int ReadCompDataRaw ( char *  bmp280_rawData )

This reads the raw BMP280 data.

Parameters:
*bmp280_rawData-array of raw output data
Returns:
0-if no error. A non-zero value indicates an error.

Definition at line 159 of file BMP280.cpp.

int ReadCompDataRaw2 ( char *  bmp280_rawData )

This reads the raw BMP280 data uses the Bosch algorithm to get the data.

in float, then the float gets converted to an String

Parameters:
*bmp280_rawData-array of raw output data
Returns:
0-if no error. A non-zero value indicates an error.

Definition at line 141 of file BMP280.cpp.

int ReadId ( void   )

Reads a unique ID from the register.

Parameters:
none
Returns:
The correct id value which is 0x58

Definition at line 252 of file BMP280.cpp.

int readReg ( char  reg,
char *  value 
)

Read a device register.

int reg_read ( char  reg,
char *  value,
char  number 
)

This function allows writing to a register.

reg- Address of the register to read from (input) *value- Pointer to the value read from the register (output)

Returns:
0-if no error. A non-zero value indicates an error.

Definition at line 206 of file BMP280.cpp.

int reg_write ( char  reg,
char  value 
)

This function allows writing to a register.

Parameters:
reg-Address of the register to write to
value-Data written to the register
Returns:
0-if no error. A non-zero value indicates an error.

Definition at line 196 of file BMP280.cpp.

void Reset ( void   )

Performs a soft reset on the BMP280.

Parameters:
none
Returns:
none

Definition at line 235 of file BMP280.cpp.

int Sleep ( void   )

Puts the BMP280 in low power Sleep mode.

Parameters:
none
Returns:
0 if no errors, -1 if error.

Definition at line 220 of file BMP280.cpp.

float ToFahrenheit ( float  temperature )

converts to Farenhite from Centigrade

Parameters:
temperaturein Centigrade
Returns:
temperature value in Farenhite

Definition at line 136 of file BMP280.cpp.

void ToFloat ( char *  bmp280_rawData,
float *  Temp_degC,
float *  Press_Pa 
)

This converts the raw BMP280 data to couble based on Bosch's algorithm.

Parameters:
*bmp280_rawData-array of raw input data
*Temp_degC-pointer to output, Temp value in deg C
*Press_Pa-pointer to output, Press value in Pascals
Returns:
0-if no error. A non-zero value indicates an error.

Definition at line 173 of file BMP280.cpp.

int writeReg ( char  reg,
char  value 
)

Write a device register.


Field Documentation

char bmp280_Calib[26]

calib25... calib00 (0xA1...0x88)

Definition at line 234 of file BMP280.h.

char bmp280_id

ID (0xD0)

Definition at line 188 of file BMP280.h.

PRESS_LSB (0xF8)

Definition at line 147 of file BMP280.h.

PRESS_MSB (0xF7)

Definition at line 150 of file BMP280.h.

PRESS_XLSB (0xF9)

Definition at line 144 of file BMP280.h.

RESET (0xE0)

Definition at line 185 of file BMP280.h.

TEMP_LSB (0xFB)

Definition at line 138 of file BMP280.h.

TEMP_MSB (0xFA)

Definition at line 141 of file BMP280.h.

TEMP_XLSB (0xFC)

Definition at line 135 of file BMP280.h.