Skip to main content

Crate mpu6050_driver

Crate mpu6050_driver 

Source
Expand description

§mpu6050-driver

no_std embedded-hal 1.0 driver for the InvenSense MPU-6050 6-axis IMU.

§Quick start

use mpu6050_driver::{
    AccelRange, Address, Dlpf, GyroRange, Mpu6050, raw_to_imu_sample,
};

let mut mpu = Mpu6050::new(i2c, Address::Ad0Low);

mpu.wake()?;
mpu.set_accel_range(AccelRange::G2)?;
mpu.set_gyro_range(GyroRange::Dps250)?;
mpu.set_dlpf(Dlpf::Cfg2)?;
mpu.set_sample_rate_divider(4)?; // ~200 Hz with Cfg2

let _identity = mpu.identity()?;
let raw = mpu.read_raw_accel_gyro_temp()?;
let _sample = raw_to_imu_sample(raw);

Provide any type that implements embedded_hal::i2c::I2c. Use Address::Ad0Low (0x68) or Address::Ad0High (0x69) according to the AD0 pin wiring.

§What this crate covers

§Is this module usable?

This crate does not authenticate chips or detect clones. Mpu6050::identity only decodes WHO_AM_I.

After bring-up, hold the board still and check ImuSample::accel_magnitude_g (near 1 g) and ImuSample::gyro_magnitude_dps (near zero aside from bias/noise). See the stationary_usability example. Large sustained errors usually mean wiring, power, address, or configuration problems — not a branding verdict.

Multi-sample threshold reports live in the mpu6050-validation-workspace (imu-tool), not in this published crate.

Structs§

FifoReadDiagnostics
Low-level FIFO diagnostics for streaming/debug burst reads.
ImuSample
IntStatus
InterruptEnable
The complete INT_ENABLE register state.
Mpu6050
Blocking MPU-6050 driver over an embedded_hal::i2c::I2c bus.
RawAccelGyroTemp
Raw accel/temp/gyro register block read from ACCEL_XOUT_H.
RawRetryPolicy
Policy controlling how many suspicious raw reads are retried and whether the final suspicious sample is rejected or accepted when retries are exhausted.

Enums§

AccelRange
Accelerometer full-scale range (ACCEL_CONFIG AFS_SEL).
Address
MPU6050 I2C address selected by the AD0 pin.
Dlpf
Digital low-pass filter configuration from the CONFIG register.
DlpfReadError
Error returned while reading the digital low-pass filter configuration.
GyroRange
Gyroscope full-scale range (GYRO_CONFIG FS_SEL).
Identity
Decoded device family from the WHO_AM_I register.
RawReadOutcome
Result of a checked raw read, including retry/recovery details.
RawSampleSuspicion
Reason a raw accel/temp/gyro sample was classified as suspicious.

Constants§

ACCEL_LSB_PER_G_2G
FIFO_ACCEL_GYRO_FRAME_BYTES
Bytes per FIFO frame for accel XYZ + gyro XYZ, no temp/ext slaves.
GYRO_LSB_PER_DPS_250DPS
TEMP_LSB_PER_DEG_C
TEMP_OFFSET_DEG_C

Functions§

raw_to_imu_sample