#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
Adafruit_MPU6050 accelgyro;
// Structs for sensor data
sensors_event_t a, g, temp;
void setup() {
Wire.begin();
Serial.begin(115200);
if (!accelgyro.begin()) {
Serial.println("MPU6050 not found!");
while (1);
}
Serial.println("MPU6050 initialized.");
}
void loop() {
accelgyro.getEvent(&a, &g, &temp);
Serial.print("Acc X: "); Serial.print(a.acceleration.x);
Serial.print(", Acc Y: "); Serial.print(a.acceleration.y);
Serial.print(", Acc Z: "); Serial.println(a.acceleration.z);
Serial.print("Gyro X: "); Serial.print(g.gyro.x);
Serial.print(", Gyro Y: "); Serial.print(g.gyro.y);
Serial.print(", Gyro Z: "); Serial.println(g.gyro.z);
delay(100);
}