Adafruit 9DOF - LSM303DLHC

Dependents:   Galileo_HoverBoardRider accelerometerTest

Embed: (wiki syntax)

« Back to documentation index

LSM303DLHC Class Reference

LSM303DLHC Class Reference

Tilt-compensated compass interface Library for the STMicro LSM303DLm 3-axis magnetometer, 3-axis acceleromter. More...

#include <LSM303DLHC.h>

Public Member Functions

 LSM303DLHC (PinName sda, PinName scl)
 Create a new interface for an LSM303DLM.
void init ()
 sets the x, y, and z offset corrections for hard iron calibration
void setScale (float x, float y, float z)
 sets the scale factor for the x, y, and z axes
void read (int a[3], int m[3])
 read the calibrated accelerometer and magnetometer values
void readAcc (int a[3])
 read the calibrated accelerometer values
void readMag (int m[3])
 read the calibrated magnetometer values
void frequency (int hz)
 sets the I2C bus frequency

Detailed Description

Tilt-compensated compass interface Library for the STMicro LSM303DLm 3-axis magnetometer, 3-axis acceleromter.

Author:
Michael Shimniok http://www.bot-thoughts.com/

This is an early revision; I've not yet implemented heading calculation and the interface differs from my earlier LSM303DLH; I hope to make this library drop in compatible at some point in the future. setScale() and setOffset() have no effect at this time.

 #include "mbed.h"
 #include "LSM303DLM.h"

 LSM303DLM compass(p28, p27);
 ...
 int a[3], m[3];
 ...
 compass.readAcc(a);
 compass.readMag(m);

Definition at line 69 of file LSM303DLHC.h.


Constructor & Destructor Documentation

LSM303DLHC ( PinName  sda,
PinName  scl 
)

Create a new interface for an LSM303DLM.

Parameters:
sdais the pin for the I2C SDA line
sclis the pin for the I2C SCL line

Definition at line 9 of file LSM303DLHC.cpp.


Member Function Documentation

void frequency ( int  hz )

sets the I2C bus frequency

Parameters:
frequencyis the I2C bus/clock frequency, either standard (100000) or fast (400000)
void init (  )

sets the x, y, and z offset corrections for hard iron calibration

Calibration details here: http://mbed.org/users/shimniok/notebook/quick-and-dirty-3d-compass-calibration/

If you gather raw magnetometer data and find, for example, x is offset by hard iron by -20 then pass +20 to this member function to correct for hard iron.

Parameters:
xis the offset correction for the x axis
yis the offset correction for the y axis
zis the offset correction for the z axis

Definition at line 15 of file LSM303DLHC.cpp.

void read ( int  a[3],
int  m[3] 
)

read the calibrated accelerometer and magnetometer values

Parameters:
ais the accelerometer 3d vector, written by the function
mis the magnetometer 3d vector, written by the function

Definition at line 33 of file LSM303DLHC.cpp.

void readAcc ( int  a[3] )

read the calibrated accelerometer values

Parameters:
ais the accelerometer 3d vector, written by the function

Definition at line 39 of file LSM303DLHC.cpp.

void readMag ( int  m[3] )

read the calibrated magnetometer values

Parameters:
mis the magnetometer 3d vector, written by the function

Definition at line 51 of file LSM303DLHC.cpp.

void setScale ( float  x,
float  y,
float  z 
)

sets the scale factor for the x, y, and z axes

Calibratio details here: http://mbed.org/users/shimniok/notebook/quick-and-dirty-3d-compass-calibration/

Sensitivity of the three axes is never perfectly identical and this function can help to correct differences in sensitivity. You're supplying a multipler such that x, y and z will be normalized to the same max/min values

Definition at line 62 of file LSM303DLHC.cpp.