Crates.io | lsm303agr |
lib.rs | lsm303agr |
version | 1.1.0 |
source | src |
created_at | 2020-09-13 14:49:19.452116 |
updated_at | 2024-06-24 20:22:39.087171 |
description | Platform-agnostic Rust driver for the LSM303AGR ultra-compact high-performance eCompass module: ultra-low-power 3D accelerometer and 3D magnetometer. |
homepage | https://github.com/eldruin/lsm303agr-rs |
repository | https://github.com/eldruin/lsm303agr-rs |
max_upload_size | |
id | 288202 |
size | 174,963 |
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 also supports the [embedded-hal-async
] traits if the async
feature is enabled.
This driver allows you to:
new_with_i2c()
.init()
.acceleration()
.accel_status()
.set_accel_mode_and_odr()
.set_accel_scale()
.accelerometer_id()
.temperature_status()
.temperature()
.acc_set_fifo_mode()
.acc_enable_interrupt()
.mag_status()
.into_mag_continuous()
.magnetic_field()
.set_mag_mode_and_odr()
.magnetometer_id()
.enable_mag_offset_cancellation()
.mag_enable_low_pass_filter()
.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
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::{Delay, I2cdev};
use lsm303agr::{AccelMode, 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_mode_and_odr(&mut Delay, AccelMode::Normal, AccelOutputDataRate::Hz50)
.unwrap();
loop {
if sensor.accel_status().unwrap().xyz_new_data() {
let data = sensor.acceleration().unwrap();
println!(
"Acceleration: x {} y {} z {}",
data.x_mg(),
data.y_mg(),
data.z_mg()
);
}
}
}
For an example of using the async support of this driver on a micro:bit V2, have a look at microbit-v2 example.
For questions, issues, feature requests, and other changes, please file an issue in the github project.
Licensed under either of
at your option.
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.