| Crates.io | mpu6050-dmp |
| lib.rs | mpu6050-dmp |
| version | 0.6.1 |
| created_at | 2022-03-02 19:14:12.484518+00 |
| updated_at | 2025-08-25 08:44:54.879395+00 |
| description | Platform-independent I2C driver for MPU6050. Supports DMP usage. Fork of drogue-mpu-6050 which uses only embedded-hal traits (no dependency on embedded-time or drogue-embedded-timer). |
| homepage | |
| repository | https://github.com/barafael/mpu6050-dmp-rs |
| max_upload_size | |
| id | 542490 |
| size | 146,655 |
mpu6050-dmpPlatform-independent i2c Driver for the InvenSense MPU-6050 motion-processor.
Reasons/differences:
drogue-embedded-timer and embedded-time removed
log removedpitch -= PI)The examples directory contains several examples demonstrating different features:
See the examples README for detailed information.
This driver can load the appropriate firmware for quaternion-based on-chip DMP processing.
Initialize your i2c bus:
let gpiob = dp.GPIOB.split();
let scl = gpiob
.pb8
.into_alternate()
.internal_pull_up(true)
.set_open_drain();
let sda = gpiob
.pb9
.into_alternate()
.internal_pull_up(true)
.set_open_drain();
let i2c = dp.I2C1.i2c((scl, sda), 400.kHz(), &clocks);
let sensor = Mpu6050::new(i2c, Address::default()).unwrap();
The MPU-6050 includes an on-chip temperature sensor. Temperature readings are available through the temperature() method when the temperature feature is enabled (enabled by default):
// Get temperature reading
let temp = sensor.temperature().unwrap();
println!("Temperature: {}°C", temp.celsius());
Setting up the DMP requires temporary exclusive access to a blocking delay implementation.
The initialize_dmp(&mut delay) method is provided to set up reasonable configurations and load the DMP firmware into the processor.
sensor.initialize_dmp(&mut delay).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[..16]).unwrap().normalize();
let ypr = YawPitchRoll::from(quat);
rprintln!("{:?}", ypr);
}