1
Fork 0
Find a file
2019-04-23 15:41:13 +02:00
example calculate variance from sensor data 2019-04-23 15:41:13 +02:00
src calculate variance from sensor data 2019-04-23 15:41:13 +02:00
.gitignore fix .gitignore mistake 2019-04-16 01:01:43 +02:00
Cargo.toml separate linux example from core 2019-04-16 00:58:34 +02:00
LICENSE Update LICENSE 2019-04-16 00:45:44 +02:00
README.md test TODO done 2019-04-17 19:39:25 +02:00

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")
        .map_err(Error::I2c)?;

    let delay = Delay;

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

    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);
    }
}

Note: this example uses API of version published on crates.io, not local master branch.

Compile linux example (Raspberry 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