Issue with I2C Scan on Arduino UNO

Dear Community,

Attached you will find a well known code for an I2C-address scan. I run it on an Arduino UNO (2 years old).
The baud rate is set to 9600. Execution releases:

"I2C scanner ::: www.lucidarme.me
0 "

That is all. It seems that it has some problems to execute Wire.requestFrom(i, 1);
because the message “I am here” is not appearing in the serial monitor.
Meanwhile nothing at all is connected to the Arduino (apart from the USB cable).

I am using Arduino 1.6.5 IDE.
I tested the pins A4 and A5 as analogPins, by connecting them to GND and to Arduinos 3.3V. In both cases I could see some changes of the integer number (GND = 0; 3.3V ~ 650 )

I tested the sketch on a Mega2560 - runs perfectly through all the numbers of addresses!

What could be wrong with my UNO board?

Thanks in advance!

I2C_Scanner.ino (857 Bytes)

There are plenty others here - http://playground.arduino.cc/Main/I2cScanner
do they show the same issue?

I don't think your code is using the correct technique. You need to use Wire.beginTransmission to detect a device.
Try Nick Gammon's I2C scanner.

Pete

There’s nothing wrong with your board. The scanner sketch you posted does not contain Wire.begin().

 #include <Wire.h>
 
 
void setup() { 
 //Initialize serial and wait for port to open:
  Serial.begin(9600); 
 
  // prints title with ending line break 
  Serial.println("I2C scanner ::: www.lucidarme.me"); 

  Wire.begin(); //Add this line to the sketch
} 
 
 
void loop() 
{
  // Test each I2C address 
  for (int i=0;i<256;i++)
  {
    Serial.println(i);
    // Request data (read one byte)
    Wire.requestFrom(i, 1);
    Serial.println("I am here");
    // If slave answers, a device is found
    if (Wire.available())
    {
      // Display address
      Serial.print(i,DEC);
      Serial.print("\t0x");
      Serial.print(i,HEX);
      Serial.print("\t");    
      Serial.print("0b");
      Serial.print(i,BIN);
      Serial.print("\t");
      Serial.println("Device found");
    }
    Serial.println("Now I am here");
//    delay(100);
  }
  Serial.println("End of scan"); 
  while (1);
}

Hello!

Thanks a lot! I used the code from the post of robtillaart. And it worked on both UNCONNECTED devices (unconnected UNO and unconnected Mega). I added an

Serial.println(address);

in the for-loop to see at which address something happens.

BUT I have still a simillar confusing problem -

Now I am connecting the chain of my I2C devices - (2x ADC1114 and 2x MCP4725). The SDA and the SCL lines are well connected to all the devices. There is NO power on each chip, neither is something else connected to the UNO / Mega board. It's just the SDA line and the SCL line which are connected. (Since neither GND nor power is connected to the chips they should be dead... they are not powered or connected elsewhere!)

I do a similar test with the new code.
Mega-Board - runs through all addresses 1-126 and says nothing found. Perfect and as expected.

UNO-Board - stops at 1 and can not continue.

If I unplug either the pin A4 (SDA) or A5 (SCL) it can complete the run until 126 without problems (finding nothing as expected). It is not important which one of the two connections I am going to break, but if both SDA and SCL are connected to the unpowered device chain, it can not communicate.

What is internally different between the Mega and the UNO?