#imu #embedded #mpu6050

mpu6050

Platform agnostic driver for MPU6050 6-axis IMU

5 releases

0.1.4 Feb 20, 2021
0.1.3 Jun 6, 2019
0.1.2 Apr 24, 2019
0.1.1 Apr 15, 2019
0.1.0 Apr 15, 2019

#58 in Hardware support

Download history 6/week @ 2020-11-14 13/week @ 2020-11-21 8/week @ 2020-11-28 10/week @ 2020-12-05 2/week @ 2020-12-12 19/week @ 2020-12-19 8/week @ 2020-12-26 18/week @ 2021-01-02 51/week @ 2021-01-09 26/week @ 2021-01-16 9/week @ 2021-01-23 9/week @ 2021-01-30 13/week @ 2021-02-06 15/week @ 2021-02-13 28/week @ 2021-02-20 11/week @ 2021-02-27

69 downloads per month

MIT license

36KB
565 lines

mpu6050 crates.io CircleCI

no_std driver for the MPU6050 6-axis IMU

What Works

  • Reading the accelerometer, gyroscope, temperature sensor
    • raw
    • scaled
    • roll/pitch estimation
  • Motion Detection
  • Setting Accel/Gyro Ranges/Sensitivity
  • Setting Accel HPF/LPF

Basic usage

To use this driver you must provide a concrete embedded_hal implementation. Here's a linux_embedded_hal example

use mpu6050::*;
use linux_embedded_hal::{I2cdev, Delay};
use i2cdev::linux::LinuxI2CError;

fn main() -> Result<(), Mpu6050Error<LinuxI2CError>> {
  let i2c = I2cdev::new("/dev/i2c-1")
          .map_err(Mpu6050Error::I2c)?;

  let mut delay = Delay;
  let mut mpu = Mpu6050::new(i2c);

  mpu.init(&mut delay)?;

  loop {
    // get roll and pitch estimate
    let acc = mpu.get_acc_angles()?;
    println!("r/p: {:?}", acc);

    // get temp
    let temp = mpu.get_temp()?;
    println!("temp: {:?}c", temp);

    // get gyro data, scaled with sensitivity 
    let gyro = mpu.get_gyro()?;
    println!("gyro: {:?}", gyro);

    // get accelerometer data, scaled with sensitivity
    let acc = mpu.get_acc()?;
    println!("acc: {:?}", acc);
  }
}

Dependencies

~3.5MB
~68K SLoC