drogue-mpu-6050

Crates.iodrogue-mpu-6050
lib.rsdrogue-mpu-6050
version0.1.0
sourcesrc
created_at2020-10-19 18:23:57.813237
updated_at2020-10-19 18:23:57.813237
descriptionInvenSense MPU-6050 i2c Driver
homepage
repositoryhttps://github.com/drogue-iot/drogue-mpu-6050
max_upload_size
id303036
size42,228
Bob McWhirter (bobmcwhirter)

documentation

README

crates.io docs.rs Matrix

drogue-mpu-6050

i2c Driver for the InvenSense MPU-6050 motion-processor.

Advanced DMP

This driver can load the appropriate firmware for quaternion-based DMP processing on-chip.

Set up

i2c

Initialize your i2c bus per usual:

let scl3 = gpioc.pc0.into_open_drain_output(&mut gpioc.moder, &mut gpioc.otyper).into_af4(&mut gpioc.moder, &mut gpioc.afrl);
let sda3 = gpioc.pc1.into_open_drain_output(&mut gpioc.moder, &mut gpioc.otyper).into_af4(&mut gpioc.moder, &mut gpioc.afrl);
let i2c = I2c::i2c3(device.I2C3, (scl3, sda3), KiloHertz(100), clocks, &mut rcc.apb1r1);

MPU driver

The MPU driver requires an embedded-time capable clock.

let sensor = Mpu6050::new(i2c, Address::default(), &CLOCK).unwrap();

Once your clock is ticking, you may then manipulate the MPU. For ease, the initialize_dmp() method is provided to set up reasonable configurations and load the DMP firmware into the processor.

let sensor: &mut Mpu6050<'_, _, _> = ctx.resources.sensor;
sensor.initialize_dmp().unwrap();

If using the advanced on-chip DMP logic, the FIFO will contain 28-byte packets of quaternion and other data.

The first 16 bytes are quaternions, which can be constructed using the Quaternion class.

let len = sensor.get_fifo_count().unwrap();
if len >= 28 {
    let buf = sensor.read_fifo(&mut buf).unwrap();
    let q = Quaternion::from_bytes(&buf[0..16]).unwrap().normalize();
    ....
}

A quaternion may also be converted into a Euler or YawPitchRoll measurement.

Commit count: 4

cargo fmt