jrowberg / i2cdevlib

I2C device library collection for AVR/Arduino or other C++-based MCUs
http://www.i2cdevlib.com
3.95k stars 7.51k forks source link

MPU6050 problems with Arduino 101 #511

Open taniaxue opened 4 years ago

taniaxue commented 4 years ago

Hi,

I have some code based on the MPU6050 DMP example (modified to poll the FIFO buffer, no interrupts). I've ran my code multiple times on both a Arduino Pro Mini and Arduino 101. It works perfectly with the Arduino Pro Mini but crashes frequently with the Arduino 101.

One of the many crashes/errors I get when using the Arduino 101 is that it often loses connection with the MPU6050 - I check this by having this in the loop(): while (!mpu.testConnection()){...}. Sometimes it manages to restart itself when I run the following lines in that while loop:

    Wire.begin(); //initialise the wire library and join I2C bus as master device
    Wire.beginTransmission(0x68); // transmit to device at I2Caddress
    Wire.write(0x6B); // access the power management register PWR_MGMT_1
    Wire.write(0); // set to zero to wake the MPU-6050
    Wire.endTransmission(1); // end the transmission

(Side question: why does the MPU6050 frequently disconnect?)

However, often when it restarts successfully, it either gets stuck in the FIFO overflow condition or alternates between FIFO overflow and outputting random ypr values, e.g. without moving the MPU6050, it gives values like this:

        mpu_ypr:    -84.45  25.88   5.49
        mpu_ypr:    58.90   7.19    48.29
        mpu_ypr:    74.57   24.00   42.93
        mpu_ypr:    -51.09  -26.73  32.93
        mpu_ypr:    101.74  -38.78  -17.80

Is there a problem with the Arduino 101 that causes frequent errors with the MPU6050? I have heard possible issues with Arduino 101 and I2C (e.g. https://github.com/arduino/ArduinoCore-arc32/issues/238) but I'm not sure if those are related to this or not.

Thanks.

taniaxue commented 4 years ago

Update: I think the I2C and Arduino 101 bug was the problem as the errors were fixed when I updated the board under Arduino IDE's Tools > Board > Boards Manager.

taniaxue commented 4 years ago

After more testing, the disconnection issue is still occurring quite frequently and sometimes the resetting sequence does not work. What would be the causes of frequent disconnection throughout the program?