Expand description
A platform-agnostic driver for the BMA400 accelerometer implemented using embedded-hal traits.
§Basic Usage
I²C - cargo add bma400 --features=i2c
// Import an embedded hal implementation
use embedded_hal_mock::eh1::i2c::{Mock, Transaction};
// replace as appropriate w/ hal crate for your MCU
use bma400::{
BMA400,
PowerMode,
Scale,
};
// i2c implements embedded-hal i2c::I2c
let mut accelerometer = BMA400::new_i2c(&mut i2c).unwrap();SPI - cargo add bma400 --features=spi
// Import an embedded hal implementation
use embedded_hal_mock::eh1::spi::{Mock, Transaction};
// replace as appropriate w/ hal crate for your MCU
use bma400::{
BMA400,
PowerMode,
Scale,
};
// spi implements embedded-hal spi::SpiDevice
let mut accelerometer = BMA400::new_spi(&mut spi).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);
}§Features
BMA400 can currently be compiled with the following feature flags:
- i2c: Use I²C
- spi: Use SPI
- float: Enable functions returning floating point values. Currently just
get_temp_celsius() - embedded-hal-async: Swaps blocking API for async API implemented using embedded-hal-async traits
§The Bosch BMA400 Accelerometer
Basic Description 12 bit, digital, triaxial acceleration sensor with smart on-chip motion and position-triggered interrupt features.
Key features
- Small Package Size
- LGA package (12 pins), footprint 2mm x 2mm, height 0.95 mm
- Ultra-low power
- Low current consumption of data acquisition without compromising on performance (< 14.5 µA with highest performance)
- Programmable functionality
- Acceleration ranges ±2g/±4g/±8g/±16g
- Low-pass filter bandwidths = (0.24/0.48)*ODR up to a max. output data read out of 800Hz
- On-chip FIFO
- Integrated FIFO on sensor with 1 KB
- On-chip interrupt features
- Auto-low power/Auto wakeup
- Activity/In-activity
- Step Counter (overall device current consumption 4µA)
- Activity Recognition (Walking, Running, Standing still)
- Orientation detection
- Tap/double tap
- Digital interface
- SPI (4-wire, 3-wire)
- I²C
- 2 interrupt pins
- VDDIO voltage range: 1.2V to 3.6V
- RoHS compliant, halogen-free
Typical applications
- Step Counting with ultra-low current consumption for extensive battery lifetime
- Advanced system power management for mobile applications and (smart) watches
- Fitness applications / Activity Tracking
- Tap / double tap sensing
- Drop detection for warranty logging
- Window/door measurements for climate control and alarm systems
- IoT applications powered by coin cell driven batteries, requiring <1µA and auto-wakeup functionality
For more info on I²C address select, see: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bma400-ds000.pdf#page=108 ↩
Re-exports§
pub use types::*;
Modules§
Structs§
- BMA400
- A BMA400 device
- I2CInterface
- I²C Interface wrapper
- SPIInterface
- SPI Interface wrapper