1
Fork 0
Find a file
2019-04-16 00:58:12 +02:00
.cargo compile target arm-v7 2019-04-15 21:13:47 +02:00
src comments 2019-04-16 00:58:12 +02:00
.gitignore add gitignore 2019-04-15 21:13:59 +02:00
Cargo.toml MIT license 2019-04-16 00:46:10 +02:00
LICENSE Update LICENSE 2019-04-16 00:45:44 +02:00
README.md Update README.md with linux example, image 2019-04-16 00:03:05 +02:00

MPU 6050 Rust Driver

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

Datasheet

Register Map Sheet

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")
        .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

  • full file here
  • Requirements: apt-get install -qq gcc-arm-linux-gnueabihf libc6-armhf-cross libc6-dev-armhf-cross
  • cross-compile with cargo build --bin main --target=arm-unknown-linux-gnueabihf

TODO