Connecting four MPU-6050 with Arduino Due on I2C

Hello

I have four MPU-6050 (http://playground.arduino.cc/Main/MPU-6050) IMU’s connected to my Arduino Due via the two I2C buses.

I only want to read accelerometer data but my code to simply read the raw data doesn’t seem to be working.
When I say not working I mean, I can see x/y/z data on my terminal window from all four accelerometers. However, when I move one accelerometer when the other three are stationary all the data from all four accelerometers changes. I’d think that if only one moved, the others should stay at a relatively constant value. Does anyone have any ideas what could be wrong?

I’ve attached a diagram of how I connected my four MPU-6050 to the Arduino.

// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
// 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
//     2011-10-07 - initial release

/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accel_i2c_68(MPU6050_ADDRESS_AD0_LOW);
MPU6050 accel_i2c_69(MPU6050_ADDRESS_AD0_HIGH);
MPU6050 accel_i2c1_68(MPU6050_ADDRESS_AD0_LOW);
MPU6050 accel_i2c1_69(MPU6050_ADDRESS_AD0_HIGH);

// Declare 12 acceleration vars, 3 for each of the four IMU's
int16_t ax68, ay68, az68, ax69, ay69, az69, ax68_1, ay68_1, az68_1, ax69_1, ay69_1, az69_1;

#define LED_PIN 13
bool blinkState = false;

void setup() {
    // join both I2C bus on Arduino Due
    Wire.begin();
    Wire1.begin();

    // initialize serial communication
    Serial.begin(9600);

    // initialize four IMU devices
    Serial.println("Initializing I2C devices...");
    accel_i2c_68.initialize();
    accel_i2c_68.setFullScaleAccelRange(MPU6050_ACCEL_FS_16);
    
    accel_i2c_69.initialize();
    accel_i2c_69.setFullScaleAccelRange(MPU6050_ACCEL_FS_16);
    
    accel_i2c1_68.initialize();
    accel_i2c1_68.setFullScaleAccelRange(MPU6050_ACCEL_FS_16);
    
    accel_i2c1_69.initialize();
    accel_i2c1_69.setFullScaleAccelRange(MPU6050_ACCEL_FS_16);

    // verify connection of all four IMU's
    Serial.println("Testing device connections...");
    Serial.println(accel_i2c_68.testConnection() ? "MPU6050 68 connection successful" : "MPU6050 68 connection failed");
    Serial.println(accel_i2c_69.testConnection() ? "MPU6050 69 connection successful" : "MPU6050 69 connection failed");
    Serial.println(accel_i2c1_68.testConnection() ? "MPU6050 1 68 connection successful" : "MPU6050 1 68 connection failed");
    Serial.println(accel_i2c1_69.testConnection() ? "MPU6050 1 69 connection successful" : "MPU6050 1 69 connection failed");

    // configure Arduino LED for
    pinMode(LED_PIN, OUTPUT);
}

void loop() {
    
    // read only acceleration raw data from all four IMU's
    accel_i2c_68.getAcceleration(&ax68, &ay68, &az68);
    accel_i2c_69.getAcceleration(&ax69, &ay69, &az69);
    accel_i2c1_68.getAcceleration(&ax68_1, &ay68_1, &az68_1);
    accel_i2c1_69.getAcceleration(&ax69_1, &ay69_1, &az69_1);

    // display tab-separated accel x/y/z values, divide by 2048.0 to get g-force values
    Serial.print("a:\t");
    Serial.print(ax68/2048.0); Serial.print("\t");
    Serial.print(ay68/2048.0); Serial.print("\t");
    Serial.print(az68/2048.0); Serial.print("\t");
    Serial.print(ax69/2048.0); Serial.print("\t");
    Serial.print(ay69/2048.0); Serial.print("\t");
    Serial.print(az69/2048.0); Serial.print("\t");
    Serial.print(ax68_1/2048.0); Serial.print("\t");
    Serial.print(ay68_1/2048.0); Serial.print("\t");
    Serial.print(az68_1/2048.0); Serial.print("\t");
    Serial.print(ax69_1/2048.0); Serial.print("\t");
    Serial.print(ay69_1/2048.0); Serial.print("\t");
    Serial.println(az69_1/2048.0);

    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);
}

arduino.jpg

but my code to simply read the raw data doesn’t seem to be working.

The code does something. You haven’t said what it does.
You expect the code to do something. You haven’t said what that is.

All that we can surmise is that what it does is not what you want. And, therefore, all we can offer is condolences. So, I’m sorry to hear that you are having problems.

PaulS:

but my code to simply read the raw data doesn't seem to be working.

The code does something. You haven't said what it does. You expect the code to do something. You haven't said what that is.

All that we can surmise is that what it does is not what you want. And, therefore, all we can offer is condolences. So, I'm sorry to hear that you are having problems.

Hi PaulS

That was my fault for not describing the output.

When I say not working I mean, I can see x/y/z data on my terminal window from all four accelerometers. However, when I move one accelerometer when the other three are stationary all the data from all four accelerometers changes. I'd think that if only one moved, the others should stay at a relatively constant value.

However, when I move one accelerometer when the other three are stationary all the data from all four accelerometers changes. I'd think that if only one moved, the others should stay at a relatively constant value.

I hate anonymous print()s. You have no idea what you are printing. A bunch of numbers appear in the Serial Monitor, and you have no idea what any given value is. Preface each value with the name of the variable being printed., and show some output/

I suspect that you are not really talking to all of your devices. You are actually talking to one device 4 times. Your initialization of the devices seems to be over-complicated and obscure to me. Have you actually connected the ADO pin on the modules to high and low voltages as required ?