#include <Wire.h>
#include <MPU6050.h>
#include <LiquidCrystal_I2C.h> // Include the LCD library
MPU6050 mpu1(0x68); // Replace 0x68 with the actual address of MPU6050-1
MPU6050 mpu2(0x69); // Replace 0x69 with the actual address of MPU6050-2
LiquidCrystal_I2C lcd(0x27, 16, 2); // Replace 0x27 with the address of your LCD (use LCD I2C scanner to find the address)
void setup() {
Serial.begin(9600);
Wire.begin();
// Initialize the LCD
lcd.init();
lcd.backlight();
// Initialize the first MPU6050
mpu1.initialize();
if (mpu1.testConnection()) {
Serial.println("MPU6050-1 connection successful");
lcd.setCursor(0, 0);
lcd.print("MPU6050-1 OK");
} else {
Serial.println("MPU6050-1 connection failed");
lcd.setCursor(0, 0);
lcd.print("MPU6050-1 Error");
while (1);
}
// Initialize the second MPU6050
mpu2.initialize();
if (mpu2.testConnection()) {
Serial.println("MPU6050-2 connection successful");
lcd.setCursor(0, 1);
lcd.print("MPU6050-2 OK");
} else {
Serial.println("MPU6050-2 connection failed");
lcd.setCursor(0, 1);
lcd.print("MPU6050-2 Error");
while (1);
}
}
void loop() {
int16_t ax1, ay1, az1, gx1, gy1, gz1;
mpu1.getMotion6(&ax1, &ay1, &az1, &gx1, &gy1, &gz1);
int16_t ax2, ay2, az2, gx2, gy2, gz2;
mpu2.getMotion6(&ax2, &ay2, &az2, &gx2, &gy2, &gz2);
Serial.print("MPU6050-1 - Gyro: ");
Serial.print(gx1);
Serial.print(", ");
Serial.print(gy1);
Serial.print(", ");
Serial.println(gz1);
Serial.print("MPU6050-2 - Gyro: ");
Serial.print(gx2);
Serial.print(", ");
Serial.print(gy2);
Serial.print(", ");
Serial.println(gz2);
// Display gyroscope data on the LCD
lcd.setCursor(0, 0);
lcd.print("G1: ");
lcd.print(gx1);
lcd.print(", ");
lcd.print(gy1);
lcd.print(", ");
lcd.print(gz1);
lcd.setCursor(0, 1);
lcd.print("G2: ");
lcd.print(gx2);
lcd.print(", ");
lcd.print(gy2);
lcd.print(", ");
lcd.print(gz2);
delay(500); // You can adjust the delay according to your requirements
}