Arduino I2C Issue

I have 2 Unos and 1 Mega. I have connected 1 Uno (the good one) to the Mega via I2C and uploaded a sketch which reads/writes between the Uno and Mega. This works just fine with no issues. I then swap the Uno (the bad one), swap the wires to connect the Mega to the bad Uno, and upload the same Uno sketch. When I do this my library gets stuck in Wire.endTransmission();

It seem to me there is something physically wrong with my 2nd Uno. I am able to send/receive serial commands if I upload a sketch to do just that but I just can't get passed Wire.endTransmission(); Any ideas on what to do? Should I just send it back and get a new Uno? Or is there something else I can try?

Clearly, there is something wrong with the second UNO. (or clone-o as the case may be) Try running this I2C scanner program with nothing attached to the UNO . It is likely to hang up and not report "Done".

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

If the scanner program hangs with no I2C device attached, there is likely a short between A4 and A5 or between one of those pins and ground. You may find an obvious defect on the board. If the processor is socketed, you can remove it and use a multimeter to see if the defect is on the board.

With a surface mount 328 and no obvious defects on the board you are most likely looking at sending the UNO back for a new one.

Thanks for the help. The bad Uno has a few hundred ohms between SDA, SCL, and GND where the good Uno has at least 8 megaohms between any two of those points. I then ran the code you posted and as expected the good one worked and the bad one hung.

I purchased both of the devices from the same retailer (Mouser) though at different times. Using IDE 1.6.1 the bad one does say 'Uncertified' while the good one does not.

Anyway, thanks again for the help.

Just a quick update. I have 4 Mega 2560s and 2 Unos. Out of the 6 Arduinos 2 of them have some sort of resistance issue on the I2C lines. Is this common or just bad luck?

Just bad luck. Inspect the soldering around the SCL/SDA pins, the A4/A4 pins, and pins 27/28 on the '328 chip. If can't see any thing obvious, remove the '328P chip and measure again - maybe you'll be able to determine if the problem is with the chip itself or with the board that way.

I think the Mega have onboard I2C pullup resistors, so measurements there are a little trickier.

I pulled the 328P chip and I got an open between SCL and SDA. Seems like the chip is the problem, at least on the uno. Good to know for next time. Thanks.