Closed truppelito closed 2 years ago
After discussing for a bit here it seems the issue is with the esp-hal. I will leave this open in case anyone wants to comment further, but also feel free to close it.
How about tagging the question with [SOLVED], for visibility?
First of all, I realise this may not be the best place to ask this question. I know this crate is for a general hal, not specifically for ESP32 and esp-hal, but maybe someone will have some intuition about this and help me find a solution. Or feel free to remove this issue.
Problem:
I'm trying to use an MPU6050 with an ESP32 using the esp-hal and this crate.
Hardware:
I'm using a breakout board like this one. Connections are very easy: power, GND, SDA and SCL connected directly to the ESP32.
I can confirm this hardware works perfectly when using the Arduino environment and the Adafruit MPU6050 library. The I2C address used is the default (0x68).
Rust software:
Using the aforementioned esp-hal crate, along with this one, I wrote this test code:
This code is based on the
cargo generate
from here with the I2C additions from the example code in the esp-hal crate.Error:
The code from above, on the exact same hardware that works on the Arduino environment, gives the following error:
Line 44 is
mpu.init(&mut delay).unwrap();
. I know that the very first command being sent to the MPU (self.write_byte(PWR_MGMT_1::ADDR, 0x01)?;
) is not working (I tested that command specifically).The weirdest part is that, over 100+ tries, it actually worked exactly once, randomly, with no code changes (or any other reason for it to start working, for that matter). The loop started running and outputting values. Although I didn't check the MEMS values, the temperature printed was around 25ºC, which is completely correct for where I am. After this one time it worked, it never worked again.
I feel like I must be missing something very obvious, but for the life of me I cannot figure it out, and ESP32 Rust examples are sparse on the internet. Any help is appreciated!