mpu6050 problem

Thank you so much for this reply. Also I have emailed to jeff, but he did't replie me yet. ok. let's try XD

Ok. I've modified the source and now Arduino can find my board, but it does the same value that the first sketch did... How is this possible?

Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
a/g:	-4488	244	17336	236	-134	-76
a/g:	-4476	252	17184	259	-146	-78
a/g:	-4436	368	17380	254	-162	-84
a/g:	-4496	336	17364	250	-173	-62
a/g:	-4544	200	17308	261	-189	-68

Looks like you are using the raw data example. There is another example directory included called "DMP6 Example" or something like that. That is the one that uses the DMP to process the data, and will allow you to output in degrees and accelerations instead of raw sensor values.

The DMP example code writes to the sensors FIFO buffer and uses an interrupt to notify the Arduino of incoming data. You have to have the interrupt pin on your sensor board connected to pin #2 I think of your Arduino (at least for my Uno R3)

Ok. I've connected the pin 2 to the pin int of my board, but it doesn't change. :roll_eyes: Howerever, now I want to try the "teapot" sketch, but I don't find the toxi libraries. Have you a dowload link for it?

import toxi.geom.*;
import toxi.processing.*;

Are you able to see anything at all in the serial monitor? If you aren't seeing anything in the serial monitor, you will not be able to get the teapot sketch to work. I never tried to get the teapot sketch to work and have never used processing for anything. I just output the yaw/pitch/roll and accelerations and wrote some C# code to view it. So I can't help you with getting that processing thing to work.

Here's a video of one of my C# programs using the output serial data.

wow! amazing! In serial monitor I read this:

Testing device connections...
MPU6050 connection successful
a/g:	-1900	264	17964	250	-172	-72
a/g:	-2024	140	17784	241	-160	-95
a/g:	-1888	212	17700	228	-162	-93
a/g:	-1932	172	17632	233	-170	-85
a/g:	-1872	192	17880	239	-146	-94
a/g:	-1952	184	17796	268	-175	-80
a/g:	-1932	284	17880	254	-160	-87
a/g:	-1984	288	17844	220	-191	-72
a/g:	-1964	228	17872	249	-160	-83

etc.
The problem is that this values are strange and i can't use it... Can you understand them?

The first 3 sets of values are are the raw accelerometer values. The 2nd set of 3 values looks to be the yaw/pitch/roll or Euler angles of the gyro.

The raw values for the accelerometer don't mean much. I think the sensors are 16 bit, so a number between 0-65k. Divide that by the G-range of the sensor. By default I think it is 4. Anyway, the DMP example has an option to enable real-world acceleration and/or readable acceleraction in G's instead of raw values. Read through the example code, you just have to un-comment a #define variable if I recall correctly. If you post your code, I will point it out for you.

thanks for this so fast reply. My code is this:

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

#define LED_PIN 13
bool blinkState = false;

void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    Wire.begin();

    // initialize serial communication
    // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)
    Serial.begin(38400);

    // initialize device
    Serial.println("Initializing I2C devices...");
    accelgyro.initialize();

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

    // configure Arduino LED for
    pinMode(LED_PIN, OUTPUT);
}

void loop() {
    // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

    // these methods (and a few others) are also available
    //accelgyro.getAcceleration(&ax, &ay, &az);
    //accelgyro.getRotation(&gx, &gy, &gz);

    // display tab-separated accel/gyro x/y/z values
    Serial.print("a/g:\t");
    Serial.print(ax); Serial.print("\t");
    Serial.print(ay); Serial.print("\t");
    Serial.print(az); Serial.print("\t");
    Serial.print(gx); Serial.print("\t");
    Serial.print(gy); Serial.print("\t");
    Serial.println(gz);

    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);
}

It's the example of the library MPU6050 (https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/Examples/MPU6050_DMP6/Processing/MPUTeapot.pde)

Yeah, that code is not using the DMP and is just returning raw values from the sensor. So the sketch is working correctly. If you want to output values that have units and mean something, try using this code.

https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/Examples/MPU6050_DMP6/MPU6050_DMP6.ino

This is the code that uses the DMP to output values in G-force and degrees of rotation.

The code you are using is just the individual raw values from the the accelerometer and gyro. The DMP code uses a fusion algorithm use the data from both the acclerometer AND gyro together to get much more accurate accleration and angle measurements than you get from the individual sensors. The calculations are being done on the DMP of the sensor though, so we can't really see what is going, its a black box to us.

The code from the FreeIMU library does not use the DMP, but uses its own fusion algorithm to determine the orientation of the sensor, and from what I can tell is at least as accurate and faster than the DMP code.

I would start with getting the DMP code working first though and see if you are happy with it or not before moving on.

Good luck.

thank you very much but there's another prolem:

Initializing I2C devices...
Testing device connections...
MPU6050 connection successful

Send any character to begin DMP programming and demo: 
Initializing DMP...
Enabling DMP...
Enabling interrupt detection (Arduino external interrupt 0)...
DMP ready! Waiting for first interrupt...
$?â

on the serial monitor I read this!!! :fearful: :fearful: :fearful:

You need to enter anything into the serial monitor and hit send. It doesn't matter what you type, I usually type "1". That should cause the program to start outputting values. The default output is for the teapot processing program to use (i've never used it so i can't vouch that it works, but I assume it does). It will look like gibberish and not mean anything to you. There are several #define commands near the top-middle of the code that if you uncomment will output things like Quaternion, Euler Angle, Yaw/Pitch/Roll, Real-World Acceleration and Readable Acceleration (gravity compensated) values in the serial monitor instead.

