upm  1.2.0
Sensor/Actuator repository for libmraa (v1.6.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions
LSM303 Class Reference

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

Detailed Description

This module defines the LSM303DLH 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.

lsm303.jpeg
#include "lsm303.hpp"
int
main(int argc, char **argv)
{
// Instantiate LSM303 compass on I2C
upm::LSM303 *sensor = new upm::LSM303(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 Member Functions

 LSM303 (int bus, int addrMag=LSM303_MAG, int addrAcc=LSM303_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

LSM303 ( int  bus,
int  addrMag = LSM303_MAG,
int  addrAcc = LSM303_ACC,
int  accScale = 8 
)

Instantiates an LSM303 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 ( )

LSM303 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 ~LSM303 (); 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: