我有四个MPU-6050(http://playground.arduino.cc/Main/MPU-6050)IMU通过两个I2C总线连接到我的Arduino Due。
我只想阅读加速度计数据,但我的代码只是简单地读取原始数据似乎没有用。有没有人有什么想法可能是错的?
这是我将四个MPU-6050连接到Arduino的图片:http://i.imgur.com/UaWP2LP.jpg
这是我的代码:
// 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);
}
答案 0 :(得分:0)
这已经很老了,可能已经不再相关了,无论如何,我来到这里寻找其他东西,但只是看着你的代码,我看到你没有告诉 MPU6050 accel_i2c ...他们应该使用i2c总线的对象。如果它实际上支持多个i2c总线,请查找您的库文档。