#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void setup() {
Serial.begin(115200);
Wire.begin(14, 12); // Specify SDA and SCL pins
mpu.initialize();
Serial.println("Testing MPU6050 connections...");
Serial.println(mpu.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
delay(1000);
}
void loop() {
// Read accelerometer and gyroscope values
int16_t ax, ay, az, gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// Print the values
Serial.print("Accel: ");
Serial.print(ax);
Serial.print(", ");
Serial.print(ay);
Serial.print(", ");
Serial.print(az);
Serial.print(" | ");
Serial.print("Gyro: ");
Serial.print(gx);
Serial.print(", ");
Serial.print(gy);
Serial.print(", ");
Serial.println(gz);
delay(1000); // Adjust the delay as needed
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4