Reputation: 1
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?
Here's a picture of how I connected my four MPU-6050 to the Arduino: https://i.sstatic.net/98JE3.jpg
Here's my code:
// 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);
}
Upvotes: 0
Views: 3933
Reputation: 343
This is pretty old and likely no longer relevant, anyway, I came here looking for something else, but just looking at your code, I see that you are not telling the MPU6050 accel_i2c... objects which i2c bus they should use. Look for your library documentation if it actualy supports multiple i2c busses.
Upvotes: 0