Giter Site home page Giter Site logo

mpu6050_light's Introduction

MPU6050_light bdg bdg bdg

Lightweight, fast and simple library to communicate with the MPU6050

⬇️ The source code is available at https://github.com/rfetick/MPU6050_light

🔄 Your feedback is important. Any issue or suggestion can be reported to the Github Issues section

Description

The library is made to retrieve accelerometer and gyroscope measurements from the MPU6050. This data is processed using a complementary filter to provide and estimation of tilt angles on X and Y with respect to the horizontal frame. The hypothesis for the validity of these angles are:

  • small linear accelerations (the gravity is the dominant one)
  • small loop delay between two calls to update() so the approximation angle[t]=angle[t-1]+gyro*dt is valid
  • heading (angle Z) is valid for small X and Y angles

Documentation

A documentation PDF is provided within the library folder, otherwise get it online at https://github.com/rfetick/MPU6050_light. It includes definitions of the functions and gives a minimal example of usage of the code. More examples can be found in the dedicated examples/ subfolder of the library.

License

See the LICENSE file

Authors

rfetick : modifications for better memory management, speed and efficiency.

tockn : initial author of the library (v1.5.2)

The library has also been improved thanks to the comments of edgar-bonet and augustosc

mpu6050_light's People

Contributors

rfetick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpu6050_light's Issues

Trouble using 2 mpu

I struggle to make the library working with 2 modules.
At the startup of my application, sometime it's working, sometime not, or it's simply hanging.

Then i realized it seems that in the begin() function, the first time we call the update() function, preInterval = 0, and it's compared to millis() to calculate the value of dt.
Depending on the order of the things you initialize in your application setup() function, the first time the millis() function will be called might give you a pretty big number, which will then enter loops in the wrap() function.
The second module will be even greater, since it waits for the first ont to complete.

I noticed you initialize that variable after the update(), which is kinda weird since it's already set in the update() method itself.

  this->update();
  angleX = this->getAccAngleX();
  angleY = this->getAccAngleY();
  preInterval = millis(); // may cause lack of angular accuracy if begin() is much before the first update()
  return status;

Would it be okay to initialize the variable before update() instead of after?
I'm not quite sure what it is for, but i know it's what slows me down.

Angle Z gyro drifting

I made the MPU6050 calibration several times and tried to change some values from the <MPU6050_light.h> library, but I cannot figure out to get the angle Z gyroscope not to drift away. Sometimes it drifts up sometimes down. I read that Earth moves 15 degree per hour so that's why it's drifts like this. What should I do to counter this?

trying to use a MPU6050 and a Sabertooth2x12 on a single arduino

so im using the sabertooth speed controller to control the two motors on my lawn mower and im trying to use the MPU6050 to keep the lawn mower straight. The problem im facing is that im trying to use the sabertooth and the MPU6050 on a single Arduino . I want to receive the data from the MPU6050 and based of that make a program to move the motor so that the mower will go in a straight line. I tested it on my computer first so I made a boundary of how much the lawnmower can deviate from the center and if it passes the boundary then I made one of the motor speed up respectively. It all worked when I ran it on my computer, however when I hooked up the sabertooth It made it didn't work, I moved the lawnmower to the left and the right motor did not speed up . when I started the program both of the motors were going ham. I don't think the arduino was getting the data from the MPU6050 or I think there were some noise interfering with the arduino. Can anyone please help me with this issue.

Library support for MPU9250?

Hello,

I am curious if this code could be modified to fit the MPU9250 sensor for use with the magnetometer (heading axis) sensor?
I am using a cookie cutter Arduino library for the MPU9250 but the fastest I can sample the data, using an ESP32, is around 1000Hz.

Thank you for your help!

M5Stack Core Esp32

Great work !!!

I would like to use this library with the M5Stack Core Esp32. It is possible ? Can you give any guidance or script?
Thank you.
Regards.

Accelerometer Z Axis offset calibration

Hi,

I have three MPU-6050 boards and they all have a different offset on the Z-Axis. like 0.3 Gs, one is 0.1 Gs and the third is 0.4Gs off which is bit annoying xD Subsequently all the values like ACC Angle and Angle are wrong.
I have worked around this by passing a float to the update function to compensate for that, but I think that it would be kind of cool to be able to just calibrate the Z-Axis offset during initialization?
Is that possible on the MPU-6050?

