upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions

API for the MMA8X5X Three-Axis Accelerometer. More...

Detailed Description

Description in web-link above: The NXP MMA8X5X are low-power, three-axis capacitive micromachined accelerometer with 10/12/14 bits of resolution. These accelerometer are packed with embedded functions with flexible user-programmable options configurable to two interrupt pins. The MMA8X5X have user-selectable full scales of +-2g/+-4g/+-8g.

// U can set your own parameters for an MMA8X5X instance with
/*
upm::mma8x5x_params_t params;
params.type = <device-id>; device-id of your sensor
params.rate = <sampling-rate>; between 0<<3 and 7<<3
params.range = <range>; between 0 and 2
params.offsetX = <x-axis offset>; between 0 and 255
params.offsetY = <y-axis offset>; between 0 and 255
params.offsetZ = <z-axis offset>; between 0 and 255
*/
std::cout << "Initializing test-application..." << std::endl;
// Instantiate an MMA8X5X instance on bus 1 with default parameters
// The sensor-type will be detected by reading out the device-id
upm::MMA8X5X mySensor(1);
// If u have set own parameters use this one
/*
upm::MMA8X5X mySensor(1, &params);
*/
// activate periodic measurements
mySensor.setActive();
// update and print available values every second
while (run) {
mySensor.getData(&data, true);
std::cout << "x: " << (int) data.x << std::endl
<< "y: " << (int) data.y << std::endl
<< "z: " << (int) data.z << std::endl;
std::cout << std::endl;
upm_delay(1);
}
std::cout << "Exiting test-application..." << std::endl;

Public Member Functions

 MMA8X5X (int bus, mma8x5x_params_t *params=NULL, int devAddr=MMA8X5X_I2C_ADDRESS)
 
int setDeviceName (uint8_t type)
 
int setDeviceParams (mma8x5x_params_t *params)
 
int setUserOffset (int8_t x, int8_t y, int8_t z)
 
int setActive (void)
 
int setStandby (void)
 
int isReady (void)
 
int sampleData (void)
 
int16_t getX (int bSampleData=0)
 
int16_t getY (int bSampleData=0)
 
int16_t getZ (int bSampleData=0)
 
int getData (mma8x5x_data_t *data, int bSampleData=0)
 

Constructor & Destructor Documentation

MMA8X5X ( int  bus,
mma8x5x_params_t params = NULL,
int  devAddr = MMA8X5X_I2C_ADDRESS 
)

Instantiates an MMA8X5X object

Parameters
busNumber of the used bus params Params of device
devAddrAddress of the used I2C device

Here is the call graph for this function:

Member Function Documentation

int setDeviceName ( uint8_t  type)

Set device name and type matching given type or read out devive_id to set name and type of device

Parameters
typeType of device if set or 0 if needed to find out by it
Returns
0 on success -1 on error

Here is the caller graph for this function:

int setDeviceParams ( mma8x5x_params_t params)

Set device params to given data or set default params and read out devive_id to set type of device

Parameters
paramsParams of device if set by user NULL if it is not set by user
Returns
0 on success -1 on error

Here is the call graph for this function:

Here is the caller graph for this function:

int setUserOffset ( int8_t  x,
int8_t  y,
int8_t  z 
)

Set user offset correction Offset correction register will be erased after accelerometer reset

Parameters
xOffset correction value for x-axis
yOffset correction value for y-axis
zOffset correction value for z-axis
Returns
0 on success -1 on error
int setActive ( void  )

Set active mode, this enables periodic measurements

Returns
0 on success -1 on error
int setStandby ( void  )

Set standby mode, this disables periodic measurements

Returns
0 on success -1 on error
int isReady ( void  )

Check for new set of measurement data.

Returns
MMA8X5X_DATA_READY if new sample is ready MMA8X5X_NODATA if nothing is available
int sampleData ( void  )

Read & calculate accelerometer data in mg & saves them to variables

Returns
0 on success -1 on error

Here is the caller graph for this function:

int16_t getX ( int  bSampleData = 0)

Get x-axis acceleration

Parameters
bSampleDataFlag to read sensor
Returns
The x-axis acceleration on success -999 on error

Here is the call graph for this function:

int16_t getY ( int  bSampleData = 0)

Get y-axis acceleration

Parameters
bSampleDataFlag to read sensor
Returns
The y-axis acceleration on success -999 on error

Here is the call graph for this function:

int16_t getZ ( int  bSampleData = 0)

Get z-axis acceleration

Parameters
bSampleDataFlag to read sensor
Returns
The z-axis acceleration on success -999 on error

Here is the call graph for this function:

int getData ( mma8x5x_data_t data,
int  bSampleData = 0 
)

Get sensor values

Parameters
dataSensor values
bSampleDataFlag to read sensor
Returns
0 on success -1 on error

Here is the call graph for this function:


The documentation for this class was generated from the following files: