Hello we're trying to run the code for 5 mpu6050s but there seems to be a problem as the values are random or with offsets.
Attached below is our current code.
I hope you could help us. thank you!
#include "Wire.h"
#include <MPU6050_light.h>
MPU6050 mpuc(Wire);
MPU6050 mpup(Wire);
MPU6050 mput(Wire);
MPU6050 mpui(Wire);
MPU6050 mpum(Wire);
unsigned long timer = 0;
int MPU6050_central = 6; //digital pin 6
int MPU6050_palm = 5; //digital pin 5
int MPU6050_thumb = 2; //digital pin 2
int MPU6050_index = 3; //digital pin 3
int MPU6050_middle = 4; //digital pin 4
float angle1_x, angle1_y, angle1_z;
float angle2_x, angle2_y, angle2_z;
float angle3_x, angle3_y, angle3_z;
float angleC_x, angleC_y, angleC_z;
float angleP_x, angleP_y, angleP_z;
void setup() {
pinMode(MPU6050_central,OUTPUT);
pinMode(MPU6050_palm,OUTPUT);
pinMode(MPU6050_thumb,OUTPUT);
pinMode(MPU6050_index,OUTPUT);
pinMode(MPU6050_middle,OUTPUT);
Serial.begin(9600);
Wire.begin();
mpuc.begin();
mpup.begin();
mput.begin();
mpui.begin();
mpum.begin();
for(int j = 1; j <= 5; j++){
if (j == 1){
digitalWrite(MPU6050_central,HIGH);
digitalWrite(MPU6050_central,LOW);// set MPU6050 central as the device being read
mpuc.setAddress(104);
mpuc.calcOffsets();
for(int j = 1; j <= 1000; j++){
central();
Serial.print("Central: ");
Serial.print(angleC_y);
Serial.print("\t ");
Serial.print(angleC_z);
Serial.print("\t ");
Serial.println(angleC_x);
}
}
if (j == 2){
digitalWrite(MPU6050_palm,HIGH);
digitalWrite(MPU6050_palm,LOW);// set MPU6050 palm as the device being read
mpup.setAddress(104);
mpup.calcOffsets();
for(int j = 1; j <= 1000; j++){
palm();
Serial.print("Palm: \t");
Serial.print(angleP_y);
Serial.print("\t ");
Serial.print(angleP_z);
Serial.print("\t ");
Serial.println(angleP_x);
}
}
if (j == 3){
digitalWrite(MPU6050_thumb,HIGH);
digitalWrite(MPU6050_thumb,LOW);// set MPU6050 thumb as the device being read
mput.setAddress(104);
mput.calcOffsets();
for(int j = 1; j <= 1000; j++){
thumb();
Serial.print("Thumb: \t");
Serial.print(angle1_y);
Serial.print("\t ");
Serial.print(angle1_z);
Serial.print("\t ");
Serial.println(angle1_x);
}
}
if (j == 4){
digitalWrite(MPU6050_index,HIGH);
digitalWrite(MPU6050_index,LOW);// set MPU6050 index as the device being read
mpui.setAddress(104);
mpui.calcOffsets();
for(int j = 1; j <= 1000; j++){
index();
Serial.print("Index: \t");
Serial.print(angle2_y);
Serial.print("\t ");
Serial.print(angle2_z);
Serial.print("\t ");
Serial.println(angle2_x);
}
}
if (j == 5){
digitalWrite(MPU6050_middle,HIGH);
digitalWrite(MPU6050_middle,LOW);// set MPU6050 middle as the device being read
mpum.setAddress(104);
mpum.calcOffsets();
for(int j = 1; j <= 1000; j++){
middle();
Serial.print("Middle: ");
Serial.print(angle3_y);
Serial.print("\t ");
Serial.print(angle3_z);
Serial.print("\t ");
Serial.println(angle3_x);
}
}
}
}
void loop() {
}
void central(){
//Reset the address of all devices
mpuc.update();
angleC_x = mpuc.getAngleX();
angleC_y = mpuc.getAngleY();
angleC_z = mpuc.getAngleZ();
}
void palm(){
mpup.update();
angleP_x = mpup.getAngleX();
angleP_y = mpup.getAngleY();
angleP_z = mpup.getAngleZ();
}
void thumb(){
mput.update();
angle1_x = mput.getAngleX();
angle1_y = mput.getAngleY();
angle1_z = mput.getAngleZ();
}
void index(){
mpui.update();
angle2_x = mpui.getAngleX();
angle2_y = mpui.getAngleY();
angle2_z = mpui.getAngleZ();
}
void middle(){
mpum.update();
angle3_x = mpum.getAngleX();
angle3_y = mpum.getAngleY();
angle3_z = mpum.getAngleZ();
}