Go Down

Topic: Help getting MPU6050 working with Arduino Due (Read 2500 times) previous topic - next topic

bhowiebkr

I'm using an Arduino Due to try and read the DMP values off of an MPU-6050 sensor. Currently it works half the time than brakes needing to cut the power to the board when it gives this error:

Testing device connections...
MPU6050 connection failed
DMP Initialization failed (code 1)


The problem is that it looks like the I2Cdev library is broken for the Due? Something about Wire.endTransmission being broken for the Due?

It sucks because I've been working on a project built around the Due and didn't expect these kinds of issues to come up.

I'm using the I2Cdev and MPU6050 libraries found here:
https://github.com/jrowberg/i2cdevlib/tree/master/Arduino

I'm not sure what areas need to be fixed could this be one of them?

Starting at line 269:

Code: [Select]
#elif (ARDUINO > 100)
            // Arduino v1.0.1+, Wire library
            // Adds official support for repeated start condition, yay!

            // I2C/TWI subsystem uses internal buffer that breaks with large data requests
            // so if user requests more than BUFFER_LENGTH bytes, we have to do it in
            // smaller chunks instead of all at once
            for (uint8_t k = 0; k < length; k += min(length, BUFFER_LENGTH)) {
                Wire.beginTransmission(devAddr);
                Wire.write(regAddr);
                Wire.endTransmission();
                Wire.beginTransmission(devAddr);
                Wire.requestFrom(devAddr, (uint8_t)min(length - k, BUFFER_LENGTH));
       
                for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) {
                    data[count] = Wire.read();
                    #ifdef I2CDEV_SERIAL_DEBUG
                        Serial.print(data[count], HEX);
                        if (count + 1 < length) Serial.print(" ");
                    #endif
                }
            }
        #endif


Is it possible someone here has successfully gotten the Arduino Due and the MPU6050 working correctly and can help?

Thanks!


SurferTim

#1
Jun 05, 2016, 01:55 am Last Edit: Jun 05, 2016, 02:55 am by SurferTim
I2C is not broken on the Due. I've ran it for days at a time without a failure. Have you tried the i2cscanner sketch to see if you are using the correct address?
http://playground.arduino.cc/Main/I2cScanner

edit: The I2C address could be 0x68 or 0x69, depending on the state of AD0. If that pin is floating, it could be changing.

And this. I found some devices require a short delay here.
Code: [Select]
                Wire.endTransmission();
                delayMicroseconds(100); // add this delay
                Wire.beginTransmission(devAddr);


Wait. That was wrong. There is no beginTransmission for a requestFrom.
Code: [Select]
            Wire.beginTransmission(devAddr);
            Wire.write(regAddr);
            Wire.endTransmission();
            delayMicroseconds(100);
            Wire.requestFrom(devAddr, (uint8_t)min(length - k, BUFFER_LENGTH));


       

bhowiebkr

I have my MPU6050 configured to address 0x68.  The i2c scanner works but not all the time. Sometimes it will not show any of the sensors on the i2c bus at a similar rate to the MPU6050 working or not. In my case I have 3 sensors on the i2c bus.

Either it'll show them all or none at all.

When the sensor sketch does run correctly, it'll run fine without stopping. But sometimes when you reset the arduino or uploading a new sketch, it'll not work at all until you cut all power to the arduino and plug it back in again.

 I've also tested this with just an MPU9150 on the i2c bus and it'll not work half the time too. So I think I've ruled out that it's not the sensors.

The code that you are pointing out that might be the issue is from the I2Cdev.cpp file found here:
https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/I2Cdev/I2Cdev.cpp

Could this be the reason why I'm having these reliability issues.

SurferTim

I have problems with my Due starting after a power down. It needs a reset either by pressing the reset button or connecting with the serial monitor. I don't know exactly why that is. There is a way to fix that with a hardware modification to the Due board. 

I use the wire library included with the IDE.

Go Up