arduino / Arduino

Arduino IDE 1.x
https://www.arduino.cc/en/software
Other
14.18k stars 7.01k forks source link

arduino mpu9250 weird data #6588

Closed Ausmints closed 7 years ago

Ausmints commented 7 years ago

I have a problem with connecting a MPU-92/65 to Arduino Leonardo and getting out data. I have used several versions of code that can be found on internet including http://www.lucidarme.me/?p=5057 and the official code for MPU-9150 Accelerometer + Gyro + Magnetometer (compass) in Arduino homepage and also a code I used previously with MPU-6050. But all of these don't send any data back and the serial monitor stays blank. Then I found this code on the internet -

// By Arduino User JohnChi // August 17, 2014 // Public Domain

include

const int MPU_addr=0x68; // I2C address of the MPU-6050 int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; void setup(){ Wire.begin(); Wire.beginTransmission(4); 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(4); Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) Wire.endTransmission(false); Wire.requestFrom(MPU_addr,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(",\t\t"); Serial.print(AcY); Serial.print(",\t\t"); Serial.print(AcZ); Serial.print(",\t\t"); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet Serial.print(",\t\t"); Serial.print(GyX); Serial.print(",\t\t"); Serial.print(GyY); Serial.print(",\t\t"); Serial.println(GyZ); delay(100); }

And from this code I finally got something, although rather gibberish, in the serial monitor. output I am still quite a beginner in all things programming so I am not quite sure what exactly am I doing wrong. Or is the MPU-92/65 broken?

per1234 commented 7 years ago

This topic is more appropriate for the Arduino Forum. I'm sure we'll be able to help you with your problem over there.

Please do this:

  1. Read http://forum.arduino.cc/index.php?topic=148850
  2. If you haven't already done so, create a new thread in the appropriate section of the forum (http://forum.arduino.cc/), following all the rules. Be sure to post your code, using code tags (</> button on the toolbar).

This issue tracker is only to be used for reporting bugs and feature requests.

EDIT: Here's the forum thread: http://forum.arduino.cc/index.php?topic=493618