How to switch the readable register?

Hello, how would I change whether this library is reading from register 0x68 to 0x69. If this is able to be done it could allow multiple sensors to be attached to the same program.

Absolute orientation

I am getting zero angles at startup. So, regardless of the initial orientation of the MPU6050, the angles are zero. Moving it updates the angles, but they are relative to the initial orientation. How can I change it to show the absolute angles with respect to gravity?

Thanks

Zeroing sensor values

Hello!

First I would like to thank you for your great contribution and your effort in simplyfing the whole process of sensor's data retrieval. I was wondering if there is a way to safely zero the values of angleX, angleY, angleZ after MPU6050 has already been calibrated in setup()? Can we just add setter methods to class MPU6050 ?

Best regards,
Ivan

mpu6050 status

I changed the value of the following line in MPU6050_light.h
#define MPU6050_ADDR 0x68
from:
0x68 to 0x69.
the example sketch shows me on the serial monitor the writing:
MPU6050 status: 4
what is it due to?
the code i am using with cpu stm32 (mini maple) in the arduino ide.

Sensor in vertical position: would like to start the angle reading (0,0,0)

Hello,

If I keep my sensor in the vertical position (the x-axis is facing upward) and run your example code GetAllData, will mpu.calcOffsets(true,true) function makes the reading starts from zero? What change do I need to make in the source code to start the angle reading from 0 in this vertical position?

Unexpected X, Y value range when run upside down

Hi,

I have an MPU6050 breakout board mounted on a Teensy 3.2.
The GetAngle example program runs fine, but when starting the program with the MPU6050 upside down the X and Y values only have a range of -25 to 25 (when rotated by 90° in either direction). Z values are unaffected.

Is there a calculation I should apply to get expected value ranges, or would this be a library specific issue?

Pronblem with initial angular tilt.

Hi,

Here's my issue, no matter at what direction I position the gyro to, I have always the initial position as a reference (0,0,0). This is not a problem on the Z axis but on the X and Y axis, it is important to know the tilt of the gyro (I'm trying to build a self balancing robot). So I don't really know if I'm missing something or what, and therefore I'm looking for you help.

PS : awesome library, very helpfull.

thank you.

support of 2 sensors

Dear Romain,
I really like the work you have done on the library MPU6050_light. Would you consider to add support of 2 MPU sensors. Basically calling all the functions you have currently implemented with "mpu0x68.xxx" and "mpu0x69.xxx".
Many thanks in advance for thinking about it!
Best regards,
76nic

Example plotting

The GetAngle example could be improved by removing the spaces so the angles can be plotted with the serial plotter:
Serial.print("X:");
Serial.print(mpu.getAngleX());
Serial.print("\tY:");
Serial.print(mpu.getAngleY());
Serial.print("\tZ:");
Serial.println(mpu.getAngleZ());

Two MPUs

Hi there!

This isn't really an issue. I was wondering how I could make the code work for two MPU sensors connected to the same Arduino. I haven't found a way to set an address for each of them. At this moment, the code compiles and uploads, but my 2 MPUs are displaying very close (if not the same) values. Any help would be appreciated!! Thanks.

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

MPU6050 mpu6050(Wire);
MPU6050 mpu6050B(Wire);

unsigned long timer = 0;

void setup() {
  
  Serial.begin(9600);
  
  Wire.begin()      ;
  mpu6050.begin()   ;
  mpu6050.calcOffsets();

  Wire.begin()      ;
  mpu6050B.begin() ;
  mpu6050B.calcOffsets();
}


void loop() {
 
 mpu6050.update();
 mpu6050B.update();
 
 if((millis()-timer)>2000){ // print values every 2s
  
  Serial.print("Accelerometer 1 ");
  Serial.print("X : ");
  Serial.print(mpu6050.getAngleX());
  Serial.print("\tY : ");
  Serial.print(mpu6050.getAngleY());
  Serial.print("\tZ : ");
  Serial.print(mpu6050.getAngleZ());
  
  Serial.print("\tAccelerometer 2 ");
  Serial.print("X : ");
  Serial.print(mpu6050B.getAngleX());
  Serial.print("\tY : ");
  Serial.print(mpu6050B.getAngleY());
  Serial.print("\tZ : ");
  Serial.println(mpu6050B.getAngleZ());
  
  //digitalWrite(LEDfun, HIGH);
  timer = millis();
 }
  
}

