#accelerometer #magnetometer #driver #read #interface #digital

lsm303

Interface to the LSM303 digital accelerometer and magnetometer

1 unstable release

Uses old Rust 2015

0.1.0 Sep 4, 2017

MIT/Apache

27KB
470 lines

Build Status

LSM303 Accelerometer and Magnetometer

This is a driver for the LSM303DLHC digital accelerometer and magnetometer.

Getting started

$ cargo run --example read

lib.rs:

Interface to the LSM303 digital accelerometer and magnetometer.

# use std::time::Duration;
# fn main() { test().unwrap(); }
# fn test() -> lsm303::Result<()> {
let device = "/dev/i2c-1";
let mut accelerometer =
    lsm303::Accelerometer::new(device)?;
let mut magnetometer =
    lsm303::Magnetometer::new(device)?;

 loop {
    let accel = accelerometer.read_acceleration()?;
    let mag = magnetometer.read_magnetic_field()?;
    println!("Accel: ({}, {}, {})  ||  Mag: ({}, {}, {})",
             accel.x, accel.y, accel.z,
             mag.x, mag.y, mag.z);
    std::thread::sleep(Duration::from_millis(100));
}
# Ok(())
# }

Dependencies

~6MB
~126K SLoC