Go Down

Topic: Mega I2C Not Working (Read 1 time) previous topic - next topic


When i run the i2c scanner code:
Code: [Select]
// --------------------------------------
// 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
//    http://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.
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.

#include <Wire.h>

void setup()

  Serial.println("\nI2C Scanner");

void loop()
  byte error, address;
  int nDevices;


  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.
    error = Wire.endTransmission();

    if (error == 0)
      Serial.print("I2C device found at address 0x");
      if (address<16)
      Serial.println("  !");

    else if (error==4)
      Serial.print("Unknow error at address 0x");
      if (address<16)
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");

  delay(5000);           // wait 5 seconds for next scan

Whether i have connected my device (MPU6050) or not i get the same output
Code: [Select]

I2C Scanner

and this stays as it is without changing or updating at all...

Pl. help, is my mega faulty???


Jun 12, 2015, 04:12 pm Last Edit: Jun 12, 2015, 04:12 pm by Peter_n
If it is connected properly, it should be detected.
The MPU-6050 is a 3.3V sensor with 3.3V I2C bus.
The Arduino Mega has a 5V I2C bus.
Did you use level shifting to connect the 3.3V I2C bus to the 5V I2C bus ?


i have the exactly same model as shown

also if nothing is connected it should at least return an error or no device connected message with does not happen.


Jun 12, 2015, 04:41 pm Last Edit: Jun 12, 2015, 04:47 pm by Peter_n
Yes, of course, you are right.
The sketch is halted. That means that the I2C hardware has a problem. Perhaps SDA or SCL is connected to GND or SDA is shortcut to SCL.

This also happens when nothing is connected ?
Check the Mega board with a magnifier, or use a multimeter to measure the SDA and SCL. There might be a solder blob or very thin copper trace that shortcuts something.

That MPU-6050 module has a 3.3V voltage regulator but no level shifting.
I think it is better to use a level shifter for SDA and SCL.

If you are willing to risk to damage the MPU-6050, you can connect 5V to VCC, and the rest as in the example on that page. The 5V is needed because then the voltage regulator on the sensor module gets 5V as input, which is better to make 3.3V for the MPU-6050. The 5V I2C bus from the Mega might damage the MPU-6050, because it pushes current into SDA and SCL.

Do you have an Arduino Uno, or an other I2C sensor ?.


Sda and scl are completely shorted :( i could not find a blob or a trace, I'll be giving it for replacement... (Sigh).


The SDA and SCL from the chip go in two directions. To pin 20,21 and to pin SDA,SCL near the USB connector (if you have a 'R3' version). Perhaps there is something under the black header ?

I can follow them on the photo (click on the photo for a larger version) : http://www.arduino.cc/en/Main/ArduinoBoardMega2560
This is the pinmapping (they are the bottom side) http://www.arduino.cc/en/Hacking/PinMapping2560

If it is an official Arduino Mega 2560, you should return it.
If you bought a cheap clone, there might be a design fault, and a new board could have the same trouble.

Go Up