5 MPU6050s

Hello we're trying to run the code for 5 mpu6050s but there seems to be a problem as the values are random or with offsets.

Attached below is our current code.

I hope you could help us. thank you!

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

MPU6050 mpuc(Wire);
MPU6050 mpup(Wire);
MPU6050 mput(Wire);
MPU6050 mpui(Wire);
MPU6050 mpum(Wire);

unsigned long timer = 0;
int MPU6050_central = 6;  //digital pin 6
int MPU6050_palm = 5; //digital pin 5
int MPU6050_thumb = 2; //digital pin 2
int MPU6050_index = 3; //digital pin 3
int MPU6050_middle = 4; //digital pin 4
float angle1_x, angle1_y, angle1_z; 
float angle2_x, angle2_y, angle2_z;
float angle3_x, angle3_y, angle3_z;
float angleC_x, angleC_y, angleC_z;
float angleP_x, angleP_y, angleP_z;


 
void setup() {
  pinMode(MPU6050_central,OUTPUT);
  pinMode(MPU6050_palm,OUTPUT);
  pinMode(MPU6050_thumb,OUTPUT);
  pinMode(MPU6050_index,OUTPUT);
  pinMode(MPU6050_middle,OUTPUT);


   Serial.begin(9600);
   Wire.begin();
   
   mpuc.begin();
   mpup.begin();
   mput.begin();
   mpui.begin();
   mpum.begin();
   for(int j = 1; j <= 5; j++){
    if (j == 1){
     digitalWrite(MPU6050_central,HIGH);
     digitalWrite(MPU6050_central,LOW);// set MPU6050 central as the device being read
     mpuc.setAddress(104);
     mpuc.calcOffsets();
     
  
    for(int j = 1; j <= 1000; j++){
    central();
    Serial.print("Central: ");
    Serial.print(angleC_y);
    Serial.print("\t ");
    Serial.print(angleC_z);
    Serial.print("\t ");
    Serial.println(angleC_x);
   }
    }
    
    if (j == 2){
    digitalWrite(MPU6050_palm,HIGH);
    digitalWrite(MPU6050_palm,LOW);// set MPU6050 palm as the device being read
    mpup.setAddress(104);
    mpup.calcOffsets();
    
   for(int j = 1; j <= 1000; j++){
    palm();
    Serial.print("Palm: \t");
    Serial.print(angleP_y);
    Serial.print("\t ");
    Serial.print(angleP_z);
    Serial.print("\t ");
    Serial.println(angleP_x);
   }
   }

   if (j == 3){
     digitalWrite(MPU6050_thumb,HIGH);
     digitalWrite(MPU6050_thumb,LOW);// set MPU6050 thumb as the device being read
     mput.setAddress(104);
     mput.calcOffsets();
     
   for(int j = 1; j <= 1000; j++){
    thumb();
    Serial.print("Thumb: \t");
     Serial.print(angle1_y);
     Serial.print("\t ");
     Serial.print(angle1_z);
     Serial.print("\t ");
     Serial.println(angle1_x);
   }
   }
   
   if (j == 4){
   digitalWrite(MPU6050_index,HIGH);
     digitalWrite(MPU6050_index,LOW);// set MPU6050 index as the device being read
     mpui.setAddress(104);
     mpui.calcOffsets();
     
   for(int j = 1; j <= 1000; j++){
    index();
    Serial.print("Index: \t");
     Serial.print(angle2_y);
     Serial.print("\t ");
     Serial.print(angle2_z);
     Serial.print("\t ");
     Serial.println(angle2_x);
   }
   }

   if (j == 5){
     digitalWrite(MPU6050_middle,HIGH);
     digitalWrite(MPU6050_middle,LOW);// set MPU6050 middle as the device being read
     mpum.setAddress(104);
     mpum.calcOffsets();
     
    for(int j = 1; j <= 1000; j++){
     middle();
     Serial.print("Middle: ");
     Serial.print(angle3_y);
     Serial.print("\t ");
     Serial.print(angle3_z);
     Serial.print("\t ");
     Serial.println(angle3_x);

     
   }
   }
   
 }

} 
 
 void loop() {
   
 }

  void central(){
      //Reset the address of all devices
     mpuc.update();
     angleC_x = mpuc.getAngleX();
     angleC_y = mpuc.getAngleY();
     angleC_z = mpuc.getAngleZ();

  }
  
  void palm(){
     mpup.update();
     angleP_x = mpup.getAngleX();
     angleP_y = mpup.getAngleY();
     angleP_z = mpup.getAngleZ();

    }
    
  void thumb(){
     mput.update();
     angle1_x = mput.getAngleX();
     angle1_y = mput.getAngleY();
     angle1_z = mput.getAngleZ();
    }
    
  void index(){
     mpui.update();
     angle2_x = mpui.getAngleX();
     angle2_y = mpui.getAngleY();
     angle2_z = mpui.getAngleZ();

    }

  void middle(){
     mpum.update();
     angle3_x = mpum.getAngleX();
     angle3_y = mpum.getAngleY();
     angle3_z = mpum.getAngleZ();
    } 
    

