MPU6050

Hallo liebes Forum,
ich möchte mit dem Lagesensor MPU 6050 den aktuellen Winkel auslesen.
Jetzt habe ich mit dem I2C-Scanner zwar die adresse auslesen können, (0x68), wenn ich dann allerdings den Sketch von AZ-Delivery Imu_zero lade, bekomme ich im seriellen Monitor die Meldung connection failed.
Könnt ihr mir bitte sagen, was ich da falsch mache? es sind die standardsketche aus dem E-Book unverändert.

LG Fridold

The code below works fine to measure tilt angles.

bekomme ich im seriellen Monitor die Meldung connection failed.

You may need to add 3.3K pullup resistors from SDA and SCl to 3.3V. They are not present on many of the cheap MPU-6050 modules from China.

/ minimal MPU-6050 tilt and roll (sjr)
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
// tested with eBay Pro Mini, **no external pullups on SDA and SCL** (works with internal pullups!)
//
#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;

void setup() {

  Wire.begin();                                      //begin the wire communication
  Wire.beginTransmission(MPU_addr1);                 //begin, send the slave adress (in this case 68)
  Wire.write(0x6B);                                  //make the reset (place a 0 into the 6B register)
  Wire.write(0);
  Wire.endTransmission(true);                        //end the transmission
  Serial.begin(9600);
}

void loop() {

  Wire.beginTransmission(MPU_addr1);
  Wire.write(0x3B);  //send starting register address
  Wire.endTransmission(false); //restart for read
  Wire.requestFrom(MPU_addr1, 6, true); //get six bytes accelerometer data

  xa = Wire.read() << 8 | Wire.read();
  ya = Wire.read() << 8 | Wire.read();
  za = Wire.read() << 8 | Wire.read();
// formula from https://wiki.dfrobot.com/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing
  roll = atan2(ya , za) * 180.0 / PI;
  pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied

  Serial.print("roll = ");
  Serial.print(roll,1);
  Serial.print(", pitch = ");
  Serial.println(pitch,1);
  delay(400);
}

Hi folks,

thanks for your answers.

the idea to attach two pull up do not change anything. i got the same response, ....no connection......

@ jremington : your code works fine , so i wanna thank you very much.

best regards fridold