Llibrary for the WiGo MPL3115A2, I2C Precision Altimeter sensor. This is a temp fork

Dependents:   sensor AerCloud_MutliTech_Socket_Modem_Example Freescale_Multi-Sensor_Shield 2lemetry_Sensor_Example ... more

Fork of MPL3115A2 by clemente di caprio

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, PinName int1, PinName int2)
 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 55 of file MPL3115A2.h.


Constructor & Destructor Documentation

MPL3115A2 ( PinName  sda,
PinName  scl,
int  addr,
PinName  int1,
PinName  int2 
)

MPL3115A2 constructor.

Parameters:
sdaSDA pin
sdlSCL pin
addraddr of the I2C peripheral
int1InterruptIn
int2InterruptIn

Interrupt schema:

* The Altitude Trigger use the IRQ1 - Altitude Trigger -> MPL3115A2_Int1.fall -> AltitudeTrg_IRQ -> MPL3115A2_usr1_fptr

* The Data ready use the IRQ2 - Data Ready -> MPL3115A2_Int2.fall -> DataReady_IRQ -> MPL3115A2_usr2_fptr

Definition at line 41 of file MPL3115A2.cpp.


Member Function Documentation

void Altimeter_Mode ( void   )

Set the Altimeter Mode.

Returns:
none

Definition at line 211 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 125 of file MPL3115A2.cpp.

void Barometric_Mode ( void   )

Set the Barometric Mode.

Returns:
none

Definition at line 182 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 71 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 302 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 318 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 471 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 337 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 348 of file MPL3115A2.cpp.

float getAltimeter ( void   )

Get the altimeter value.

Returns:
altimeter value as float

Definition at line 359 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 489 of file MPL3115A2.cpp.

unsigned char getDeviceID (  )

Get the value of the WHO_AM_I register.

Returns:
DEVICE_ID value == 0xC4

Definition at line 278 of file MPL3115A2.cpp.

float getPressure ( void   )

Get the pressure value.

Returns:
pressure value as float

Definition at line 394 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 506 of file MPL3115A2.cpp.

unsigned char getStatus ( void   )

Return the STATUS register value.

Returns:
STATUS register value

Definition at line 294 of file MPL3115A2.cpp.

float getTemperature ( void   )

Get the temperature value.

Returns:
temperature value as float

Definition at line 437 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 524 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 284 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 239 of file MPL3115A2.cpp.

void Reset ( void   )

Soft Reset.

Parameters:
none
Returns:
none

Definition at line 59 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 560 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 540 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 550 of file MPL3115A2.cpp.