how to reset all for a status = writeData(MPU6050_PWR_MGMT_1_REGISTER, 0x01) = 0 again

Hi, I use your library and I wanted to add the INT function.

This works:

#define MPU6050_ADDRESS   0x68 // Device address when ADO = 0
#define SIGNAL_PATH_RESET 0x68
#define ACCEL_CONFIG      0x1C
#define MOT_THR           0x1F  // Motion detection threshold bits [7:0]
#define MOT_DUR           0x20  // Duration counter threshold for motion interrupt generation, 1 kHz rate, LSB = 1 ms
#define MOT_DETECT_CTRL   0x69
#define WHO_AM_I_MPU6050  0x75  // Should return 0x68
#define INT_PIN_CFG       0x37
#define INT_ENABLE        0x38
#define INT_STATUS        0x3A

  writeByte(MPU6050_ADDRESS, 0x6B, 0x00);
  writeByte(MPU6050_ADDRESS, SIGNAL_PATH_RESET, 0x07); //Reset all internal signal paths in the MPU-6050 by writing 0x07 to register 0x68;
  writeByte(MPU6050_ADDRESS, ACCEL_CONFIG, 0x01); //Write register 28 (==0x1C) to set the Digital High Pass Filter, bits 3:0. For example set it to 0x01 for 5Hz. (These 3 bits are grey in the data sheet, but they are used! Leaving them 0 means the filter always outputs 0.)
  writeByte(MPU6050_ADDRESS, MOT_THR, 10); //Write the desired Motion threshold to register 0x1F (For example, write decimal 20).  
  writeByte(MPU6050_ADDRESS, MOT_DUR, 40); //Set motion detect duration to 1  ms; LSB is 1 ms @ 1 kHz rate  
  writeByte(MPU6050_ADDRESS, MOT_DETECT_CTRL, 0x15); //to register 0x69, write the motion detection decrement and a few other settings (for example write 0x15 to set both free-fall and motion decrements to 1 and accelerometer start-up delay to 5ms total by adding 1ms. )   
  writeByte(MPU6050_ADDRESS, INT_ENABLE, 0x40); //write register 0x38, bit 6 (0x40), to enable motion detection interrupt.     
  writeByte(MPU6050_ADDRESS, INT_PIN_CFG, 0x10); 

however, and I spent hours and hours to try to understand.... and tried all possible manipulations but not the right one....

Once I code the MPU with the above code, I cannot execute anymore the example GetAngle.ino, status returns error 2.

Have you got a suggestion to reset the MPU that still works on interruptions but cannot load another code to measure angles for instance

GetAngle works fine alone but "hangs" up when embedded in other sketch

Using the GetAngle code I have no problems but when the same code is embedded in a much larger sketch which calls mpu.update about every 12 ms the program freezes after a minute +-. Does mpu.update need to be called more frequently? Can you suggest anything else which might be happening?

Using 2 MPU6050

Hey, Im trying to use the setAddress() Method but im still only having the data from the 0x68 device. Can somebody help me?

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

