Yesterday I have tried to use a MPU6050 with ESP32 in arduino IDE.
I've tried several ways to get the acceleration data from the sensor.
At first I used the Adafruit MPU library. The sensor laid flat on a surface but X showed me -3m/s², Y something around 1m/s² and Z ~0m/s². I Expected X:0, Y:0, Z:9,81.
// Arduino Guide: https://RandomNerdTutorials.com/arduino-mpu-6050-accelerometer-gyroscope/
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void setup(void) {
Serial.begin(115200);
while (!Serial) {
delay(10); // will pause Zero, Leonardo, etc until serial console opens
}
// Try to initialize!
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
mpu.setAccelerometerRange(MPU6050_RANGE_16_G);
mpu.setGyroRange(MPU6050_RANGE_250_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.println("");
delay(100);
}
void loop() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
/* Print out the values */
Serial.print(a.acceleration.x);
Serial.print(",");
Serial.print(a.acceleration.y);
Serial.print(",");
Serial.print(a.acceleration.z);
Serial.print(", ");
Serial.print(g.gyro.x);
Serial.print(",");
Serial.print(g.gyro.y);
Serial.print(",");
Serial.print(g.gyro.z);
Serial.println("");
delay(10);
}
Next, I used another example-code to get the raw sensor data. The results were nearly the same, like X: -5000, Y: 1500 and Z: 300. I don't know the exact values but they were in this magnitude.
So I installed a calibration library and have done the calibration. After this, X and Y were ~0 and Z ~16,000. (I think this should be the real values).
After turning the sensor 90°, Y was 16,000, X ~0 but Z keeps at 16,000.
It seems like the sensor is always returning values near 0 for Z and the calibration-offset adds 16k to Z, so Z is always 16k.
Is this sensor broken?
Thank you!