upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | List of all members

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 magnometer and acceleromter are accessed at two seperate I2C addresses.

lsm303.jpeg
// Instantiate LSM303 compass on I2C
// Get the coordinate data
sensor.getCoordinates();
short[] 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
System.out.println("coor: rX " + coor[0] + " - rY " + coor[1] + " - rZ " + coor[2]);
System.out.println("coor: gX " + sensor.getCoorX() + " - gY " + sensor.getCoorY()
+ " - gZ " + sensor.getCoorZ());
// Get and print out the heading
System.out.println("heading: " + sensor.getHeading());
// Get the acceleration
sensor.getAcceleration();
short[] accel = sensor.getRawAccelData();
// Print out the X, Y, and Z acceleration data using two different
// methods
System.out.println("acc: rX " + accel[0] + " - rY " + accel[1] + " - rZ " + accel[2]);
System.out.println("acc: gX " + sensor.getAccelX() + " - gY " + sensor.getAccelY()
+ " - gZ " + sensor.getAccelZ());

Public Member Functions

synchronized void delete ()
 
 LSM303 (int bus, int addrMag, int addrAcc, int accScale)
 
 LSM303 (int bus, int addrMag, int addrAcc)
 
 LSM303 (int bus, int addrMag)
 
 LSM303 (int bus)
 
float getHeading ()
 
int getCoordinates ()
 
int getAcceleration ()
 
short[] getRawCoorData ()
 
short getCoorX ()
 
short getCoorY ()
 
short getCoorZ ()
 
short[] getRawAccelData ()
 
short getAccelX ()
 
short getAccelY ()
 
short getAccelZ ()
 

Constructor & Destructor Documentation

LSM303 ( int  bus,
int  addrMag,
int  addrAcc,
int  accScale 
)

Instantiates an LSM303 object

Parameters
i2cbus
addrMagnetometer
addrAccelerometer

Member Function Documentation

int getAcceleration ( )

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

short getAccelX ( )

Gets the X component of the acceleration data

short getAccelY ( )

Gets the Y component of the acceleration data

short getAccelZ ( )

Gets the Z component of the acceleration data

int getCoordinates ( )

Gets the coordinates in the XYZ order

short getCoorX ( )

Gets the X component of the coordinates data

short getCoorY ( )

Gets the Y component of the coordinates data

short getCoorZ ( )

Gets the Z component of the coordinates data

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
short [] getRawAccelData ( )

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

short [] getRawCoorData ( )

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


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