float currentAngleX_A, currentAngleY_A, currentAngleZ_A;
float currentAngleX_B, currentAngleY_B, currentAngleZ_B;

MPU6050 mpuA(Wire);
MPU6050 mpuB(Wire);

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

    mpuA.setAddress(0x68);
    mpuA.begin();
    Serial.println(F("Calculating gyro offset, do not move MPU6050"));
    delay(1000);
    mpuA.calcGyroOffsets();
    Serial.println("Done.");
    
    mpuB.setAddress(0x69);
    mpuB.begin();
    Serial.println(F("Calculating gyro offset, do not move MPU6050"));
    delay(1000);
    mpuB.calcGyroOffsets();
    Serial.println("Done.");
}
void loop()
{
    mpuA.update();
    currentAngleX_A = mpuA.getAngleX();
    currentAngleY_A = mpuA.getAngleY();
    currentAngleZ_A = mpuA.getAngleZ();

    mpuB.update();
    currentAngleX_B = mpuB.getAngleX();
    currentAngleY_B = mpuB.getAngleY();
    currentAngleZ_B = mpuB.getAngleZ();

    Serial.print(currentAngleX_A);
    Serial.print(" , ");
    Serial.print(currentAngleY_A);
    Serial.print(" , ");
    Serial.print(currentAngleZ_A);
    Serial.print(" , ");
    Serial.print(currentAngleX_B);
    Serial.print(" , ");
    Serial.print(currentAngleY_B);
    Serial.print(" , ");
    Serial.print(currentAngleZ_B);
    Serial.println(" ");
}

Yaw angles are constantly drifting or increasing/decreasing rapidly

Hello, I am using your library and sending IMU data over ROSSerial to my ground station.

Everything is going ok but yaw angle are constantly increasing/decreasing their values. Sometimes there is a drift. For e.g., if I just put the IMU at some horizontal surface, yaw angle try to increase/decrease.

  • Tell me one thing, for euler angles, we can use getAngle() right?
  • Is function getAngleAcc gives the euler angle rates?

B) Do you have some calibration offsets function in your library so I will add the value of offset for my MPU6050? As I have already calculated the offsets.

physical position x, y and z axes

I state that the mpu6050 module is combined with a qmc5883l module and I would like to use them for pitch, roll and compass on my off-road vehicle.
the physical position of the modules is rotated 90 degrees with respect to the horizontal plane on which the axes are drawn.
I have seen that with your library the mpu6050 module resets itself in any position, and from what I understand, the physical position of the module is indifferent, is it true ?.
with the sketch of the example alldata I get this:
11: 03: 59.601 -> TEMPERATURE: 23.85
11: 03: 59.634 -> ACCELERATE X: 0.00 Y: -0.00 Z: 0.99
11: 03: 59.667 -> GYRO X: -0.01 Y: -0.34 Z: -0.08
11: 03: 59.700 -> ACC ANGLE X: -0.08 Y: -0.26
11: 03: 59.733 -> ANGLE X: -0.03 Y: -0.70 Z: -0.17
after 10 minutes, without touching the module, I get:
11: 13: 10.313 -> TEMPERATURE: 23.85
11: 13: 10.313 -> ACCELERATE X: -0.01 Y: 0.03 Z: 0.99
11: 13: 10.379 -> GYRO X: 0.05 Y: 0.09 Z: -0.10
11: 13: 10.412 -> ACC ANGLE X: 1.85 Y: 0.50
11: 13: 10.445 -> ANGLE X: 1.59 Y: 0.71 Z: 7.62

are the values ​​correct, especially for the Z angle?
Also I would use it with the QMC5883L to compensate for the compass's x and y or z axes. can I use the filtered data or should I use the raw data?
sorry for the long email.
Greetings

Glitch on X angle value when flipping from 180 to -180

Hello, I have an issue when the MPU6050 is upside down and the angle passes from 180 to -180 and vice versa. I get some "parasite values" (see code) that I'd like to remove, does anyone know how to do that?
Cheers and merry Christmas!

