#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu; // Crear objeto del sensor
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("Inicializando MPU6050...");
mpu.initialize();
// Verificar conexión
if (mpu.testConnection()) {
Serial.println("MPU6050 conectado correctamente.\n");
} else {
Serial.println("Error: No se detecta el MPU6050.");
while (1); // Detiene ejecución
}
// Encabezado de columnas
Serial.println("AcX\tAcY\tAcZ\tTemp\tGyX\tGyY\tGyZ");
}
void loop() {
int16_t ax, ay, az; // Acelerómetro
int16_t gx, gy, gz; // Giroscopio
int16_t tempRaw; // Temperatura cruda
// Leer datos del sensor
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// Leer temperatura
tempRaw = mpu.getTemperature();
float tempC = (tempRaw / 340.0) + 36.53;
// Mostrar los datos en el orden de la planilla
Serial.print(ax / 16384.0, 3); Serial.print("\t");
Serial.print(ay / 16384.0, 3); Serial.print("\t");
Serial.print(az / 16384.0, 3); Serial.print("\t");
Serial.print(tempC, 2); Serial.print("\t");
Serial.print(gx / 131.0, 2); Serial.print("\t");
Serial.print(gy / 131.0, 2); Serial.print("\t");
Serial.println(gz / 131.0, 2);
delay(500); // Esperar med
}