Giter Club home page Giter Club logo

lsm303agr-rs's Introduction

Rust LSM303AGR Ultra-low-power 3D Accelerometer and 3D Magnetometer Driver

crates.io Docs Build Status Coverage Status

This is a platform agnostic Rust driver for the LSM303AGR ultra-compact high-performance eCompass module: ultra-low-power 3D accelerometer and 3D magnetometer using the embedded-hal traits.

This driver allows you to:

  • Connect through I2C or SPI. See: new_with_i2c().
  • Initialize the device. See: init().
  • Accelerometer:
    • Read accelerometer data. See: accel_data().
    • Read accelerometer data unscaled. See: accel_data_unscaled().
    • Get accelerometer status. See: accel_status().
    • Set accelerometer output data rate. See: set_accel_odr().
    • Set accelerometer mode. See: set_accel_mode().
    • Set accelerometer scale. See: set_accel_scale().
    • Get accelerometer ID. See: accelerometer_id().
    • Get temperature sensor status. See: temperature_status().
    • Get temperature sensor data. See: temperature_data().
    • Get temperature sensor data in celsius. See: temperature_celsius().
  • Magnetometer:
    • Get the magnetometer status. See: mag_status().
    • Change into continuous/one-shot mode. See: into_mag_continuous().
    • Read magnetometer data. See: mag_data().
    • Read magnetometer data unscaled. See: mag_data_unscaled().
    • Set magnetometer output data rate. See: set_mag_odr().
    • Get magnetometer ID. See: magnetometer_id().

The LSM303AGR is an ultra-low-power high- performance system-in-package featuring a 3D digital linear acceleration sensor and a 3D digital magnetic sensor. The LSM303AGR has linear acceleration full scales of ±2g/±4g/±8g/±16g and a magnetic field dynamic range of ±50 gauss.

The LSM303AGR includes an I2C serial bus interface that supports standard, fast mode, fast mode plus, and high-speed (100 kHz, 400 kHz, 1 MHz, and 3.4 MHz) and an SPI serial standard interface.

The system can be configured to generate an interrupt signal for free-fall, motion detection and magnetic field detection.

The magnetic and accelerometer blocks can be enabled or put into power-down mode separately.

Documents: Datasheet - Application note

Usage

To use this driver, import this crate and an embedded_hal implementation, then instantiate the device.

Please find additional examples using hardware in this repository: driver-examples

use linux_embedded_hal::I2cdev;
use lsm303agr::{AccelOutputDataRate, Lsm303agr};

fn main() {
    let dev = I2cdev::new("/dev/i2c-1").unwrap();
    let mut sensor = Lsm303agr::new_with_i2c(dev);
    sensor.init().unwrap();
    sensor.set_accel_odr(AccelOutputDataRate::Hz50).unwrap();
    loop {
        if sensor.accel_status().unwrap().xyz_new_data {
            let data = sensor.accel_data().unwrap();
            println!("Acceleration: x {} y {} z {}", data.x, data.y, data.z);
        }
    }
}

Support

For questions, issues, feature requests, and other changes, please file an issue in the github project.

License

Licensed under either of

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

lsm303agr-rs's People

Contributors

eldruin avatar robyoung avatar dam4rus avatar hargonix avatar chrysn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.