Llibrary for the WiGo MPL3115A2, I2C Precision Altimeter sensor.

Dependents:   KL25Z_Batt_Test WIGO_MPL3115A2 Multi-Sensor SPACEmk2 ... more

Embed: (wiki syntax)

« Back to documentation index

MPL3115A2 Class Reference

MPL3115A2 Class Reference

MPL3115A2 Altimeter example. More...

#include <MPL3115A2.h>

Public Member Functions

 MPL3115A2 (PinName sda, PinName scl, int addr)
 MPL3115A2 constructor.
uint8_t getDeviceID ()
 Get the value of the WHO_AM_I register.
unsigned char getStatus (void)
 Return the STATUS register value.
float getAltimeter (void)
 Get the altimeter value.
unsigned int getAltimeterRaw (unsigned char *dt)
 Get the altimeter value in raw mode.
float getPressure (void)
 Get the pressure value.
unsigned int getPressureRaw (unsigned char *dt)
 Get the pressure value in raw mode.
float getTemperature (void)
 Get the temperature value.
unsigned int getTemperatureRaw (unsigned char *dt)
 Get the temperature value in raw mode.
void Altimeter_Mode (void)
 Set the Altimeter Mode.
void Barometric_Mode (void)
 Set the Barometric Mode.
unsigned int getAllData (float *f)
 Get the altimeter or pressure and temperature values.
unsigned int getAllData (float *f, float *d)
 Get the altimeter or pressure and temperature values and the delta values.
void getAllMaximumData (float *f)
 Get the altimeter or pressure and temperature captured maximum value.
void getAllMinimumData (float *f)
 Get the altimeter or pressure and temperature captured minimum value.
unsigned int getAllDataRaw (unsigned char *dt)
 Get the altimeter or pressure, and temperature values in raw mode.
unsigned int isDataAvailable (void)
 Return if there are date available.
void Oversample_Ratio (unsigned int ratio)
 Set the oversampling rate value.
void DataReady (void(*fptr)(void), unsigned char OS)
 Configure the sensor to streaming data using Interrupt.
void AltitudeTrigger (void(*fptr)(void), unsigned short level)
 Configure the sensor to generate an Interrupt crossing the center threshold.
void Reset (void)
 Soft Reset.
void SetPressureOffset (char offset)
 Configure the Pressure offset.
void SetTemperatureOffset (char offset)
 Configure the Temperature offset.
void SetAltitudeOffset (char offset)
 Configure the Altitude offset.

Detailed Description

MPL3115A2 Altimeter example.

 #include "mbed.h"
 #include "MPL3115A2.h"
 
 #define MPL3115A2_I2C_ADDRESS (0x60<<1)
 MPL3115A2 wigo_sensor1(PTE0, PTE1, MPL3115A2_I2C_ADDRESS);
 Serial pc(USBTX, USBRX);

 // pos [0] = altitude or pressure value 
 // pos [1] = temperature value 
 float sensor_data[2];

 int main(void) {

    pc.baud( 230400);
    pc.printf("MPL3115A2 Altimeter mode. [%d]\r\n", wigo_sensor1.getDeviceID()); 

    wigo_sensor1.Oversample_Ratio( OVERSAMPLE_RATIO_32);
    
    while(1) {
        //
        if ( wigo_sensor1.isDataAvailable()) {
            wigo_sensor1.getAllData( &sensor_data[0]);
            pc.printf("\tAltitude: %f\tTemperature: %f\r\n", sensor_data[0], sensor_data[1]);
        }
        //
        wait( 0.001);
    }

 }

Definition at line 74 of file MPL3115A2.h.


Constructor & Destructor Documentation

MPL3115A2 ( PinName  sda,
PinName  scl,
int  addr 
)

MPL3115A2 constructor.

Parameters:
sdaSDA pin
sdlSCL pin
addraddr of the I2C peripheral

Definition at line 74 of file MPL3115A2.cpp.


Member Function Documentation

void Altimeter_Mode ( void   )

Set the Altimeter Mode.

Returns:
none

Definition at line 244 of file MPL3115A2.cpp.

void AltitudeTrigger ( void(*)(void)  fptr,
unsigned short  level 
)

Configure the sensor to generate an Interrupt crossing the center threshold.

Parameters:
userfunctin callback, level in meter
Returns:
none

Definition at line 158 of file MPL3115A2.cpp.

void Barometric_Mode ( void   )

Set the Barometric Mode.

Returns:
none

Definition at line 215 of file MPL3115A2.cpp.

void DataReady ( void(*)(void)  fptr,
unsigned char  OS 
)

Configure the sensor to streaming data using Interrupt.

Parameters:
userfunctin callback, oversampling values. See MPL3115A2.h
Returns:
none

Definition at line 104 of file MPL3115A2.cpp.

