bolderflight / invensense-imu

Arduino and CMake library for communicating with the InvenSense MPU-6500, MPU-9250 and MPU-9255 nine-axis IMUs.
MIT License
497 stars 210 forks source link

Library not working with ESP-32 #95

Closed JanKuceraCF closed 2 years ago

JanKuceraCF commented 2 years ago

At least that is my suspicion. The MPU-9250 works with asukiaaa library, but can only read gyro and acceleration values, not magnetometer. The problem currently to me appears to be that the ESP-32 is using different pins for I2C communication. The mentioned library (asukiaaa) allows for I2C pins definition. I did not figure out how to do such in this library. Maybe it is some value that can be altered in the .ccp or .h files?

flybrianfly commented 2 years ago

In the past, the issue was the core designers of ESP-32 didn't implement an I2C repeated start properly. You may want to try replacing endTransmission(false) with endTransmission() throughout the code.

This library doesn't do anything with the pins; as you notice, you pass it the I2C bus object to use. Ensure you're passing the correct I2C bus object. Some core modules let you use setSCL or setSDA to set alternative pin definitions. I'm not sure how ESP-32 does this, but you would call those methods outside of this library.

JanKuceraCF commented 2 years ago

The second suggestion... I can initialize Wire object with custom pins via Wire.begin(#SDA_PIN,#SCL_PIN); Problem I have with that is that (most likely on my side) I have no idea what to actually do with it, since when initializing the MPU9250 object it uses the Wire object already well outside the setup method where I can call the Wire.begin(SDA,SCL) and as far as I was able to figure out there is no method to give the MPU-9250 object different Wire at later point after the object is created.

The first one, when I changed the endTransmission(false) as suggested it started returning error -5, which, if I am reading it right means that the ID of the sensor is not actually 113 or 115. I can confirm that as the ID that the other mentioned library returns is 112. If I alter the check to accept id 112 then it fails later with status code -14. If I bypass that by not returning -14 by returning the value of whoAmIAK8963() the console shows nothing. But it does start returning data... on gyro, acceleration and temperature, no mag values... which means 3 things.

1) I don't actually need to set the Wire object as it seems to be set correctly on its own. 2) Show I barely know what I am doing 3) I probably got 'scammed' and got the MPU-6500 instead of MPU-9250, wouldn't expect that from local shop

and 4) sorry to take your time for nothing :)

flybrianfly commented 2 years ago

That's not too uncommon and, unfortunately, we've seen it cropping up more recently.