Offset value for calibrate MPU-6050

i already saw other post with same topic: How to implement MPU6050 offsets into code? - Projects / Programming - Arduino Forum

i also looking for tutorial in youtube and some codes in github but my head start to dizzy. i get my offset value for calibrating MPU-6050 using program by Jeff Rowberg

please how to add this value in program? since the example library already display the data in m/s^2 unit, so when I substract it directly it become unvalid value, i also dunno what unit is this offset? and i need to calibrate it because my Z-axis accelero display ~11 m/s^2 which not valid cause it must be aroun 9.8 due to gravity.

i know this website from other post: Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers
it said:
image
since uncalibrated data is (a.acceleration.x), offset is a fixed value, how about the scalling factor should I use?
note: i only need the accelerometer, cause many posts mostly about calibrate the gyro for balance like this ino.file MPU6050_Latest_code.ino (7.4 KB)

here i drop my unvalid data code

#include <Arduino.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

Adafruit_MPU6050 mpu;

float ax_offset = -1686;
float ay_offset = -4053;
float az_offset = 955;
float gx_offset = 49;
float gy_offset = 42;
float gz_offset = -9;

void setup() {
  Serial.begin(115200);
  mpu.begin();
  mpu.setAccelerometerRange(MPU6050_RANGE_2_G);
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
  delay(1000);
}

void loop() {
  /* Get new sensor events with the readings */
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);
    
  // Apply offset correction
  float ax = a.acceleration.x - ax_offset; //scaling factor ??
  float ay = a.acceleration.y - ay_offset;
  float az = a.acceleration.z - az_offset;

  float gx = g.gyro.x - gx_offset;
  float gy = g.gyro.y - gy_offset;
  float gz = g.gyro.z - gz_offset;

  /* Print out the values */
  Serial.print("Acceleration X: "); Serial.print(ax); Serial.print(" m/s², ");
  Serial.print("Y: "); Serial.print(ay); Serial.print(" m/s², ");
  Serial.print("Z: "); Serial.print(az); Serial.println(" m/s²");

  Serial.print("Rotation X: "); Serial.print(gx); Serial.print(" rad/s, ");
  Serial.print("Y: "); Serial.print(gy); Serial.print(" rad/s, ");
  Serial.print("Z: "); Serial.print(gz); Serial.println(" rad/s");

  Serial.println("");
  delay(500);
}

and this the display of serial monitor

Hey @sinus_20 , have you tried using the example code in the library of jeff rowberg, MPU6050 - IMU_Zero.ino,

If you read from line number 44 to 73 in this link you will find what jrowberg mean by offsets and how you should use them, hope this helps. Thank you!

thank u @iamaryang, i read those library example for mpu6050_raw data and imu_zero, so this far i understand that offset is only apply in raw data, right? i try to upload the example mpu6050_raw data with some modification from line 94

// use the code below to change accel/gyro offset values (line 95-115)
    Serial.println("Updating internal sensor offsets...");
    // -1686,  -4053,  955,    49,     42,     -9
    accelgyro.setXAccelOffset(-1686);
    accelgyro.setYAccelOffset(-4053);
    accelgyro.setZAccelOffset(955);
    accelgyro.setXGyroOffset(49);
    accelgyro.setYGyroOffset(42);
    accelgyro.setZGyroOffset(-9);
    Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); 
    Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); 
    Serial.print("\n");

the result is

but i still don't understand the correlation with m/s^2 unit cause in adafruit_mpu6050 there's no such thing as function to get calibrate value.

then i try IMU_zero, but it turns out error in line 255 ('SetAveraging' was not declared in this scope), i thought i should declare it first since I use platform.io instead of arduino.ide, other void function can be executed since all of them are outside the void loop, so i still can't upload it to my esp32 microcontroller, please help me, i really saw many post about this mpu-6050 calibration issue but still can't figure out the solutions.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.