X : 174.68	Y : 0.70	Z : -13.56
X : 174.85	Y : 0.68	Z : -13.56
X : 175.05	Y : 0.69	Z : -13.56
X : 175.24	Y : 0.69	Z : -13.56
X : 175.38	Y : 0.67	Z : -13.56
X : 175.46	Y : 0.68	Z : -13.56
X : 175.62	Y : 0.68	Z : -13.56
X : 175.81	Y : 0.68	Z : -13.56
X : 175.91	Y : 0.68	Z : -13.56
X : 175.99	Y : 0.70	Z : -13.55
X : 176.12	Y : 0.70	Z : -13.54
X : 176.31	Y : 0.69	Z : -13.54
X : 176.55	Y : 0.69	Z : -13.53
X : 176.75	Y : 0.70	Z : -13.53
X : 176.92	Y : 0.68	Z : -13.52
X : 177.09	Y : 0.69	Z : -13.52
X : 177.12	Y : 0.70	Z : -13.52
X : 177.13	Y : 0.69	Z : -13.53
X : 177.17	Y : 0.70	Z : -13.53
X : 177.26	Y : 0.69	Z : -13.53
X : 177.35	Y : 0.68	Z : -13.53
X : 177.43	Y : 0.67	Z : -13.53
X : 177.54	Y : 0.66	Z : -13.53
X : 177.69	Y : 0.66	Z : -13.53
X : 177.85	Y : 0.67	Z : -13.53
X : 178.03	Y : 0.67	Z : -13.54
X : 178.26	Y : 0.67	Z : -13.54
X : 178.58	Y : 0.63	Z : -13.55
X : 171.81	Y : 0.61	Z : -13.57
X : 126.24	Y : 0.59	Z : -13.59        // parasite X angle from here, should go straight to approx. -180
X : 92.74	Y : 0.41	Z : -13.59
X : 57.65	Y : 0.58	Z : -13.61
X : 26.60	Y : 0.71	Z : -13.63
X : 20.41	Y : 0.75	Z : -13.63
X : 1.22	Y : 0.76	Z : -13.63
X : -22.61	Y : 0.78	Z : -13.63
X : -43.28	Y : 0.75	Z : -13.63
X : -61.26	Y : 0.74	Z : -13.63
X : -76.89	Y : 0.74	Z : -13.63
X : -90.43	Y : 0.75	Z : -13.63
X : -100.61	Y : 0.74	Z : -13.63
X : -104.25	Y : 0.73	Z : -13.63
X : -114.19	Y : 0.74	Z : -13.63
X : -122.81	Y : 0.75	Z : -13.63
X : -130.30	Y : 0.74	Z : -13.63
X : -136.77	Y : 0.72	Z : -13.63
X : -142.41	Y : 0.74	Z : -13.63
X : -147.29	Y : 0.74	Z : -13.63
X : -151.54	Y : 0.74	Z : -13.63
X : -155.25	Y : 0.74	Z : -13.63
X : -158.04	Y : 0.74	Z : -13.63
X : -160.86	Y : 0.75	Z : -13.63
X : -163.33	Y : 0.76	Z : -13.63
X : -165.46	Y : 0.76	Z : -13.63
X : -167.33	Y : 0.76	Z : -13.63
X : -168.96	Y : 0.77	Z : -13.63
X : -170.37	Y : 0.78	Z : -13.63
X : -171.59	Y : 0.77	Z : -13.63
X : -172.66	Y : 0.79	Z : -13.63
X : -173.57	Y : 0.78	Z : -13.63
X : -174.24	Y : 0.78	Z : -13.63
X : -174.95	Y : 0.81	Z : -13.63
X : -175.57	Y : 0.79	Z : -13.63
X : -176.08	Y : 0.78	Z : -13.63
X : -176.54	Y : 0.77	Z : -13.63
X : -170.59	Y : 0.78	Z : -13.63
X : -171.77	Y : 0.77	Z : -13.63
X : -172.80	Y : 0.75	Z : -13.63
X : -173.69	Y : 0.75	Z : -13.63
X : -174.47	Y : 0.76	Z : -13.63
X : -175.04	Y : 0.75	Z : -13.63
X : -175.63	Y : 0.75	Z : -13.63
X : -176.15	Y : 0.76	Z : -13.63
X : -176.60	Y : 0.76	Z : -13.63
X : -176.97	Y : 0.76	Z : -13.63
X : -177.31	Y : 0.75	Z : -13.63
X : -177.60	Y : 0.76	Z : -13.63
X : -177.85	Y : 0.77	Z : -13.63
X : -171.58	Y : 0.75	Z : -13.63
X : -172.63	Y : 0.75	Z : -13.63
X : -173.43	Y : 0.75	Z : -13.63
X : -174.26	Y : 0.74	Z : -13.63
X : -174.96	Y : 0.74	Z : -13.63
X : -175.57	Y : 0.75	Z : -13.63
X : -176.09	Y : 0.77	Z : -13.63
X : -176.54	Y : 0.77	Z : -13.63
X : -176.93	Y : 0.79	Z : -13.63
X : -177.29	Y : 0.79	Z : -13.63
X : -177.58	Y : 0.77	Z : -13.63

