Hello everybody!
I have a question for you. I just started using the MPU6050 gyroscope and accelerometer and I'm having some trouble. I read a little bit the documentation and watched a lot of videos and tutorial, but I'm having an issue.
Here's my code :
#include "Arduino.h"
#include "Wire.h"
const int MPU_ADDR = 0x68;
int16_t gyro[] = {0, 0, 0};
void setup_mpu() {
Wire.begin();
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x6B);
Wire.write(0x00);
Wire.endTransmission();
}
void print_gyro() {
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x43);
Wire.endTransmission();
Wire.requestFrom(MPU_ADDR, 6);
for(int i = 0 ; i < 3 ; ++i) {
gyro[i] = Wire.read() << 8 | Wire.read();
Serial.print(i);
Serial.print(" = ");
Serial.print(gyro[i]);
}
Serial.println("");
}
As you can see, in the function print_gyro(), i'm reading starting at the register 0x43. It's supposed to be the first register for the gyroscope x axis. But i'm getting the accelerometer data (the value update only when I move the MPU6050).
Then, I tried read from the register 0x3b (where it's supposed to be the accelerometer data) and now im getting values updating from the angle of the MPU6050.
Can someone tell me why ? Am I doing something wrong ? Does my MPU6050 registers crazy ? Am I crazy ??
Thanks for your help !