mpu6050 0.1.2

Platform agnostic driver for MPU6050 6-axis IMU

MPU 6050 Rust Driver

Platform agnostic driver for MPU 6050 6-axis IMU using embedded_hal.

Datasheet | Register Map Sheet

Docs | Crate

Visualization options for testing and development in viz branch

Basic usage - linux_embedded_hal example

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

fn main() -> Result<(), Error<LinuxI2CError>> {
    let i2c = I2cdev::new("/dev/i2c-1")

    let delay = Delay;

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

    println!("Calibrated with bias: {:?}", mpu.get_bias().unwrap());
    println!("Calculated variance: {:?}", mpu.get_variance().unwrap());

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

        // get roll and pitch estimate - averaged accross n readings (steps)
        let acc = mpu.get_acc_angles_avg(Steps(5))?;
        println!("r/p avg: {:?}", acc);

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

        // get temp - averages across n readings (steps)
        let temp = mpu.get_temp_avg(Steps(5))?;
        println!("temp avg: {}c", temp);

        // get gyro data, scaled with sensitivity 
        let gyro = mpu.get_gyro()?;
        println!("gyro: {:?}", gyro);
        // get gyro data, scaled with sensitivity - averaged across n readings (steps) 
        let gyro = mpu.get_gyro_avg(Steps(5))?;
        println!("gyro avg: {:?}", gyro);
        // get accelerometer data, scaled with sensitivity
        let acc = mpu.get_acc()?;
        println!("acc: {:?}", acc);
        // get accelerometer data, scaled with sensitivity - averages across n readings (steps)
        let acc = mpu.get_acc_avg(Steps(5))?;
        println!("acc avg: {:?}", acc);


Note: this example uses API of version on local master branch. Some functions may not be available on published crate yet.

Compile linux example (Raspberry Pi 3B)

files here


$ apt-get install -qq gcc-armv7-linux-gnueabihf libc6-armhf-cross libc6-dev-armhf-cross

and all dependencies in example/Cargo.toml


$ rustup target add armv7-unknown-linux-gnueabihf

To configure the linker use example/.cargo/config

cross-compile with

$ cargo build --target=armv7-unknown-linux-gnueabihf