Fustion with magnetometer

Hi my friend, have you ever tried fusing this library of yours with data from magnetometer to prevent drift on the gyro? If so, could you point me in the right direction?

BTW, your library is really great! Works perfectly and apart from the drift on yaw, its produces an awesome result!

Different gyro value at startup and after reset

Hi there,
I'm using esp-wroom32 and i just noticed that when we turn the power ON (from usb or from a battery) calibration coefs are 2x higher than what they should be. measurments are also 2 times higher.
When i reset the board via the reset bouton, calibration coef are goods, 2 times less than before. Measurments are perfect.

This behavior is hapening every time.

exemple :
when i turn it ON it's : (coefX = 4 / coefY = 2 / coefZ = 2)
Each time i reset it's : (coefX = 2 / coefY = 1 / coefZ = 1)

I tried to reset the MPU, only the gyro etc... but nothing works. I'm not sure if it is related to the mpu or to the ESP32 but i never had this kind of problem with other i2c device (nor icm20948 nor mpu9050...)

Thank you,

calcOffsets not working if being called outside of setup?

Hello, I'm currently making a RC car and my remote uses the MPU6050 + this library.
I have 2 modes of control which involves the MPU: AngleX(for turning left and right) and angleY(for going forward and backwards) for the first mode and AngleZ, acting as a steering for the second mode. I know that when I turn on the remote and wait for the offset calculation, all values should be 0(assuming remote was put in the desired position). But I wanted to add a functionality to the remote where no matter the holding position, if I press a button, I can recalculate the offsets and I can start controlling the car with the new offsets. I tried doing that using the calcOffsets(true, true)(in a separate function) method, but it doesn't work. I also tried using the setGyroOffsets(0,0,0) and setAccOffsets(0,0,0)(also in a separate function) but it also didn't work for me. what works is resetting the board(arduino mega). I could be wrong in assuming that the offset calculation in this library just sets the fields to 0 and start doing angle measurements from there, that's how I think it works, if not, a clarification from the devs will be great.
Great library and documentation, thank you for making it!

'long' should be 'unsigned long' for millis value.

To avoid the rollover problem, the variable to store a millis value in should be 'unsigned long'.

In "MPU6050_light.h", the preInterval should be unsigned long.
In the example "GetAllData.ino", the timer should be unsigned long.

There are a few minor things:

