Go Down

Topic: MPU-6050 errors reading data (Read 6402 times) previous topic - next topic

badben

I am a complete noobie with both arduino and electronics in general.

I have and arduino due and a mpu-6050 breakout board from ebay http://www.ebay.co.uk/itm/1x-MPU-6050-Module-3-Axis-Gyroscope-3-Axis-Accelerometer-Sensor-MPU6050-Arduino-/320995455051?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item4abcd1f04b

I have connected the

3v3 pin to the 3.3v output on arduino
gnd pin to the gnd pin on arduino
scl pin to scl1 pin on arduino
sda pin to sda1 pin on arduino

I have used the following sketch http://playground.arduino.cc//Main/MPU-6050

the serial output is as follows:

InvenSense MPU-6050
June 2012
WHO_AM_I : 0, error = 1
PWR_MGMT_2 : 0, error = 1

MPU-6050
Read accel, temp and gyro, error = 1
accel x,y,z: 0, 4200984, 134257412
temperature: 37.259 degrees Celsius
gyro x,y,z : 1, 0, 137590197,

MPU-6050
Read accel, temp and gyro, error = 1
accel x,y,z: 0, 1073747994, 525467
temperature: 36.509 degrees Celsius
gyro x,y,z : 1, 0, 137590197,

MPU-6050
Read accel, temp and gyro, error = 1
accel x,y,z: 0, 4200984, 134257412
temperature: 37.259 degrees Celsius
gyro x,y,z : 1, 0, 137590197,

MPU-6050
Read accel, temp and gyro, error = 1
accel x,y,z: 0, 1073747994, 525467
temperature: 36.509 degrees Celsius
gyro x,y,z : 1, 0, 137590197,


................

I can't figure out why the error is shown as 1 and there is no change in the gyro readings and the accel readings seem to jump back and forth to exactly the same readings.

can anybody please help??

Thanks

Arctic_Eddie

The thing that puzzles me is how you can get such a large number from a signed integer. That's at least one clue about your problem.

Check sketch and monitor baud settings to be sure they're matched.

badben

I have checked and the baud rates are the same.

To make things more puzzling I have also run the I2C scanner sketch and it outputs

I2C Scanner
Scanning...
No I2C devices found

Scanning...
No I2C devices found

Scanning...
No I2C devices found

When reverting back to the earlier sketch for the MPU6050 the output to serial monitor shows an error of 1 when trying to read the sensor.  The error number is the output from:

Code: [Select]

Wire.endTransmission(false);


According to the Arduino reference the error codes are as follows:

    0:success
    1:data too long to fit in transmit buffer
    2:received NACK on transmit of address
    3:received NACK on transmit of data
    4:other error

Therefore it looks like this is an issue with transmit buffer, whatever that is?

How do I resolve this or am I going in completely the wrong direction?

Arctic_Eddie

I'm at a loss also but the data size suggests a mismatch of some form. The print statements would fit if the data were long but the structure declarations show 8 and 16 bit type. I guess the first thing to do is go back to the sketch and look for typos.

badben

I found the problem.

The issue was I think that the mpu-6050 board is set to sleep mode by default.  In order to get round this I first of all added the following library for the MPU6050

http://www.i2cdevlib.com/devices/mpu6050#source

Then I had to comment out the
Code: [Select]
#include <avr/pgmspace.h> in MPU6050.h

and then I had to comment out any additional relating to
Code: [Select]
useProgMem in MPU6050.cpp as there is an issue with <avr/pgmspace.h> on the Arduino Due apparently.

Finally, using the example sketch for the library for raw sensor data I added the following code:

Code: [Select]
accelgyro.setSleepEnabled(false);

immediately before:

Code: [Select]
accelgyro.initialize();

It now works!

Arctic_Eddie

Glad you found the problem. There will likely be lots of library problems with the Due. However, progress is progress.

I'm having the exact same error as you, but the solution you stated isn't working for me, could you please paste your code?

#7
Aug 13, 2013, 04:03 am Last Edit: Aug 13, 2013, 04:08 am by PolskiKutz Reason: 1
Hello,

me and my friends are using shield http://dx.com/p/gy-521-mpu-6050-module-3-axis-gyroscope-accelerometer-for-arduino-162646 and we are encountering the exact same problem as badben. We followed Your instructions and we are still getting same errors.
The sketches we use are located here: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050/Examples (we tried both of them), http://playground.arduino.cc/Main/MPU-6050
We are wondering if it's our fault (however we followed the instructions precisely) or maybe it's the shield that is broken. We dropped it from about 1.5m once but since it should report +-16g I find it hard to belive that it could break after that sort of accident.

Any help would be great! Cheers!

For the ones still trying to figure out how to make this breakout board work, I found the solution on Arduino Playgroud, and posted on this page: http://www.i2cdevlib.com/forums/topic/8-mpu6050-connection-failed/#entry352

It seens that you need to put pull-up resistors on the SCL and SDA pins. 10K worked here.

Would it be POSSIBLE FOR YOU TO SEND ME YOUR LIBRARY? I DONT UNDERSTAND WHAT PARTS TO DELETE IN THE MPU6050.CPP.

THANKS

Hi could you mention how to manipulate the 6050.cpp and add or remove what,

I have the same problem and cant geti it worked :(

kubarbaz

Code: [Select]

#include<Wire.h>
/*const int MPU=0x68;*/
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(0x68);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(0x68);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(0x68,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  delay(333);
}


i've eliminated MPU=0x68 variable and used 20/21 pins ( scl sda ) and it worked. hope it helps.

Go Up