Arduino MPU 6050 calibration and sensitivity understanding please help

Hi,

I'm currently working on a project to measure arm movements. I'm using an Arduino UNI with a MPU 6050 GY521. I have a working code that measures its raw values and I understand that I need to count in the sensitivity range 2g, 4g etc to get actual workable values.

I'm using GitHub - jrowberg/i2cdevlib: I2C device library collection for AVR/Arduino or other C++-based MCUs to find my acceleration offsets to calibrate the device but I don't know how to incorporate this into my code. I aso dont understand where i can add it the sensitivity range to get actual measurements.

Help will be much appreciated!
I'm new to the arduino world and am struggling to find anything useful as it seems this is basic knowledge to most people.

Thank you for your time. the following is the code I also got online to get the raw values:
//Arduino Project Hub

#include<Wire.h>

const int buttonPin = A5;

const int button = A4;

const int MPU=0x68; // I2C address of the MPU-6050
int16_t X, Y, Z;

void setup(){
pinMode(buttonPin, INPUT);
pinMode(button, INPUT);
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,6,true); // request a total of 14 registers
X=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
Y=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
Z=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Serial.print(""); Serial.print(X);
Serial.print(" "); Serial.print(Y);
Serial.print(" "); Serial.print(Z);
Serial.println();

// delay(100); //100ms
}

Hi, I would like an update on this situation. as I am currently finding the same problem, that everyone just refers to the jeff rowberg library! which i tried using but I'm new to arduino and so find it hard to simple change the .cpp files.

So how were you able to change the sensitivity?

Thank you

This module requires you a fairly deep understanding of how it works.

I'm currently trying to study the theoretical background of these sensors they are interesting.

There are other factors that may affect the device functionality.

Check this site:

Thank you very much I'll have a look!

do you happen to have a code to find the range of sensitivity its in or to calibrate it by any chance?

Hi, I'm new to the coding world and for a project im using an Arduino uno with an MPU 6050, GY 521 to gather some measurements of hand movements

But so far I only have a code to get raw data. I've done as much research as I can and have gathered up different codes from git hub but I cant seem to use them on my 1 task.

Does anyone have any code on the calibration for the MPU or a code to find and change its sensitivity?

Thank you for your time and help!

Hi, I am working on a similar project to that one you described. I was wondering if you would be able to share the script you used for the collection of acceleration as I am really struggling to understand the conversion from raw to in relation to G and cant seem to incorporate it into my script.

Thank you, I would be so grateful!

do you happen to have a code to find the range of sensitivity its in or to calibrate it by any chance?

That would be whatever is the default in the library you are using.

If you aren't using a library, then the default sensitivity is automatically set on power up, as described in the device data sheet.

Accelerometers usually don't need calibration, but if you want to do it, follow this tutorial: Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers

Don't forget that you have a handy standard: the Earth's gravity is 9.8 m/s/s, which is reported by the accelerometer when it is held still.

Please do not double post.

@JPEG_uno, stop cross-posting.

@JPEG_uno, stop hijacking.

@Coding Badly Jeez sorry, I didnt know I did that and I'm new, cut some slack please

In this situation what exactly would "cut some slack" entail?

I'd rename X, Y, Z to Xraw, Yraw, Zraw. the raw values are not very useful as an end product.

I'd suggest you get the MPU60X0 register map, https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf. From the register map you can get the mpu6050's scale factors that you have set, based on accelerometer sensitivity, as per page 46 of the MPU60X0 register data sheet. Also, you will need to two's complement the accel_raw before applying the scale factors. For the accelrometers, apply the calibration elements during scale factor conversion, always keep the accel_raw data between reads, you'll need it for other functions. You will, also, want to look up the functions to convert scaled accelerometer data into angular data to get accelerometer tilt angle values. At this point you will find accelerometer tilt angle values to be quite erratic and, perhaps, may want a way to calm that data down a bit, smooth it out. That's where your rate gyro data comes in.

After rate gyro data, is obtained from the mpu, apply scale factors / two complement but do not apply calibration data to the gyro, at this time.

Looking around on the internet you can find the formula for the complementary filter, the filter will demonstrate how to apply scale factored accelerometer data to obtain angular data and scaled factored gyro data to obtain angular rate data. Once the angular rate data for the gyros has been obtained apply the calibration data to the gyro data.

With calibrated gyro and accelerometer data send the information through the complemntary filter to get something useful for your project.

You will need to determine the full scale settings of the rate gyros and accelerometers to match your project requirements. You may want to lock the free running mpu clock to one of the gyro's PLL's for greater stability, as explained in the register data sheet. You will, also, need to know the sampling time, as per the data sheet for the complementary filter.

On another note, if you are going to use servos in your project, and have those servos torque based up mpu angular readings, use torque by micros and use metal geared servos. A plastic geared servo will last less then 2 weeks under continous mpu torque control; my expereince.

When you calibrate the rate gyros and accelerometers, place the mpu unit flat on a piece of foam and do not play boom boom music or slam doors or have large trucks drive by during the calibration procedure. You may find that the full scale range of +-2 degrees to be a bit too sensitive, which means a change of scale factor.

Good luck.