SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By mrlooneytoon
#166670
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. 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: Image
Code: Select all
// 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);
}
By mrlooneytoon
#166681
Oh and 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.