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
- Power:
Mpu6050::wake,Mpu6050::reset - Identity:
Mpu6050::who_am_i,Mpu6050::identity - Ranges / filter / rate:
Mpu6050::set_accel_range,Mpu6050::set_gyro_range,Mpu6050::set_dlpf,Mpu6050::set_sample_rate_divider - Motion reads:
Mpu6050::read_raw_accel_gyro_temp,Mpu6050::read_raw_checked,Mpu6050::read_raw_with_retry - FIFO and interrupts: see the
fifoand interrupt helpers onMpu6050 - Conversion:
raw_to_imu_sample,RawAccelGyroTemp::temp_degrees_c - Magnitudes:
ImuSample::accel_magnitude_g,ImuSample::gyro_magnitude_dps
§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§
- Fifo
Read Diagnostics - Low-level FIFO diagnostics for streaming/debug burst reads.
- ImuSample
- IntStatus
- Interrupt
Enable - The complete
INT_ENABLEregister state. - Mpu6050
- Blocking MPU-6050 driver over an
embedded_hal::i2c::I2cbus. - RawAccel
Gyro Temp - Raw accel/temp/gyro register block read from ACCEL_XOUT_H.
- RawRetry
Policy - Policy controlling how many suspicious raw reads are retried and whether the final suspicious sample is rejected or accepted when retries are exhausted.
Enums§
- Accel
Range - Accelerometer full-scale range (
ACCEL_CONFIGAFS_SEL). - Address
- MPU6050 I2C address selected by the AD0 pin.
- Dlpf
- Digital low-pass filter configuration from the CONFIG register.
- Dlpf
Read Error - Error returned while reading the digital low-pass filter configuration.
- Gyro
Range - Gyroscope full-scale range (
GYRO_CONFIGFS_SEL). - Identity
- Decoded device family from the
WHO_AM_Iregister. - RawRead
Outcome - Result of a checked raw read, including retry/recovery details.
- RawSample
Suspicion - 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