Arduino leonardo with MPU6050_DMP

Hi guys, I am newbie here, it is my first question. I hope i can get your response smiley-wink

Actually I want to construct a B-robot from this website " GitHub - JJulio/b-robot: Self Balance arduino robot. Control via Smartphone. Fully 3D printed project." and I use Arduino leonardo .
and now can get the data from data from MPU6050 by including only MPU6050.h, I2Cdev.h, Wire.h. ( the code is below). I connect SDA , SCL arduino-pin SDA SCL MPU605-pin, and it work well when i connect int-pin of MPU to nothing , but when I connect int_pin of MPU to digital pin 3(int #0_pin) of Arduino, the data is not sent .

and the second problem is that i want the get the data in euler or row pitch roll format. and I use the example code in the folder MPU6050_DMP6 (you will have this code if you go to that link and download). It does not work even though I connect or not connect the int_pin of MPU. Could anyone help me ???? thanks in advance smiley-grin

#include "I2Cdev.h"
#include "MPU6050.h"

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

// 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;
//MPU6050 accelgyro(0x69); // <-- use for AD0 high

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

// uncomment "OUTPUT_READABLE_ACCELGYRO" if you want to see a tab-separated
// list of the accel X/Y/Z and then gyro X/Y/Z values in decimal. Easy to read,
// not so easy to parse, and slow(er) over UART.
#define OUTPUT_READABLE_ACCELGYRO

// uncomment "OUTPUT_BINARY_ACCELGYRO" to send all 6 axes of data as 16-bit
// binary, one right after the other. This is very fast (as fast as possible
// without compression or data loss), and easy to parse, but impossible to read
// for a human.
//#define OUTPUT_BINARY_ACCELGYRO


#define LED_PIN 13
bool blinkState = false;

void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    // 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");

    // use the code below to change accel/gyro offset values
    /*
    Serial.println("Updating internal sensor offsets...");
    // -76   -2359   1688   0   0   0
    Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); // -76
    Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); // -2359
    Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); // 1688
    Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); // 0
    Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); // 0
    Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); // 0
    Serial.print("\n");
    accelgyro.setXGyroOffset(220);
    accelgyro.setYGyroOffset(76);
    accelgyro.setZGyroOffset(-85);
    Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); // -76
    Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); // -2359
    Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); // 1688
    Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); // 0
    Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); // 0
    Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); // 0
    Serial.print("\n");
    */

    // 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);

    #ifdef OUTPUT_READABLE_ACCELGYRO
        // 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);
    #endif

    #ifdef OUTPUT_BINARY_ACCELGYRO
        Serial.write((uint8_t)(ax >> smiley-cool); Serial.write((uint8_t)(ax & 0xFF));
        Serial.write((uint8_t)(ay >> smiley-cool); Serial.write((uint8_t)(ay & 0xFF));
        Serial.write((uint8_t)(az >> smiley-cool); Serial.write((uint8_t)(az & 0xFF));
        Serial.write((uint8_t)(gx >> smiley-cool); Serial.write((uint8_t)(gx & 0xFF));
        Serial.write((uint8_t)(gy >> smiley-cool); Serial.write((uint8_t)(gy & 0xFF));
        Serial.write((uint8_t)(gz >> smiley-cool); Serial.write((uint8_t)(gz & 0xFF));
    #endif

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

Hi meta

I have the same problem with yours.

every body pleas help us.

thanks :slight_smile:

    #ifdef OUTPUT_BINARY_ACCELGYRO
        Serial.write((uint8_t)(ax >> smiley-cool); Serial.write((uint8_t)(ax & 0xFF));
        Serial.write((uint8_t)(ay >> smiley-cool); Serial.write((uint8_t)(ay & 0xFF));
        Serial.write((uint8_t)(az >> smiley-cool); Serial.write((uint8_t)(az & 0xFF));
        Serial.write((uint8_t)(gx >> smiley-cool); Serial.write((uint8_t)(gx & 0xFF));
        Serial.write((uint8_t)(gy >> smiley-cool); Serial.write((uint8_t)(gy & 0xFF));
        Serial.write((uint8_t)(gz >> smiley-cool); Serial.write((uint8_t)(gz & 0xFF));
    #endif

I am certain that there is no constant named smiley-cool defined anywhere. Copying crap that someone else has mis-posted is useless.

Hi
This video Simple Arduino Robot uses a MPU6050 to manage steering - YouTube might help.
It talks about some of the issues you can run into when a Leonardo is linked to a 6050.
If it's not what you're needing, please say so, & maybe I or, someone else, can post something
that will help.

The following is raw code to get the data vectors, it originally came from either a library and/or sketch I forget , I tore it apart and unlike most people READ THE DATA SHEET.

I tried using the interrupt function also but couldn't use it cause my wiring didn't allow me access to a interrupt pin. Instead set up a timer to poll the chip every X amount of time for new data.

It reads the vectors as a string of bytes, then you just chuck the bytes into the correct variable.

// variables
uint8_t IMUAddress = 0x68;

//setup
i2cWrite(IMUAddress,0x6B,0x00); // disable sleep mode

if(i2cRead(IMUAddress,0x75,1)[0] != 0x68) // confirms that it is IC2 address 68
while(1);

if (i2cRead(IMUAddress,0x19,1)[0] != 0x07)
i2cWrite(IMUAddress,0x19,0x07); //sample rate 1KHz 8k/(7+1) = 1000 Hz

if (i2cRead(IMUAddress,0x1A,1)[0] != 0x05)
i2cWrite(IMUAddress,0x1A,0x05); // see page 13 of data sheet, Register 26/1A Hex CONFIG

if (i2cRead(IMUAddress,0x1B,1)[0] != 0x18)
i2cWrite(IMUAddress,0x1B,0x18); // Register 27 Gyroscope Configuration GYRO_CONFIG +- 2000

if (i2cRead(IMUAddress,0x1C,1)[0] != 0x18)
i2cWrite(IMUAddress,0x1C,0x18);

//some subroutine in the program
uint8_t* data = i2cRead(IMUAddress,0x3B,14); // this data is stored in register 3B(Hex)
accX = ((data[0] << 8) | (data[1]));
accY = ((data[2] << 8) | (data[3]));
accZ = ((data[4] << 8) | data[5]);
temp = ((data[6] << 8) | data[7]);
gyroY = ((data[8] << 8) | data[9]);
gyroX = ((data[10] << 8) | data[11]);
gyroZ = ((data[12] << 8) | data[13]);
//// Calculate the angls based on the different sensors and algorithm /////
accYangle = ((double)atan2(accY,accZ)+PI)*RAD_TO_DEG; // angle calculated soley from the accelometer, no drift but unstable
accXangle = ((double)atan2(accX,accZ)+PI)*RAD_TO_DEG;
temp = (temp+512)/340 + 35;
//////// calculate gyrorate //////////////////////////////////////////
gyroXrate = -(double)(gyroX/16.4); // 16.4 is from the spec sheet for proper calibration at 2000deg/s on gyros
gyroYrate = -(double)(gyroY/16.4);
gyroZrate = (double)(gyroZ/16.4);

//end of program subroutines to be called on data read/writes to 6050
void i2cWrite(uint8_t Address, uint8_t registerAddress, uint8_t data){

Wire.beginTransmission(Address); // address 68
Wire.write(registerAddress); // the address
Wire.write(data);
Wire.endTransmission(); // Send stop

}
uint8_t* i2cRead(uint8_t Address, uint8_t registerAddress, uint8_t nbytes) {
uint8_t data[nbytes];

Wire.beginTransmission(Address);
Wire.write(registerAddress);
Wire.endTransmission(false); // Don't release the bus
Wire.requestFrom(Address, nbytes); // Send a repeated start and then release the bus after reading
for(uint8_t i = 0; i < nbytes; i++)
data = Wire.read();

  • return data;*
    }[/quote]