Go Down

Topic: mpu6050 problem (Read 13 times) previous topic - next topic

Subsea

thanks for this so fast reply. My code is this:
Code: [Select]
// 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)

jjspierx

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.

Subsea

thank you very much but there's another prolem:
Code: [Select]
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!!! :smiley-eek-blue: :smiley-eek-blue: :smiley-eek-blue:

jjspierx

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.

Subsea

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.  :)

Go Up