sketch_81_I2C-Bus_Scan

sketch_81_I2C-Bus_Scan
  /*Ausgabe der "Rohdaten" des MPU6050 am Serial Monitor, inkl.Temperatur.
  MPU-6050 Short Example Sketch, from Arduino User JohnChi, Public Domain.*/
  
  #include<Wire.h>
  const int MPU_addr=0x68;                      // I2C address of the MPU-6050
  int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;          // "16_t" gibt an, dass die integer-Variable 16 Bit haben soll... 
                                                // ...dadurch funkioniert es auch mit ESP8622 (integer ist dort 32 Bit lang).
  void setup()
  {
    Wire.begin(D2,D1);                          // D2 (SDA) und D1 (SCL)
    Wire.beginTransmission(MPU_addr);
    Wire.write(0x6B);                           // PWR_MGMT_1 register
    Wire.write(0);                              // set to zero (wakes up the MPU-6050)
    Wire.endTransmission();
    Serial.begin(9600);                         // Serial Monitor auf 9600 Baud einstellen !
  }
  
  void loop()
  {
    Wire.beginTransmission(MPU_addr);
    Wire.write(0x3B);                           // starting with register 0x3B (ACCEL_XOUT_H)
    Wire.endTransmission();
    Wire.requestFrom(MPU_addr,14);              // 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)
    Tmp=Wire.read()<<8|Wire.read();             // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
    GyX=Wire.read()<<8|Wire.read();             // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
    GyY=Wire.read()<<8|Wire.read();             // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
    GyZ=Wire.read()<<8|Wire.read();             // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
    
    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);  // see data sheet
    Serial.print(" | GyX = "); Serial.print(GyX);
    Serial.print(" | GyY = "); Serial.print(GyY);
    Serial.print(" | GyZ = "); Serial.println(GyZ);
    delay(2000);                  
  }