Advertisement
lucainnoc

Untitled

May 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. // MPU-6050 Short Example Sketch
  2. #include<Wire.h>
  3. const int MPU=0x68; // I2C address of the MPU-6050
  4. int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
  5. void setup(){
  6. Wire.begin();
  7. Wire.beginTransmission(MPU);
  8. Wire.write(0x6B); // PWR_MGMT_1 register
  9. Wire.write(0); // set to zero (wakes up the MPU-6050)
  10. Wire.endTransmission(true);
  11. Serial.begin(9600);
  12. }
  13. void loop(){
  14. Wire.beginTransmission(MPU);
  15. Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
  16. Wire.endTransmission(false);
  17. Wire.requestFrom(MPU,14,true); // request a total of 14 registers
  18. AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
  19. AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  20. AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  21.  
  22. double pitch = (atan2(AcY,AcZ))*180.0/3.14;
  23. Serial.print("Pitch: ");
  24. Serial.print(pitch,3);
  25.  
  26.  
  27. Serial.println(" ");
  28. delay(500);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement