Interface library for ST LSM303DLM 3-axis magnetometer/accelerometer
Dependents: AVC_2012 m3pi_Kompass Fish_2014Fall Fish_2014Fall ... more
LSM303DLM Class Reference
Tilt-compensated compass interface Library for the STMicro LSM303DLm 3-axis magnetometer, 3-axis acceleromter. More...
#include <LSM303DLM.h>
Public Member Functions | |
LSM303DLM (PinName sda, PinName scl) | |
Create a new interface for an LSM303DLM. | |
void | setOffset (float x, float y, float z) |
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.
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 77 of file LSM303DLM.h.
Constructor & Destructor Documentation
LSM303DLM | ( | PinName | sda, |
PinName | scl | ||
) |
Create a new interface for an LSM303DLM.
- Parameters:
-
sda is the pin for the I2C SDA line scl is the pin for the I2C SCL line
Definition at line 8 of file LSM303DLM.cpp.
Member Function Documentation
void frequency | ( | int | hz ) |
sets the I2C bus frequency
- Parameters:
-
frequency is the I2C bus/clock frequency, either standard (100000) or fast (400000)
void read | ( | int | a[3], |
int | m[3] | ||
) |
read the calibrated accelerometer and magnetometer values
- Parameters:
-
a is the accelerometer 3d vector, written by the function m is the magnetometer 3d vector, written by the function
Definition at line 32 of file LSM303DLM.cpp.
void readAcc | ( | int | a[3] ) |
read the calibrated accelerometer values
- Parameters:
-
a is the accelerometer 3d vector, written by the function
Definition at line 38 of file LSM303DLM.cpp.
void readMag | ( | int | m[3] ) |
read the calibrated magnetometer values
- Parameters:
-
m is the magnetometer 3d vector, written by the function
Definition at line 50 of file LSM303DLM.cpp.
void setOffset | ( | float | x, |
float | y, | ||
float | z | ||
) |
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:
-
x is the offset correction for the x axis y is the offset correction for the y axis z is the offset correction for the z axis
Definition at line 68 of file LSM303DLM.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 61 of file LSM303DLM.cpp.
Generated on Tue Jul 12 2022 18:32:34 by
