7 releases

0.1.6 Nov 3, 2022
0.1.5 Jan 10, 2022
0.1.4 Feb 20, 2021
0.1.3 Jun 6, 2019
0.1.2 Apr 24, 2019

#1217 in Hardware support

Download history 204/week @ 2024-07-21 135/week @ 2024-07-28 486/week @ 2024-08-04 86/week @ 2024-08-11 310/week @ 2024-08-18 306/week @ 2024-08-25 236/week @ 2024-09-01 203/week @ 2024-09-08 210/week @ 2024-09-15 339/week @ 2024-09-22 133/week @ 2024-09-29 47/week @ 2024-10-06 421/week @ 2024-10-13 404/week @ 2024-10-20 292/week @ 2024-10-27 576/week @ 2024-11-03

1,697 downloads per month
Used in 3 crates

MIT license

37KB
584 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
~65K SLoC