unsigned int getAllData ( float *  f )

Get the altimeter or pressure and temperature values.

Parameters:
arrayof float f[2]
Returns:
0 no data available, 1 for data available

Definition at line 335 of file MPL3115A2.cpp.

unsigned int getAllData ( float *  f,
float *  d 
)

Get the altimeter or pressure and temperature values and the delta values.

Parameters:
arrayof float f[2], array of float d[2]
Returns:
0 no data available, 1 for data available

Definition at line 351 of file MPL3115A2.cpp.

unsigned int getAllDataRaw ( unsigned char *  dt )

Get the altimeter or pressure, and temperature values in raw mode.

Parameters:
arrayof unsigned char[5]
Returns:
1 if data are available, 0 if not.

Definition at line 504 of file MPL3115A2.cpp.

void getAllMaximumData ( float *  f )

Get the altimeter or pressure and temperature captured maximum value.

Parameters:
arrayof float f[2]
Returns:
0 no data available, 1 for data available

Definition at line 370 of file MPL3115A2.cpp.

void getAllMinimumData ( float *  f )

Get the altimeter or pressure and temperature captured minimum value.

Parameters:
arrayof float f[2]
Returns:
0 no data available, 1 for data available

Definition at line 381 of file MPL3115A2.cpp.

float getAltimeter ( void   )

Get the altimeter value.

Returns:
altimeter value as float

Definition at line 392 of file MPL3115A2.cpp.

unsigned int getAltimeterRaw ( unsigned char *  dt )

Get the altimeter value in raw mode.

Parameters:
dtpointer to unsigned char array
Returns:
1 if data are available, 0 if not.

Definition at line 522 of file MPL3115A2.cpp.

unsigned char getDeviceID (  )

Get the value of the WHO_AM_I register.

Returns:
DEVICE_ID value == 0xC4

Definition at line 311 of file MPL3115A2.cpp.

float getPressure ( void   )

Get the pressure value.

Returns:
pressure value as float

Definition at line 427 of file MPL3115A2.cpp.

unsigned int getPressureRaw ( unsigned char *  dt )

Get the pressure value in raw mode.

Parameters:
dtpointer to unsigned char array
Returns:
1 if data are available, 0 if not.

Definition at line 539 of file MPL3115A2.cpp.

unsigned char getStatus ( void   )

Return the STATUS register value.

Returns:
STATUS register value

Definition at line 327 of file MPL3115A2.cpp.

float getTemperature ( void   )

Get the temperature value.

Returns:
temperature value as float

Definition at line 470 of file MPL3115A2.cpp.

unsigned int getTemperatureRaw ( unsigned char *  dt )

Get the temperature value in raw mode.

Parameters:
dtpointer to unsigned char array
Returns:
1 if data are available, 0 if not.

Definition at line 557 of file MPL3115A2.cpp.

unsigned int isDataAvailable ( void   )

Return if there are date available.

Returns:
0 for no data available, bit0 set for Temp data available, bit1 set for Press/Alti data available bit2 set for both Temp and Press/Alti data available

Definition at line 317 of file MPL3115A2.cpp.

void Oversample_Ratio ( unsigned int  ratio )

Set the oversampling rate value.

Parameters:
oversamplingvalues. See MPL3115A2.h
Returns:
none

Definition at line 272 of file MPL3115A2.cpp.

void Reset ( void   )

Soft Reset.

Parameters:
none
Returns:
none

Definition at line 92 of file MPL3115A2.cpp.

void SetAltitudeOffset ( char  offset )

Configure the Altitude offset.

Altitude Data User Offset Register (OFF_H) is expressed as a 2’s complement number in meters. The user offset register provides user adjustment to the vertical height of the Altitude output. The range of values are from -128 to +127 meters. In RAW output mode no scaling or offsets will be applied in the digital domain

Parameters:
offset
Returns:
none

Definition at line 593 of file MPL3115A2.cpp.

void SetPressureOffset ( char  offset )

Configure the Pressure offset.

Pressure user accessible offset trim value expressed as an 8-bit 2's complement number. The user offset registers may be adjusted to enhance accuracy and optimize the system performance. Range is from -512 to +508 Pa, 4 Pa per LSB. In RAW output mode no scaling or offsets will be applied in the digital domain

Parameters:
offset
Returns:
none

Definition at line 573 of file MPL3115A2.cpp.

void SetTemperatureOffset ( char  offset )

Configure the Temperature offset.

Temperature user accessible offset trim value expressed as an 8-bit 2's complement number. The user offset registers may be adjusted to enhance accuracy and optimize the system performance. Range is from -8 to +7.9375°C 0.0625°C per LSB. In RAW output mode no scaling or offsets will be applied in the digital domain

Parameters:
offset
Returns:
none

Definition at line 583 of file MPL3115A2.cpp.