I'm having difficulties configuring my MPU-6500. I'm not sure how to calibrate it to get accurate readings as I am still very new to this. I am using the MPU-6500 with my Arduino Uno. Below is the code that I have written after referencing to sources I could find online and attempted to comment on in an attempt to understand the code. There are many resources available for the MPU-6050 but not so for the MPU-6500.
#include<Wire.h>
const int MPU_addr = 0x68; // I2C address of the MPU-6500
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ; //16-bit integer
void setup() {
Wire.begin(); //join I2C bus
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6500)
Wire.endTransmission(true); //sends a stop message after transmission, releasing I2C bus
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false); //sends a restart message after transmission
Wire.requestFrom(MPU_addr, 14, true);
// master requests a total of 14 registers from slave, true = sends a stop message after the request, releasing I2C bus
AcX = Wire.read() << 8; // 0x3B (ACCEL_XOUT_H) read most significant byte first
AcX = Wire.read(); // 0x3C (ACCEL_XOUT_L) then least significant byte
AcY = Wire.read() << 8; // 0x3D (ACCEL_YOUT_H) read most significant byte first
AcY = Wire.read(); // 0x3E (ACCEL_YOUT_L) then least significant byte
AcZ = Wire.read() << 8; // 0x3F (ACCEL_ZOUT_H)read most significant byte first
AcZ = Wire.read(); // 0x40 (ACCEL_ZOUT_L) then least significant byte
Tmp = Wire.read() << 8; // 0x41 (TEMP_OUT_H) read most significant byte first
Tmp = Wire.read(); // 0x42 (TEMP_OUT_L) then least significant byte
GyX = Wire.read() << 8; // 0x43 (GYRO_XOUT_H) read most significant byte first
GyX = Wire.read(); // 0x44 (GYRO_XOUT_L) then least significant byte
GyY = Wire.read() << 8; // 0x45 (GYRO_YOUT_H) read most significant byte first
GyY = Wire.read(); // 0x46 (GYRO_YOUT_L) then least significant byte
GyZ = Wire.read() << 8; // 0x47 (GYRO_ZOUT_H) read most significant byte first
GyZ = Wire.read(); // 0x48 (GYRO_ZOUT_L) then least significant byte
//results
Serial.print("MPU-6500");
Serial.println();
Serial.print("Accelerometer X, Y, Z = "); //print accelerometer values
Serial.print(AcX);
Serial.print (", ");
Serial.print(AcY);
Serial.print (", ");
Serial.print(AcZ);
Serial.println();
Serial.print("Temperature = "); //print temperature
Serial.print(Tmp / 333.87 + 21); //equation for temperature in degrees C from datasheet
Serial.print("°C");
Serial.println();
Serial.print("Gyroscope X, Y, Z = "); //print gyroscope values
Serial.print(GyX);
Serial.print (", ");
Serial.print(GyY);
Serial.print (", ");
Serial.print(GyZ);
Serial.println();
Serial.print("\n");
delay(2000);
}