Driver for the LSM303D digital compass. Permits access to all LSM303D registers by name, including multi-byte register sets, and has convenience methods for floating-point accelerometer and magnetometer reads scaled according to the device settings. Written from scratch for Mbed 6.0
Dependents: UoY-32C-lab8-exercise UoY-32C-lab5-lsm303d
Driver for the LSM303D digital compass
Permits access to all LSM303D registers by name, including multi-byte register sets. Convenience methods are included for sensor reads, including floating-point accelerometer and magnetometer reads scaled according to the device settings, and for the more common settings (data rates and scales).
I2C connection only. Written from scratch for Mbed 6.0.
The interface is subject to minor changes with each version. Deprecation warnings will be issued where possible.
Defaults
The class constructor checks that an LSM303D is present on the I2C bus, then enables all sensors. The accelerometer and magnetometer update rates are both set to 50Hz, and the scales are left at their device defaults of +-2g for the accelerometer and +-4gauss for the magnetometer.
Basic usage
Some usage examples
#include "lsm303d.h" LSM303D lsm303d(D14, D15); // SDA and SCL pins for I2C lsm303d.setAccelScale(LSM303D::AccelScale::scale_4g); // set +-4g range lsm303d.INT1_enable_DRDY_A(); // set DRDY_A bit in CTRL3 register (enable INT1 on accel data ready) short rawX = lsm303d.getAccelX(); // returns 16-bit signed result, unscaled float x, y, z; lsm303d.getAccelInto(x, y, z); // overwrites parameters, values in g float mX = lsm303d.getMagX(); // returns value in gauss
History
Capitalise filenames to match class name
2021-02-17, by ajp109 [Wed, 17 Feb 2021 13:13:13 +0000] rev 11
Capitalise filenames to match class name
Add accelerometer filter selection
2021-02-10, by ajp109 [Wed, 10 Feb 2021 21:27:54 +0000] rev 10
Add accelerometer filter selection
Update documentation; fix cache bug in RWRegister
2021-01-31, by ajp109 [Sun, 31 Jan 2021 14:35:50 +0000] rev 9
Update documentation; fix cache bug in RWRegister
Testing making nested classes public for docs generation purposes
2021-01-27, by ajp109 [Wed, 27 Jan 2021 11:05:26 +0000] rev 8
Testing making nested classes public for docs generation purposes
Docs testing - trying to document protected nested classes
2021-01-27, by ajp109 [Wed, 27 Jan 2021 10:58:33 +0000] rev 7
Docs testing - trying to document protected nested classes
Docs updates
2021-01-27, by ajp109 [Wed, 27 Jan 2021 10:42:39 +0000] rev 6
Docs updates
More documentation experiments
2021-01-26, by ajp109 [Tue, 26 Jan 2021 22:46:48 +0000] rev 5
More documentation experiments
Testing doxygen options
2021-01-26, by ajp109 [Tue, 26 Jan 2021 22:04:52 +0000] rev 4
Testing doxygen options
Doc updates
2021-01-26, by ajp109 [Tue, 26 Jan 2021 22:01:49 +0000] rev 3
Doc updates
Start documentation
2021-01-26, by ajp109 [Tue, 26 Jan 2021 21:28:48 +0000] rev 2
Start documentation