MPU6050 Help

Hello, I am trying to figure out how to use a MPU6050 breakout board i bought, but i am stumped. I will attach the three files i am trying to use, but i cannot get it to work correctly. the second one is the closest. it will actually compile and give me values, but im not sure whats wrong. i modified the code to convert the raw data to readable data, but now no matter what i do, the accelerometer is almost always at 0 for x, y, and z. The gyroscope kind of works, but it seems to calibrate itself every time i stop moving the board. i do believe that it is correct, but if i hold the breadboard that the breakout board is on still, all the gyro values will go to 0, or something very close to 0. if i move the breadboard, the values change and when i stop moving again, they all go back to 0 again. any help is greatly appreciated. i am new with this stuff, and i do not really know what i am doing. thanks!

gyro_accel_test1.ino (1.91 KB)

gyro_accel_test2.ino (31.4 KB)

gyro_accel_test3.ino (3.36 KB)

The MPU-6050 sensor has MEMS sensors for gyro and acceleration. The gyro drifts and the accelerometer is sensitive for vibration.

The second file is this, http://playground.arduino.cc/Main/MPU-6050 If that is working, the sensor is connected to the I2C bus and working. You can use that sketch to do some calculations, try to compensate the offset and to learn about the MPU-6050.

The first and third files is code by Jeff Rowberg. Go to his website and install the i2cdev library and the MPU-6050 library with examples. The first example is simple, the second example is the serious work with dmp and calculations and quaternions. http://www.i2cdevlib.com/

Did you know this Kalman guide ? http://forum.arduino.cc/index.php/topic,58048.0.html

I have been to Jeff Rowbergs github and downloaded his library and example sketches, but it still would not compile. it gave a ton of errors with the library. but i didnt mess with it too much because i got one of the files to return values, but they are weird values. i modified the code to divide the raw values for the accelerometer by 16384 (since i am using the 2g setting) and the gyro by 131 (since i am using the +-250 setting). the accelerometer now always says 0, even when i move the breadboard the MPU6050 breakout board is on. so something is not right there. also, the gyro always goes back to 0 for all the axes after i stop moving the board, even when they should not be 0. its like it recalibrated itself. it seems to do it every time it prints out the values in the serial monitor. i really have no idea what is going on. edit: i am reading that link you posted about the kalman guide. hopefully it helps! thanks!

suicidalacorn: ...a ton of errors...

You could make a screendump of the first errors. The first one, or two or three errors is what to look at. I don't know what kind of errors, perhaps missing something or only compiler warnings for (un)signed variable mismatch.

This is the first one.

In the example sketch, it says [glow=yellow,2,300]#include "Wire.h"[/glow], you could try [glow=yellow,2,300]#include <Wire.h>[/glow].

The error message is about the use of ‘SPI’ in the functions in I2Cdev.cpp
But I can’t find ‘SPI’ anywhere in that file

So I don’t know how you got that message, it seems impossible.
Is your I2Cdev.cpp the same as the one in the link ?
Do you have a lot (too many) libraries installed mixed with older ones or with the same name that were downloaded from different locations ?

suicidalacorn: also, the gyro always goes back to 0 for all the axes after i stop moving the board, even when they should not be 0. its like it recalibrated itself. it seems to do it every time it prints out the values in the serial monitor. i really have no idea what is going on.

The gyro should go to zero whenever it is not moving. The gyro measures angular velocity, so when it is not moving, it measures zero. A common misconception is that gyro's measure anglular position, but they do not. However, by integrating the angular velocity, coupled with accelerometer data, you can get relatively good pitch and roll data. Rowberg's code that accesses the DMP can calculate Yaw, Pitch and Roll (though the yaw is subject to drift without a magnetometer).

Erdin:
In the example sketch, it says [glow=yellow,2,300]#include "Wire.h"[/glow], you could try [glow=yellow,2,300]#include <Wire.h>[/glow].

The error message is about the use of ‘SPI’ in the functions in I2Cdev.cpp
But I can’t find ‘SPI’ anywhere in that file
i2cdevlib/I2Cdev.cpp at master · jrowberg/i2cdevlib · GitHub
So I don’t know how you got that message, it seems impossible.
Is your I2Cdev.cpp the same as the one in the link ?
Do you have a lot (too many) libraries installed mixed with older ones or with the same name that were downloaded from different locations ?

I’ve gotten those same errors before trying to compile with the i2Cdev library. I don’t remember what I did to fix it, but I remember maintaining two sets of the i2C library, the original one, and my modified one which actually compiled. When I get home later today, I will try to compare the two and see if I can figure out what the problem was for me and see if it is the same for you. I haven’t used Rowberg’s code in awhile, I have been playing around with FreeIMU libary (which also uses i2CDev).

jjspierx:
The gyro should go to zero whenever it is not moving. The gyro measures angular velocity, so when it is not moving, it measures zero. A common misconception is that gyro’s measure anglular position, but they do not. However, by integrating the angular velocity, coupled with accelerometer data, you can get relatively good pitch and roll data. Rowberg’s code that accesses the DMP can calculate Yaw, Pitch and Roll (though the yaw is subject to drift without a magnetometer).

That makes a ton of sense! thank you for clarifying! i never would have known that, i thought it measured the position based on gravity or something. so if i use the dmp example from Rowberg’s library i should be able to get the pitch and roll?
also, thank you for offering to look at the libraries. i will change #include “Wire.h” to #include <Wire.h> and see if that helps. thanks!

suicidalacorn:
That makes a ton of sense! thank you for clarifying! i never would have known that, i thought it measured the position based on gravity or something. so if i use the dmp example from Rowberg’s library i should be able to get the pitch and roll?
also, thank you for offering to look at the libraries. i will change #include “Wire.h” to #include <Wire.h> and see if that helps. thanks!

Yeah, when I said it was a common misconception, I meant that I myself made that mistake when I started out playing with sensors. :-). Actually the accelerometer is more instrumental to determining the pitch and roll than the gyro. The accelerometer measure accelerations, so when at rest when laying flat the acceleration due to gravity should register 1G (when converted from raw value) in the -Z direction. As the sensor rotates you can tell the pitch and roll by determining the how the acceleration due to gravity vector changes. However, other accelerations will interfere with this, so using the fusion of accelerometer and gyro data together you can get pretty reliable pitch and roll. You can also get yaw, but only relative yaw, since there is no magnetometer to tell you magnetic north as a baseline. Rowbergs code which accesses the DMP of the MPU6050 does this automatically for you, it is like a black box of calculations that we don’t have access to, but we can get yaw/pitch/roll outputs from it.

Awesome! re-downloaded the arduino idea and started from scratch. i only added a DHT22 library and all the data from this link: i2cdevlib/Arduino/MPU6050 at master · jrowberg/i2cdevlib · GitHub
it did compile, but i have not had a chance to upload it yet. i will upload it in a few minutes and see what i get. (by the way, i am talking about the DMP example sketch.) i just downloaded processing earlier today and i have next to no experience with it, but when i try to run the processing sketch thing included with the DMP example, i get these errors. it says i might be missing a library, so should i just google the library it says and put it in the processing library folder?
edit: i uploaded the sketch, and in the serial monitor, this is what i get. i assume this is because it is meant to be running with processing???

The advanced example with 'dmp' uses the interrupt. Connect the INT to Arduino digital pin 2.

Erdin:
The advanced example with ‘dmp’ uses the interrupt.
Connect the INT to Arduino digital pin 2.

ok, i did that, but see my last post. i am still getting the same thing.
Edit: yes, the reason it was weird symbols was because it was made for processing! and i downloaded the missing library and it works! thank you guys so much!