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

API for the LSM303DLH Accelerometer & Compass. More...

Detailed Description

This module defines the LSM303DLHDLH 3-axis magnetometer/3-axis accelerometer. This module was tested with the Seeed Studio* Grove 6-Axis Accelerometer & Compass module used over I2C. The magnetometer and acceleromter are accessed at two seperate I2C addresses.

lsm303dlh.jpeg
#include "lsm303dlh.hpp"
int
main(int argc, char** argv)
{
// Instantiate LSM303DLH compass on I2C
upm::LSM303DLH sensor(0);
// Get the coordinate data
sensor.getCoordinates();
int16_t* coor = sensor.getRawCoorData(); // in XYZ order.
// The sensor returns XZY, but the driver compensates and makes it XYZ
// Print out the X, Y, and Z coordinate data using two different methods
std::cout << "coor: rX " << (int) coor[0] << " - rY " << (int) coor[1] << " - rZ "
<< (int) coor[2] << std::endl;
std::cout << "coor: gX " << sensor.getCoorX() << " - gY " << sensor.getCoorY() << " - gZ "
<< sensor.getCoorZ() << std::endl;
// Get and print out the heading
std::cout << "heading: " << sensor.getHeading() << std::endl;
// Get the acceleration
sensor.getAcceleration();
int16_t* accel = sensor.getRawAccelData();
// Print out the X, Y, and Z acceleration data using two different methods
std::cout << "acc: rX " << (int) accel[0] << " - rY " << (int) accel[1] << " - Z "
<< (int) accel[2] << std::endl;
std::cout << "acc: gX " << sensor.getAccelX() << " - gY " << sensor.getAccelY() << " - gZ "
<< sensor.getAccelZ() << std::endl;
return 0;
}

Public Types

enum  LSM303DLH_SLAVE_T { LSM303DLH_MAG_T = 0, LSM303DLH_ACC_T }
 

Public Member Functions

 LSM303DLH (int bus, int addrMag=LSM303DLH_MAG, int addrAcc=LSM303DLH_ACC, int accScale=8)
 
float getHeading ()
 
mraa::Result getCoordinates ()
 
mraa::Result getAcceleration ()
 
int16_t * getRawCoorData ()
 
int16_t getCoorX ()
 
int16_t getCoorY ()
 
int16_t getCoorZ ()
 
int16_t * getRawAccelData ()
 
int16_t getAccelX ()
 
int16_t getAccelY ()
 
int16_t getAccelZ ()
 

Constructor & Destructor Documentation

LSM303DLH ( int  bus,
int  addrMag = LSM303DLH_MAG,
int  addrAcc = LSM303DLH_ACC,
int  accScale = 8 
)

Instantiates an LSM303DLH object

Parameters
busI2C bus to use
addrMagI2C address of the Magnetometer (default 0x1E)
addrAccI2C address of the Accelerometer (default 0x19)
accScaleAccelerometer scale, can be 2, 4 or 8 (default 8)

Member Function Documentation

float getHeading ( )

LSM303DLH object destructor where is no more need for this here - I2c connection will be stopped automatically when m_i2c variable will go out of scope ~LSM303DLH (); Gets the current heading; headings <0 indicate an error has occurred

Returns
float

Here is the call graph for this function:

mraa::Result getCoordinates ( )

Gets the coordinates in the XYZ order

Here is the caller graph for this function:

mraa::Result getAcceleration ( )

Gets accelerometer values Should be called before other "get" functions for acceleration

int16_t * getRawCoorData ( )

Gets raw coordinate data; it is updated when getCoordinates() is called

int16_t getCoorX ( )

Gets the X component of the coordinates data

int16_t getCoorY ( )

Gets the Y component of the coordinates data

int16_t getCoorZ ( )

Gets the Z component of the coordinates data

int16_t * getRawAccelData ( )

Gets raw accelerometer data; it is updated when getAcceleration() is called

int16_t getAccelX ( )

Gets the X component of the acceleration data

int16_t getAccelY ( )

Gets the Y component of the acceleration data

int16_t getAccelZ ( )

Gets the Z component of the acceleration data


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