Use of Inturputs pin on MPU-6050

I'm working a project to Control RC brushless motors with a tilt input, meaning as the device tilts over the motors will kick in too keeping it upright. pretty simple huh?

I've got my test rig working and have had some results, but not a stable rig as yet, the thing i can't understand is why my loop time is not consistent, with Plus or minus 1 sometimes 2 milliseconds, and sometimes missing data from the MPU-6050.

The code ive been using for reference is MPU6050_DMP6 which uses an interrupt but ive just come across this guy who is doing something very similar to what im trying to achieve but no interrupt! PID Arduino drone MPU6050 gyro
So is the interrupt needed to use the MPU-6050 with I^2 or not? And it it posible to remove it and have the gyro output data at a constant time period.

I remember reading that a signal over the interrupt signifies to the Arduino that there is data ready form the MPU-6050 but know little more than this!

pretty simple huh?

No, not at all simple, as you will discover. Basically, you are building a balancing robot, which has been done and discussed on this forum many times.

For informed help, please read and follow the directions in the "How to use this forum" post.

Thanks for the direction towards self-balancing robots, I am reading up about this now and the use of Kalman filters and Comparative filters.

I hope i am following the "how to use" post, yes I have done lots of google searches but i haven't found a clear answer about the two questions;

Is the interrupt necessary with the MPU-6050? and why do some people use them and some not?

Also

How to get a regular output from the MPU-6050 to then plug into the Arduino for PID control?

Thanks
Dan

Whether or not you need an interrupt to do that depends on all the details of how you write the rest of the code. And the particular details of your robot.

If you had read the "How to use" thread you would have known that you are asked to post your code. In code tags. And all the details of what you are building.

Don't "hope you are following" the rules. READ THEM!!!! It doesn't take long. It's ridiculous to expect a bunch of people to work on your project for you for free if you aren't even willing to read through a simple post explaining the rules.

I don't expect the members of this forum to do my code for me, if I had a very specific problem about a line that wouldn't compile then yes that would make sense to post it. But the code runs fine, I'm just trying to get a better understanding about the interrupt, and why its necessary in some code that I have found online and others not.

I referenced the two codes that I am talking about in my original post these are what I'm trying to understand, why does one use an interrupt and the other not? - does seeing my code really help you answer this question?

So is the interrupt needed to use the MPU-6050 with I^2 or not? And is it possible to remove it and have the gyro output data at a constant time period?

Dan_at_NewProd:
Thanks for the direction towards self-balancing robots, I am reading up about this now and the use of Kalman filters and Comparative filters.

I hope i am following the "how to use" post, yes I have done lots of google searches but i haven't found a clear answer about the two questions;

Is the interrupt necessary with the MPU-6050? and why do some people use them and some not?

Also

How to get a regular output from the MPU-6050 to then plug into the Arduino for PID control?

Thanks
Dan

No.

Desire, want and need.

The loop function can be used to get regular readings from the mpu6050. I suggest getting a copy of the MPU60X0 register PDF file. At first it may seem like ancient Greek but is a really useful document.

Is the interrupt necessary with the MPU-6050? and why do some people use them and some not?

  1. No
  2. Different programming styles

Dan_at_NewProd:

  • does seeing my code really help you answer this question?

Yes. I can’t tell you why a piece of code is written the way it is without seeing it.

I have some code on my computer now that handles the driving of my robot. Can you tell me why, without seeing any of it, I wrote it the way I did?

Please be reasonable. You’re acting like there’s only one way to do things and that just by mentioning interrupt we’re going to know exactly what the code does. That’s ridiculous. If you want to know something about some specific piece of code then it shouldn’t be a stretch to imagine that you should show the code you’re asking about to the people you’re asking.

Dan_at_NewProd:
Is the interrupt necessary with the MPU-6050? and why do some people use them and some not?

No, your code example http://www.electronoobs.com/eng_robotica_tut9_2_2.php doesn’t use interrupts and is very fast. The reading is probably noisy and doesn’t use much in the way of filtering. with a balancing bot, the noise will be eliminated at this high sample rate because the motors can’t react fast enough every little shift and tap will be detected

The angle calculations are using only the acceleration as it relates to gravity to make the calculations.

  Acc_rawX=(Wire.read()<<8|Wire.read())/4096.0 ; //each value needs two registres
  Acc_rawY=(Wire.read()<<8|Wire.read())/4096.0 ;
  Acc_rawZ=(Wire.read()<<8|Wire.read())/4096.0 ; 
 /*Now in order to obtain the Acc angles we use euler formula with acceleration values
 after that we substract the error value found before*/  
 /*---X---*/
 Acc_angle_x = (atan((Acc_rawY)/sqrt(pow((Acc_rawX),2) + pow((Acc_rawZ),2)))*rad_to_deg) - Acc_angle_error_x;
 /*---Y---*/
 Acc_angle_y = (atan(-1*(Acc_rawX)/sqrt(pow((Acc_rawY),2) + pow((Acc_rawZ),2)))*rad_to_deg) - Acc_angle_error_y;

How to get a regular output from the MPU-6050 to then plug into the Arduino for PID control?

there are two ways you can do this get reading from the MPU 6050 as fast as you can and calculate the angle. then every so many milliseconds (I like 10ms for my balancing bot) pass the stable reading to the PID Loop

void loop(){
// Get Readings
// filter Readings
// Skip PID until 10 MS has passed
  static unsigned long _Timer;
  if ( millis() - _Timer >= (10)) {
    _Timer += (10);
    // PID Calculations
    // Adjust motors
  }
}

Running PID to fast will make Ki and KD difficult to tune.
Now My balancing bot ( https://youtu.be/uyHdyF0_BFo ) uses the interrupt feature of the MPU6050 along with the MPU6050’s ability to Calculate and merge many readings into a stable reading DMP (Digital Motion Processing) with the MPU6050’ built-in microprocessing unit. The link to my thread (a couple years old now) is here with the code
https://forum.arduino.cc/index.php?topic=397918.msg2786138#msg2786138
One drawback with my code is that the MPU6050 firmware needs to be loaded each time its powered on and this takes up a chunk of the UNO’s memory.
One advantage is that the UNO’s processing load is minimal allowing it to do more if you can fit it in :slight_smile:

Z

Thanks, zhomeslice, that really helps!