-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Trying to build/run example code (Simple_MPU6050_Example or Simple_MPU6050_Basic_Example and probably the others) for PI PICO-W code compiles and downloads to target, but I2C is not working.
Serial output reports that detected MPU6050 at 0x68, with WHOAmI=0x00
Does this regardless of what is connected, even when nothing connected.
After a brief test using a new project and just the Simple_Wire.cpp/h and using the following code:
======
#include "Simple_Wire.h"
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println(F("MyTest_I2C:Start:"));
Simple_Wire myWire;
// scan I2C on Pico board, see what we can find.
Serial.println(F("try call I2C_Scanner()"));
myWire.I2C_Scanner();
}
void loop() {
// put your main code here, to run repeatedly:
}
======
Code correctly identifies when DMP6050 (GY-521) is connected or missing.
Proving that the I2C is working.
====
Further exploration resulted in observation that in you example code, you generally have:
"Simple_MPU6050 mpu;" at the top of the file before setup() or loop().
In my case defining the global "mpu" object before the setup() and initial creation of the Serial.begin() appears to kill I2C.
I am guessing that there is some code race condition preventing I2C setup, or breaking it if Serial.begin() comes after the mpu creation.
I managed to find a HACK that works for my PI PICO-W, but probably is not the correct solution.
I changed the "Simple_MPU6050 mpu;" to "Simple_MPU6050 *mpu;", as a pointer.
Changed ALL "mpu." to "mpu->"
Then in Setup() after the Serial.begin() I added:
"
Simple_MPU6050 myMpu;
mpu = &myMpu;
"
This delayed the creation of the mpu object until after the Serial monitor setup.
BUT this then kills code in loop(), so code in loop() then has to be moved inside setup() at the end in a WHILE loop, otherwise exiting setup() destroys the "mpu" object, but the pointer still points to something.
Another thing I could not work out is how to select different pins for the I2C bus, as Simple_MPU6050 and Simple_Wire classes do not appear to expose a method to allow user selection of alternate I2C pins during creation of the mpu object.