lsm303-driver
A no_std Rust driver for the ST LSM303 accelerometer + magnetometer family
(also sold as the GY-511 breakout board):
- LSM303DLH
- LSM303DLM
- LSM303DLHC
- LSM303D
Built on embedded-hal 1.0. It is async by default; enable the sync feature
for the blocking API.
Usage
use ;
// `i2c` is any `embedded_hal_async::i2c::I2c` implementation.
let mut sensor = new;
sensor.enable_default.await?;
let = sensor.read.await?;
// accel.x, accel.y, accel.z, mag.x, mag.y, mag.z (raw i16 counts)
Don't know which chip you have? Let the driver detect it:
use ;
let found = detect.await?;
let mut sensor: = match found.into_driver ;
sensor.enable_default.await?;
For the blocking version:
= { = "0.1", = false, = ["sync"] }
Then drop the .awaits.
Status
Tested only on the LSM303D. The other variants are implemented from their datasheets but not yet tested on hardware.
Credits
Based on Pololu's LSM303 Arduino library: device detection, register map and default configuration are ported from it. Pololu's copyright and MIT license notice is kept in LICENSE-POLOLU.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.