#include <Wire.h>
#define MPU_ADDR 0x68
int16_t Ax, Ay, Az, Gx, Gy, Gz, Temperature;
void setup()
{
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Wire.begin();
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x75);
Wire.endTransmission(false);
Wire.requestFrom(MPU_ADDR, 1);
int16_t who_am_i = Wire.read();
Serial.println(who_am_i, HEX);
}
void loop()
{
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_ADDR, 14);
int16_t t = Wire.read();
Ax = (t << 8) | Wire.read();
t = Wire.read();
Ay = (t << 8) | Wire.read();
t = Wire.read();
Az = (t << 8) | Wire.read();
t = Wire.read();
Temperature = (t << 8) | Wire.read();
t = Wire.read();
Gx = (t << 8) | Wire.read();
t = Wire.read();
Gy = (t << 8) | Wire.read();
t = Wire.read();
Gz = (t << 8) | Wire.read();
t = Wire.read();
Serial.print("Ax: "); Serial.print(Ax);
Serial.print("| Ay: "); Serial.print(Ay);
Serial.print("| Az: "); Serial.print(Az);
Serial.print("| Temp: "); Serial.print(Temperature / 340.00 + 36.53);
Serial.print("| Gx: "); Serial.print(Gx);
Serial.print("| Gy: "); Serial.print(Gy);
Serial.print("| Gz: "); Serial.println(Gz);
delay(300);
}