Crates.io | bma400 |
lib.rs | bma400 |
version | 0.2.0 |
source | src |
created_at | 2023-03-14 19:59:12.440193 |
updated_at | 2023-10-29 17:34:59.092398 |
description | A platform-agnostic Rust driver for the BMA400 12-bit ultra-low-power 3-axis accelerometer. |
homepage | |
repository | https://github.com/cfrenette/bma400-rs |
max_upload_size | |
id | 810108 |
size | 1,494,350 |
A platform-agnostic Rust driver for the BMA400 accelerometer implemented using embedded-hal
traits
I²C - cargo add bma400 --features=i2c-default
// Import an embedded hal implementation
use linux_embedded_hal::I2cdev; // replace as appropriate w/ hal crate for your MCU
use bma400::{
BMA400,
PowerMode,
Scale,
};
// i2c implements embedded-hal i2c::WriteRead and i2c::Write
let mut accelerometer = BMA400::new_i2c(i2c).unwrap();
SPI - cargo add bma400 --features=spi
// Import an embedded hal implementation
use linux_embedded_hal::{
Spidev,
Pin
}; // replace as appropriate w/ hal crate for your MCU
use bma400::{
BMA400,
PowerMode,
Scale,
};
// spi implements embedded-hal spi::Transfer and spi::Write
// csb_pin implements embedded-hal digital::v2::OutputPin
let mut accelerometer = BMA400::new_spi(spi, csb_pin).unwrap();
From here it's the same API for both:
// The accelerometer is in sleep mode at power on
// Let's wake it up and set the scale to 2g
accelerometer
.config_accel()
.with_power_mode(PowerMode::Normal)
.with_scale(Scale::Range2G)
.write().unwrap();
// Read a single measurment
if let Ok(measurement) = accelerometer.get_data() {
assert_eq!(30, measurement.x);
assert_eq!(16, measurement.y);
assert_eq!(988, measurement.z);
}
For a full example using the tap interrupt mapped to a GPIO pin on the nrf52833, see examples/
.
(from the manufacturer)
12 bit, digital, triaxial acceleration sensor with smart on-chip motion and position-triggered interrupt features.
Licensed under your choice of either:
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 licensed as above, without any additional terms or conditions.