MPU 6050 without powerup calibration

Hello,
I need to make a device that measure an angle in one axis. I need an absolute value in deegres like in digital level. That's why I need to skip calibration on powerup. And that's where I have my issue. No matter what library I use, when I decide to skip calibration the result from 6050 is between -30 and 30 degrees. Even If the sensor is upside down.

Here is my code:

#include "Wire.h"
#include <MPU6050_light.h>
#include "Math.h"

MPU6050 mpu(Wire);
unsigned long timer = 0;

void setup() {
Serial.begin(38400);
Wire.begin();

byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while(status!=0){ }

//mpu.calcOffsets(true , true); // calibration line
}
void loop() {
mpu.update();
Serial.println(mpu.getAngleY());
}

If only I uncomment 'calibration line' program is working corectly and results are between -90 and 90.

Can you give me some clue how to fix this issue?

You could use the approach described here, which does not require calibration: How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing-DFRobot

However, the results will be more accurate if you do calibrate the accelerometer, as described in the following link. It needs to be done only once, and the corrections are then incorporated into the program.

Code:

// minimal MPU-6050 tilt and roll (sjr). Works with MPU-9250 too.
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
//
// Tested with 3.3V eBay Pro Mini with no external pullups on I2C bus (worked with internal pullups)
// Add 4.7K pullup resistors to 3.3V if required. A4 = SDA, A5 = SCL

#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;

void setup() {

  Wire.begin();                                      //begin the wire communication
  Wire.beginTransmission(MPU_addr1);                 //begin, send the slave adress (in this case 68)
  Wire.write(0x6B);                                  //make the reset (place a 0 into the 6B register)
  Wire.write(0);
  Wire.endTransmission(true);                        //end the transmission
  Serial.begin(9600);
}

void loop() {

  Wire.beginTransmission(MPU_addr1);
  Wire.write(0x3B);  //send starting register address, accelerometer high byte
  Wire.endTransmission(false); //restart for read
  Wire.requestFrom(MPU_addr1, 6); //get six bytes accelerometer data
  int t = Wire.read();
  xa = (t << 8) | Wire.read();
  t = Wire.read();
  ya = (t << 8) | Wire.read();
  t = Wire.read();
  za = (t << 8) | Wire.read();
// formula from https://wiki.dfrobot.com/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing
  roll = atan2(ya , za) * 180.0 / PI;
  pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied

  Serial.print("roll = ");
  Serial.print(roll,1);
  Serial.print(", pitch = ");
  Serial.println(pitch,1);
  delay(400);
}

Thank you for an answer. I will try it soon.

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