LSM9DS0
A platform-agnostic Rust driver for the ST LSM9DS0 9-axis IMU (3D accelerometer, 3D gyroscope, 3D magnetometer).
Built on embedded-hal-async traits for I2C and SPI communication.
Features
- I2C and SPI interface support
- Configurable sensor ranges and data rates
- Temperature sensor
- FIFO support
- Interrupt configuration
no_stdcompatible
Usage
Add the dependency to your Cargo.toml:
[]
= "0.1"
I2C
use ;
use Delay;
let interface = init;
let config = new
.with_gyro_enabled
.with_gyro_data_rate
.with_accel_data_rate
.with_mag_mode
.with_temperature_enabled
.with_auto_calibration;
let mut imu = new_with_config;
imu.init.await?;
let = imu.read_gyro.await?; // DegreesPerSecond
let = imu.read_accel.await?; // GForce
let = imu.read_mag.await?; // Gauss
let temp = imu.read_temp.await?; // Celsius
SPI
The LSM9DS0 has separate chip selects for the gyroscope and accelerometer/magnetometer. Provide two SpiDevice instances:
use ;
use Delay;
let interface = init;
let mut imu = new;
imu.init.await?;
Configuration
Sensor parameters can be set at initialization or changed at runtime:
use ;
use Delay;
// At initialization
let config = new
.with_gyro_scale
.with_accel_scale
.with_mag_scale;
// At runtime
imu.set_gyro_scale.await?;
imu.set_accel_data_rate.await?;
// Calibrate the gyroscope and accelerometer during runtime
imu.calibrate_gyro.await?;
imu.calibrate_accel.await?;
Default Configuration
The driver's default configuration matches the device's power-on-reset register values from the datasheet, with two exceptions where the actual hardware defaults differ from the documented values:
| Register | Datasheet | Actual |
|---|---|---|
| CTRL_REG7_XM | 0x02 | 0x03 |
| INT_CTRL_REG_M | 0x00 | 0xE8 |
Examples
See the examples/ directory for platform-specific examples, including RP2040.