Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MPU-6050 Short Example Sketch
- #include<Wire.h>
- const int MPU=0x68; // I2C address of the MPU-6050
- int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
- void setup(){
- Wire.begin();
- Wire.beginTransmission(MPU);
- 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(MPU);
- Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
- Wire.endTransmission(false);
- Wire.requestFrom(MPU,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)
- double pitch = (atan2(AcY,AcZ))*180.0/3.14;
- Serial.print("Pitch: ");
- Serial.print(pitch,3);
- Serial.println(" ");
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement