Arduino freezes the instant I connect either SCL or SDA pins (MPU6050 Acc)

I am trying to get an accelerometer working so that I can find the rotation of an object.
I have copy-pasted quite a lot of different codes for it, trying to make it work (I have the MPU6050 and I2C libraries installed) but to no avail.
In short my problem is that I soon as I connect either the SCL(A5) or SDA(A4) pins to my Arduino NANO, it just freezes.

Wiring:
5V → Vcc
Gnd → Gnd
A4 → SDA
A5 → SCL
(D2 → INT)

Some codes that I have used :
link: Arduino and MPU6050 Accelerometer and Gyroscope Tutorial
(I’ve tried only the first written code)

+MPU6050_DM6 default example (ARDUINO IDE/File/Examples/MPU6050/MPU6050_DM6)

With this code I do get an output but it’s just this line

Serial.println(F("Initializing I2C devices..."));

and then it just freezes. Though I am quite sure it’s not the code’s fault.

Do you have any ideea how I could resolve my problem?

MPU6050_DMP6.ino (16.6 KB)

Test basic I2C communications by connecting the MPU6050 to the Arduino, and running the I2C address scanner program.

Test basic I2C communications by connecting the MPU6050 to the Arduino, and running the I2C address scanner program.

I tried this, but it also gets stuck. It just stays on

I2C Scanner
Scanning…

After a little bit of testing, I found out that it freezes at error = Wire.endTransmission();

(full code)

    // --------------------------------------
    // i2c_scanner
    //
    // Version 1
    //    This program (or code that looks like it)
    //    can be found in many places.
    //    For example on the Arduino.cc forum.
    //    The original author is not know.
    // Version 2, Juni 2012, Using Arduino 1.0.1
    //     Adapted to be as simple as possible by Arduino.cc user Krodal
    // Version 3, Feb 26  2013
    //    V3 by louarnold
    // Version 4, March 3, 2013, Using Arduino 1.0.3
    //    by Arduino.cc user Krodal.
    //    Changes by louarnold removed.
    //    Scanning addresses changed from 0...127 to 1...119,
    //    according to the i2c scanner by Nick Gammon
    //    https://www.gammon.com.au/forum/?id=10896
    // Version 5, March 28, 2013
    //    As version 4, but address scans now to 127.
    //    A sensor seems to use address 120.
    // Version 6, November 27, 2015.
    //    Added waiting for the Leonardo serial communication.
    //
    //
    // This sketch tests the standard 7-bit addresses
    // Devices with higher bit address might not be seen properly.
    //
     
    #include <Wire.h>
     
     
    void setup()
    {
      Wire.begin();
     
      Serial.begin(9600);
      while (!Serial);             // Leonardo: wait for serial monitor
      Serial.println("\nI2C Scanner");
    }
     
     
    void loop()
    {
      byte error, address;
      int nDevices;
     
      Serial.println("Scanning...");
     
      nDevices = 0;
      for(address = 1; address < 127; address++ )
      {
        // The i2c_scanner uses the return value of
        // the Write.endTransmisstion to see if
        // a device did acknowledge to the address.
        Wire.beginTransmission(address);
        error = Wire.endTransmission();
     
        if (error == 0)
        {
          Serial.print("I2C device found at address 0x");
          if (address<16)
            Serial.print("0");
          Serial.print(address,HEX);
          Serial.println("  !");
     
          nDevices++;
        }
        else if (error==4)
        {
          Serial.print("Unknown error at address 0x");
          if (address<16)
            Serial.print("0");
          Serial.println(address,HEX);
        }    
      }
      if (nDevices == 0)
        Serial.println("No I2C devices found\n");
      else
        Serial.println("done\n");
     
      delay(5000);           // wait 5 seconds for next scan
    }

Any ideas?

I gave you +1 karma for good debugging, getting closer to the problem :smiley:

You have a hardware problem on the I2C bus.
Either SDA is shortcut to SCL or SDA is shortcut to GND or SCL is shortcut to GND.
That causes the Wire.endTransmission() to halt the sketch. It is caused by the Wire library that has no timeouts for that. I know, it is a shame.

Either there is a shortcut on the module, or the module has no power.
When you have a 5V Arduino board and a MPU6050 module without level shifters for SDA and SCL, then you have a problem anyway.
Do you have a I2C module that is compatible with 5V ? An EEPROM for example ?

You can try a sketch with only a Wire.begin() in setup() en keep the loop() empty. That will initialize the I2C hardware, but will not use the I2C bus. Then you can measure with a multimeter which signal is stuck to GND.

@OP

You can bring START condition on the I2C Bus without having connection of any slave device in order to do the sanity check of the I2C Bus. The procedures are:

1. Connect 4.7k/2.2k pull-up with SDA and SCL lines.
2. Upload the following sketch. If START condition is asserted on the bus, the Serial Monitor will show 8

void setup()
{
    Serial.begin(9600);
    TWCR = 0b10100100; //TWINT TWEA TWSTA TWSTO TWWC TWEN X TWIE //no SCL is generated
    while(bitRead(TWCR,7)!= HIGH)
	;		//wait until the process completes and then TWINT will assume LH-state
    Serial.print((TWSR & 0b11111000),HEX); //shows: 0x08(00001000) indicates successful process; 
}

void loop()
{
    
}

You can bring START condition on the I2C Bus without having connection of any slave device in order to do the sanity check of the I2C Bus. The procedures are:

  1. Connect 4.7k/2.2k pull-up with SDA and SCL lines.
  2. Upload the following sketch. If START condition is asserted on the bus, the Serial Monitor will show 8

I've tried this and I do get an 8 as output. So I guess my Arduino is fine.

Either SDA is shortcut to SCL or SDA is shortcut to GND or SCL is shortcut to GND.

Tested for shorts but could not find any (I used a multimeter set to measure resistance of 200 Ohms)

Do you have a I2C module that is compatible with 5V ? An EEPROM for example ?

Unfortunately I don't have any.

You can try a sketch with only a Wire.begin() in setup() en keep the loop() empty. That will initialize the I2C hardware, but will not use the I2C bus. Then you can measure with a multimeter which signal is stuck to GND.

I am not really sure if I've tested this correctly:
I've connected the accelerometer and uploaded the code and then I checked the voltage between all the pins and ground:
All pins excluding SDA, SCL and VCC have a 0.83 voltage.
SDA and GND gives a 0.79 voltage
SCL and GND gives a 1.05 voltage
VCC and GND gives a 4.52 voltage

So I am not really sure how I should interpret this data.

Thank you for trying to help me!

If you are using a standard, high impedance voltmeter to measure those voltages, then something is wrong. The I2C lines should be both HIGH (about equal to Vcc) in the idle state.

You MUST have 2.2K to 4.7K pullup resistors from SDA and SCL to Vcc, which for the MPU6050 is 3.3V. The official Arduino Nano does not have pullup resistors.

Post a link to the product page for your sensor. If those resistors are not on your module, communications will not work. You could try using one of these level shifters as a go-between.

Better, use a 3.3V Arduino (with pullup resistors) to communicate with your sensor.

Your MPU-6050 could be broken.

Your MPU-6050 could be broken.

Yes, especially if you have exposed the module inputs to 5V.

SnipaSenpai:
I've tried this and I do get an 8 as output. So I guess my Arduino is fine.

That says that the I2C logic of the Arduino is probably good; but, what's about the physical connections among the MCU pins (27/SDA, 28/SCL) with A4/SDA and A5/SCL pins of the connector? Check the continuity using an AVO Meter.

The best would be to check the I2C bus functionality using two Arduinos.

jremington:
Yes, especially if you have exposed the module inputs to 5V.

I have been (often) playing with UNO and MPU6050 Module without any trouble. I think that the MPU6050 is 5V tolerant though the Module has an on-board 5V/3.3V regulator for the working voltage of the chip.

MPU6050.jpg

MPU6050.jpg

I think that the MPU6050 is 5V tolerant

No, it is not.

Vdd = (typically) 3.3V, and the data sheet states the absolute maximum input voltage level (for CLKIN, AUX_DA, AD0, FSYNC, INT, SCL, SDA) is -0.5V to Vdd + 0.5V.

A number of people on this forum have reported destroying their MPU6050 modules by connecting their inputs to 5V outputs.

jremington:
A number of people on this forum have reported destroying their MPU6050 modules by connecting their inputs to 5V outputs.

So for safe and reliable operation, we need suitable level sifters.