MPU6050_light Setup

Hello!

Been trying to setup an MPU6050 gryoscope to read my angle and accelerometer values, the strange thing is however is when I'm using the MPU6050_light library and mpu.getAngleZ(); the value of my angle increases over time. When I tilt it down and up it changes, but slowly over time it increases in value. Not sure why this is, all I really want is to read the current angle and I noticed that some of the libraries read the change in angle. Please help me out!

The gyro is a "rate gyro", which measures the rate of rotation, not an angle.

To obtain orientation angles requires integrating the rotation rates with respect to time, and for that to work, the gyro must be calibrated to remove the zero offsets.

ah alright I'll try the offset function and see if that works

I took a look at the MPU050_light library, and it is not promising.

On the other hand, the MPU6050 was declared obsolete and manufacture was discontinued a number of years ago, so what you have today is some sort of clone or counterfeit. I doubt much is lost using "code lite".

idk man I just need a sensor to measure angles, got any recommendations besides a BMI160 because that seems to overheat for me for some reason?

What do you mean by "measure some angles"?

Here is the minimum code needed to measure two tilt angles with the MPU-6050, but the basic idea works with any accelerometer. No accelerometer library needed.

// 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);
}

would this give the angles or the change in angles?

Hi, @rhythm8503

Can you tell us the application of your project?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

First, you need to explain what you mean by "measure some angles" and what you hope to do with the sensor.

Hello! Tried the offset command and it didn't work so I'll try like you mentioned before and manually write commands through i2C. I just don't understand why it rises/falls in value over time it makes no sense to me? I don't know if it's cause it's integrating or something.

Second this project is a range calculator for a dart blaster, last time I used a BMI160 and it worked but messed with my TFT setup so I swapped over to the MPU6050. Are there any libraries you guys recommend as I really don't like manually writing each command

Based on how the MPU6050 drifts, I might go back to the BMI160 as it kept overheating likely being DOA.

nvm the old library doesn't work but for the MPU6050 I found I can manually set the offset so I'm gonna try that

Now what I don't understand with the library is, when plugged into my laptop MPU.calcOffsets works and the drift is solved, but as soon as I plug it into a direct power supply, the angle begins to drift at a normal rate? For now I have hard set values put in but it still drifts a little, any ideas?

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Please not a Fritzy or a cut and paste Paint picture.

Some images of your project would help, so we can see your component layout.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi!

I would greatly prefer to keep this project as confidential as possible until it's release, there is a larger issue I have found which may lead to the drift which I will be posting significantly more details in.

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