I've just seen that Jeff had comment the information to obtain the values in degrees and g. Tomorrow I'm testing. Thank you very, very much for all this information. :slight_smile:

No problem, I am new to all this too, and just got my first Arduino and MPU6050 sensor a few weeks ago, so this is all very fresh in my mind on exactly how to get it all working. :slight_smile: Glad I could help.

You're helping me a lot! ok, i changed my sketch in this:

#include "Wire.h"

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"

#include "MPU6050_6Axis_MotionApps20.h"
//#include "MPU6050.h" // not necessary if using MotionApps include file

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for SparkFun breakout and InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 mpu;

/* =========================================================================
   NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
   depends on the MPU-6050's INT pin being connected to the Arduino's
   external interrupt #0 pin. On the Arduino Uno and Mega 2560, this is
   digital I/O pin 2.
 * ========================================================================= */

/* =========================================================================
   NOTE: Arduino v1.0.1 with the Leonardo board generates a compile error
   when using Serial.write(buf, len). The Teapot output uses this method.
   The solution requires a modification to the Arduino USBAPI.h file, which
   is fortunately simple, but annoying. This will be fixed in the next IDE
   release. For more info, see these links:

   http://arduino.cc/forum/index.php/topic,109987.0.html
   http://code.google.com/p/arduino/issues/detail?id=958
 * ========================================================================= */



// uncomment "OUTPUT_READABLE_QUATERNION" if you want to see the actual
// quaternion components in a [w, x, y, z] format (not best for parsing
// on a remote host such as Processing or something though)
//#define OUTPUT_READABLE_QUATERNION

// uncomment "OUTPUT_READABLE_EULER" if you want to see Euler angles
// (in degrees) calculated from the quaternions coming from the FIFO.
// Note that Euler angles suffer from gimbal lock (for more info, see
// http://en.wikipedia.org/wiki/Gimbal_lock)
//#define OUTPUT_READABLE_EULER

// uncomment "OUTPUT_READABLE_YAWPITCHROLL" if you want to see the yaw/
// pitch/roll angles (in degrees) calculated from the quaternions coming
// from the FIFO. Note this also requires gravity vector calculations.
// Also note that yaw/pitch/roll angles suffer from gimbal lock (for
// more info, see: http://en.wikipedia.org/wiki/Gimbal_lock)
#define OUTPUT_READABLE_YAWPITCHROLL

// uncomment "OUTPUT_READABLE_REALACCEL" if you want to see acceleration
// components with gravity removed. This acceleration reference frame is
// not compensated for orientation, so +X is always +X according to the
// sensor, just without the effects of gravity. If you want acceleration
// compensated for orientation, us OUTPUT_READABLE_WORLDACCEL instead.
#define OUTPUT_READABLE_REALACCEL

// uncomment "OUTPUT_READABLE_WORLDACCEL" if you want to see acceleration
// components with gravity removed and adjusted for the world frame of
// reference (yaw is relative to initial orientation, since no magnetometer
// is present in this case). Could be quite handy in some cases.
//#define OUTPUT_READABLE_WORLDACCEL

// uncomment "OUTPUT_TEAPOT" if you want output that matches the
// format used for the InvenSense teapot demo
//#define OUTPUT_TEAPOT

and now I'm reciving this:

Initializing I2C devices...
Testing device connections...
MPU6050 connection successful

Send any character to begin DMP programming and demo: 
Initializing DMP...
Enabling DMP...
Enabling interrupt detection (Arduino external interrupt 0)...
DMP ready! Waiting for first interrupt...
ypr	0.09	-2.43	8.77
areal	-111	379	2561
ypr	0.07	-2.45	8.82
areal	-144	464	3145
ypr	0.05	-2.46	8.86
areal	-163	524	3579
ypr	0.03	-2.48	8.91
areal	-174	562	3896

Is ypr about the gyroscope? Howerever the areal values are still strange...

Yaw/pitch/roll is presumably found by a fusion algorithm contained within the DMP, so it uses both the gyroscope and accelerometer to determine the yaw/pitch/roll. Remember, the gyroscope does not actually determine angular position, but it measures angular velocity. To determine angular position from angular velocity, one must integrate the values over time from the gyroscope to find position. This introduces error, because of noise and imperfection in the sensor. The accelerometer should always read 1G of force in the Z direction when the Z-axis is normal to the ground plane. With this information you can also use an accelerometer to determine angular position, but accelerometers are very noisy so their data alone is not great either. But the fused algorithm presumably is much better.

To get that fancy display to work, you need to have the "Processing" working on your computer, and then find some libraries for it.
I don't recall all the details now, but it was quite a hassle to get it to work.

oh, also, the accelerometer values, I forget what units they are in, but they are not in G by default. I don't recall what it was, but I had to convert it by dividing by 28xx(don't remember what "xx" values are). My conversion and code are at home, I will look for it later. If you don't need an EXACT value now, just let the sensor sit still and take an average value of the Z axis (make sure the sensor is as flat as possible). This value should be about equal to 1G of accleration, so use that number to divide all of your accelerometer values before printing them to the serial port and they will be in G's.

michinyon:
To get that fancy display to work, you need to have the "Processing" working on your computer, and then find some libraries for it.
I don't recall all the details now, but it was quite a hassle to get it to work.

You don't need processing to get the display in the video I posted. That is C# code I wrote and OpenTK rendering the cube based on the yaw/pitch/roll values output from the sensor. It did take a decent amount of work getting it working, only because I had never tried 3D rendering before so I had to learn about that and the different libraries out there and finally chose OpenTK (which is free).

I found the toxi libraries for the processing sketch. But I'm still not understanding how to convert the raw values to the real position of my board on the space and if it's possible. Can you explain this to me?