mpu6050 0.1.1

Platform agnostic driver for MPU6050 6-axis IMU
Documentation

MPU 6050 Rust Driver

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

Datasheet | Register Map Sheet

Docs | Crate

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") // or privide your owm on different platforms
        .map_err(Error::I2c)?;

    let delay = Delay;

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

    loop {
        // get roll and pitch estimate
        match mpu.get_acc_angles() {
            Ok(r) => {
                println!("r/p: {:?}", r);
            },
            Err(_) => {} ,
        }

        // get temp
        match mpu.get_temp() {
            Ok(r) => {
                println!("temp: {}c", r);
            },
            Err(_) => {} ,
        }

        // get gyro data, scaled with sensitivity 
        match mpu.get_gyro() {
            Ok(r) => {
                println!("gyro: {:?}", r);
            },
            Err(_) => {} ,
        }
        
        // get accelerometer data, scaled with sensitivity
        match mpu.get_acc() {
            Ok(r) => {
                println!("acc: {:?}", r);
            },
            Err(_) => {} ,
        }
    }
}

Compile linux example (Rapsberry Pi 3B)

files here

Requirements:

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

and all dependencies in example/Cargo.toml

Rustup:

$ 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

TODO