#arm #cortex-m #stm32 #hal


no_std driver for the MPU9250 & onboard AK8963 (accelerometer + gyroscope + magnetometer IMU)

38 releases

Uses old Rust 2015

0.25.0 Jul 29, 2023
0.24.1 Aug 8, 2022
0.24.0 Oct 14, 2020
0.22.2 Jun 14, 2020
0.7.3 Oct 7, 2018

#117 in Hardware support

Download history 84/week @ 2023-11-01 26/week @ 2023-11-08 65/week @ 2023-11-15 66/week @ 2023-11-22 172/week @ 2023-11-29 18/week @ 2023-12-06 69/week @ 2023-12-13 70/week @ 2023-12-20 53/week @ 2023-12-27 60/week @ 2024-01-03 32/week @ 2024-01-10 48/week @ 2024-01-17 70/week @ 2024-01-24 51/week @ 2024-01-31 25/week @ 2024-02-07 415/week @ 2024-02-14

587 downloads per month
Used in pixracer_bsp


2.5K SLoC


no_std driver for the MPU9250 (and some MPU* devices) & onboard AK8963 (accelerometer + gyroscope + magnetometer IMU).

Build Status

What works

  • Reading the accelerometer, gyroscope, temperature sensor, and magnetrometer: both raw and scaled and converted values.
  • Setting DLPF, reading scales, sample rate divisor.
  • Reading the WHO_AM_I registers of mpu9250 and ak8963.
  • Getting resolutions and factory sensitivities.

Supported chips

  • MPU9250 -- Imu and Marg;
  • MPU9255 -- Imu and Marg;
  • MPU6500 -- Imu only.


MPU9255 has some extra capability in the ASIC that allows some additional gesture control but otherwise this chip is identical to the MPU9250.

Basic usage

Include library as a dependency in your Cargo.toml crates.io:

version = "<version>"

Use embedded-hal implementation to get SPI, NCS, and delay, then create mpu handle:

extern crate mpu9250; // or just use mpu9250; if 2018 edition is used.

// to create sensor with mag support and default configuration:
let mut _imu = Mpu9250::marg_default(spi, ncs, &mut delay)?;
// to create sensor without mag support and default configuration:
let mut marg = Mpu9250::imu_default(spi, ncs, &mut delay)?;
// to get all supported measurements:
let all = marg.all()?;
println!("{:?}", all);

More examples

Number of examples can be found in proving-ground repo. Examples include: reading temperature, calibrating magnetrometer, reading all sensors.

Experimental I2C support

Expiremntal I2C support is enabled via i2c feature flag. When enabled, SPI support will be deactivated and type of mpu9250 driver will change from Mpu9250<SpiDevice<SPI, NCS>, MODE> will change to Mpu9250<I2cDevice<I2C>, Imu>.

The MPU9250 currently supports an IMU-only configuration. See the BeagleBone Blue example for a demonstration. Support for the AK8963 is a WPI.


API Docs available on docs.rs.


Licensed under either of

at your option.


Started off as a fork of japaric's mpu9250 repo.