Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- const int MPU_addr=0x68; // I2C address of MPU-6500
- int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
- void setup(){
- Wire.begin();
- Wire.beginTransmission(MPU_addr);
- Wire.write(0x6B); // PWR_MGMT_1 register
- Wire.write(0); // set to zero (wakes up the MPU-6500)
- Wire.endTransmission(true);
- Serial.begin(9600);
- }
- void loop(){
- Wire.beginTransmission(MPU_addr);
- Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
- Wire.endTransmission(false);
- Wire.requestFrom(MPU_addr,14,true); // read 14 bytes from MPU-6500
- AcX=Wire.read()<<8|Wire.read(); // concatenate high and low byte for each axis
- AcY=Wire.read()<<8|Wire.read();
- AcZ=Wire.read()<<8|Wire.read();
- Tmp=Wire.read()<<8|Wire.read();
- GyX=Wire.read()<<8|Wire.read();
- GyY=Wire.read()<<8|Wire.read();
- GyZ=Wire.read()<<8|Wire.read();
- 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); // convert to Celsius
- Serial.print(" | GyX = "); Serial.print(GyX);
- Serial.print(" | GyY = "); Serial.print(GyY);
- Serial.print(" | GyZ = "); Serial.println(GyZ);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement