-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch_2_MPU650s_output_simplified.ino
74 lines (63 loc) · 1.81 KB
/
sketch_2_MPU650s_output_simplified.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#include "Wire.h"
MPU6050 mpu0(0x68);
MPU6050 mpu1(0x69);
bool dmpReady0 = false;
bool dmpReady1 = false;
uint8_t devStatus0;
uint8_t devStatus1;
uint8_t fifoBuffer0[64];
uint8_t fifoBuffer1[64];
Quaternion q;
VectorFloat gravity;
float ypr[3];
void setupMPU(MPU6050 &mpu, bool &dmpReady, uint8_t address) {
Serial.println(F("Initializing I2C devices..."));
mpu.initialize();
Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
Serial.println(F("Initializing DMP..."));
devStatus0 = mpu.dmpInitialize();
mpu.setDMPEnabled(true);
if (devStatus0 == 0) {
mpu.CalibrateAccel(6);
mpu.CalibrateGyro(6);
mpu.PrintActiveOffsets();
Serial.println(F("DMP ready! Waiting for first interrupt..."));
dmpReady = true;
} else {
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus0);
Serial.println(F(")"));
}
}
void setup() {
Serial.begin(9600);
Wire.begin();
Wire.setClock(400000);
while (!Serial);
setupMPU(mpu0, dmpReady0, 0x68);
setupMPU(mpu1, dmpReady1, 0x69);
}
void loop() {
if (!dmpReady0 || !dmpReady1) return;
Serial.print("Device1: ");
readMpuData(mpu0, fifoBuffer0);
Serial.print("\t");
Serial.print("Device2: ");
readMpuData(mpu1, fifoBuffer1);
Serial.println();
}
void readMpuData(MPU6050 &mpu, uint8_t *fifoBuffer) {
if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) {
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
Serial.print(ypr[0]);
Serial.print("\t");
Serial.print(ypr[1]);
Serial.print("\t");
Serial.print(ypr[2]);
Serial.print("\t");
}
}