Could you use spaces instead of tabs ? Both are used and the indents are not the same.
A millis timer is: if (currentMillis - previousMillis >= interval) {. Could you change the > into >= in the example "GetAllData.ino" ?

This is trickery code:

accZ = (!upsideDownMounting - upsideDownMounting) * ((float)rawData[2]) / acc_lsb_to_g - accZoffset;

Please use normal code:

accZ = ((float)rawData[2]) / acc_lsb_to_g - accZoffset;
if (upsideDownMounting)
  accZ = -accZ;

What do the different status messages mean?

Hello all,

Does anyone know what the different error statuses mean when initializing the device? I keep getting MPU6050 status: 4 and MPU status: 2 errors when powering the device. I'd like to know what these mean?

Thanks!

Pitch value changes with change in GyroZ

Thanks for your amazing library.

I am using your library for balancing drone.
For eg my drone is at zero pitch and zero roll. But as soon as I get angular rotation in z axis. pitch and roll value increases for a moment and return backs to normal. But that moment is enough for my drone to crash.
I would be higly obliged if you provide me any guidance to solve this issue
Thanking you.

reset angle values to zero in void loop

can anyone tell how to zero the value if mpu6050 angle reading during loop.
by pressing a button attached to digital pin Arduino, values will be reset to zero

question regarding the source code and the documentation

Why is the source code like this
angleAccX = atan2(accY, sgZ * sqrt(accZ * accZ + accX * accX)) * RAD_2_DEG; // [-180,+180] deg
angleAccY = - atan2(accX, sqrt(accZ * accZ + accY * accY)) * RAD_2_DEG; // [- 90,+ 90] deg

when in the documentation, it is written as the following?
angleAccX = atan2(sgZ *accY, sqrt(accZ *accZ + accX *accX)) * RAD_2_DEG; // [-180,+180] deg
angleAccY = atan2(accX, sqrt(accZ *accZ + accY *accY)) * RAD_2_DEG; // [- 90,+ 90] deg

Suggest replacing use of math functions with float versions instead of double versions

Hi
Thanks for the library, it has been most useful to me.

A suggestion if I may,

Using float version's of math functions would on some (perhaps even most) platforms result in faster execution and potentially smaller code size.

Function prototypes in math.h

double sqrt( double x );
float sqrtf( float x );

double atan2( double y, double x );
float atan2f( float y, float x );

Mixing float values with functions taking/returning double values means these need to be converted between the two,
(float <-> double). Explicitly using float versions of the respective functions will ensure that the most efficient compilation and execution is achieved. Similarly, expressing literals as typed values is normally best practice (particularly with floating point types) as it makes intent clear and leaves less room for ambiguity.

void MPU6050::update(){
  // retrieve raw data
  this->fetchData();
  
  // estimate tilt angles: this is an approximation for small angles!
  float sgZ = (float)((accZ>=0.f)-(accZ<0.f)); // allow one angle to go from -180 to +180 degrees
  //float sgZ = accZ<0.f ? -1.f : 1.f; /* Less obfuscated than above ?? */
  angleAccX =   atan2f(accY, sgZ*sqrtf(accZ*accZ + accX*accX)) * (float)RAD_2_DEG; // [-180,+180] deg
  angleAccY = - atan2f(accX,     sqrtf(accZ*accZ + accY*accY)) * (float)RAD_2_DEG; // [- 90,+ 90] deg

  unsigned long Tnew = millis();
  float dt = (float)(Tnew - preInterval) * 1e-3f;
  preInterval = Tnew;

  // Correctly wrap X and Y angles (special thanks to Edgar Bonet!)
  // https://github.com/gabriel-milan/TinyMPU6050/issues/6
  angleX = wrap(filterGyroCoef*(angleAccX + wrap(angleX +     gyroX*dt - angleAccX,180.f)) + (1.f-filterGyroCoef)*angleAccX,180.f);
  angleY = wrap(filterGyroCoef*(angleAccY + wrap(angleY + sgZ*gyroY*dt - angleAccY, 90.f)) + (1.f-filterGyroCoef)*angleAccY, 90.f);
  angleZ += gyroZ*dt; // not wrapped (to do???)

}

I hope you find this useful.

ESP32 support?

Will this interface with the MPU6050 on an ESP32 Development Board ?

Issue with ESP32

I connected MPU6050 in the default pins of SCL and SDA in ESP32 (GPIO 21 and GPIO 22). In the first time, ran smoothly right the example code. But when I adapted the library to my project code, simply the library stopped work. I've tried again run the code of example to test again, but w/o success — like the library doesn't find the SCL and SDA pins.

I already check out the hex address code of the sensor pins in ESP32 and it's right like in the library (0x68), so idk what's the problem or how solve it.

I just thought in set the pins when calls MPU6050 mpu(Wire); but idk how to do this.

The relationship between the offsets of the standard MPU6050 class from i2cdev and this library.

Hello! I have some offsets that I got for the MPU6050 class from the I2C library. But there the offsets are set, for example, as
void setXAccelOffset(int16_t offset);

For example, my offsets:
int16_t offsetMPU[6] = {-1372, 857, 887, 3, -40, -52};
However, in this class, I saw that the offsets are set in float format. Tell me, what is the relationship between them? I believe it exists, but I can't figure it out.
Thank you in advance for your time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.