juliangaal / mpu6050

MPU6050 embedded-hal driver written in Rust
https://crates.io/crates/mpu6050
MIT License
52 stars 31 forks source link

Make device address configurable #38

Closed nilclass closed 2 years ago

nilclass commented 3 years ago

The i2c address can be changed by pulling the AD0 pin up (Section 6.4, Page 15 of datasheet revision 3.2).

This can be necessary to do if there is an address conflict with another chip.

These changes add functions new_with_addr and new_with_addr_and_sens to deal with this case.

Example:

let mut mpu = Mpu6050::new_with_addr(i2c, 0x69);
juliangaal commented 2 years ago

Thanks for letting me know, and thanks for the PR

EDIT: I think this

https://github.com/juliangaal/mpu6050/blob/e27840bb2514f7e7a18467efd2800860b0a01a6f/src/lib.rs#L169

should be self.slave_addr, If I'm not mistaken. Didn't see that before when I merged

nilclass commented 2 years ago

@juliangaal

Thanks for merging :slightly_smiling_face:

I think this (...) should be self.slave_addr, If I'm not mistaken. Didn't see that before when I merged

I thought so too at first, but when testing I always got 0x68. Looking at the register map documentation, that's expected:

The contents of WHO_AM_I are the upper 6 bits of the MPU-60X0’s 7-bit I2C address.
The least significant bit of the MPU-60X0’s I2C address is determined by the value of the AD0 pin.
The value of the AD0 pin is not reflected in this register.