Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. // MPU-6050 Short Example Sketch
  2. // By Arduino User JohnChi
  3. // August 17, 2014
  4. // Public Domain
  5. #include<Wire.h>
  6. const int MPU=0x68; // I2C address of the MPU-6050
  7. int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
  8. void setup(){
  9. Wire.begin();
  10. Wire.beginTransmission(MPU);
  11. Wire.write(0x6B); // PWR_MGMT_1 register
  12. Wire.write(0); // set to zero (wakes up the MPU-6050)
  13. Wire.endTransmission(true);
  14. Serial.begin(9600);
  15. }
  16. int prevAcX_value=0;
  17. int prevAcY_value=0;
  18. int prevAcZ_value=0;
  19. void loop(){
  20. Wire.beginTransmission(MPU);
  21. Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
  22. Wire.endTransmission(false);
  23. Wire.requestFrom(MPU,14,true); // request a total of 14 registers
  24. AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
  25. AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  26. AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  27. Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  28. GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  29. GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  30. GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  31. Serial.print("AcX = "); Serial.print(AcX);
  32. Serial.print(" | AcY = "); Serial.print(AcY);
  33. Serial.print(" | AcZ = "); Serial.print(AcZ);
  34. Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet
  35. Serial.print(" | GyX = "); Serial.print(GyX);
  36. Serial.print(" | GyY = "); Serial.print(GyY);
  37. Serial.print(" | GyZ = "); Serial.println(GyZ);
  38. delay(333);
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement