3.8 KiB
3.8 KiB
mpu6050

no_std driver for the MPU6050 6-axis IMU
Datasheet | Register Map Sheet
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<(), 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);
}
}
Linux example (Raspberry Pi 3B)
Cross compile
Requirements:
$ apt-get install -qq gcc-arm-linux-gnueabihf libc6-armhf-cross libc6-dev-armhf-cross
Rustup:
$ rustup target add armv7-unknown-linux-gnueabihf
To configure the linker use .cargo/config
file
cross-compile with
$ cargo build --examples --target=armv7-unknown-linux-gnueabihf
Copy binary to rpi, once steps below are successfully completed.
On RPi (RPi OS lite, 15.02.21)
Install i2c dependencies
$ sudo apt-get install i2c-tools libi2c-dev python-smbus -y
Enable and load kernel modules at boot
- edit
/etc/modules
and addi2c-dev i2c-bcm2708
- edit
/boot/config.txt
and add/uncommentdtparam=i2c_arm=on dtparam=i2c1=on
- reboot
- check if working with
sudo i2cdetect -y 1
orsudo i2cdetect -y 0
. You should bet a signal similar to this0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- 68 -- -- -- -- 70: -- -- -- -- -- -- -- --
- Wire up
RPi GPIO MPU6050 5V Power VCC Ground GND GPIO 2 SCL GPIO 3 SDA
TODO
- init with default settings
- init with custom settings
- custom sensitivity
- custom device initialization
- device verification
- basic feature support as described here
- rename constants to better match datasheet
- complementary filter for roll, pitch estimate, possible on device?
- low pass filter registers? How to use?
- sample rate devider with register 25? or timer/clock control with PWR_MGMT_2
- internal clock, register 108
POWER_MGMT_2
, will cycle between sleep mode and waking up to take a single sample of data from active sensors at a rate determined by LP_WAKE_CTRL (page 41-43)
- internal clock, register 108
- plotting csv datafor testing? -> See viz branch