I2C - how does that work?

I can't wrap my head around how I2C works with Arduino. I was checking examples and tutorials where two Arduinos are connected using I2C and analog 4 and 5 are connected, as well as ground, like here:

Reading multiple tutorials I don't doubt that it works yet it seems to defy logic to connect two analog inputs. How on Earth can anyone send bytes over two connected inputs??? How does the master send anything over an analog input? Thank you for your answers in advance!

alkopop79:
I can't wrap my head around how I2C works with Arduino. I was checking examples and tutorials where two Arduinos are connected using I2C and analog 4 and 5 are connected, as well as ground, like here:

http://arduino.cc/en/Tutorial/MasterWriter

Reading multiple tutorials I don't doubt that it works yet it seems to defy logic to connect two analog inputs.

Don't confuse the primary use of a given arduino pin to it's possible secondary uses. When the I2C hardware controller inside the AVR 328p chip gets activated by the proper software commands, those analog input pins 4 and 5 are no longer analog input pins, but rather become the 2 I2C clock and data signals. Most arduino I/O pins have more then one purpose, such as pins 0 and 1 being hardware serial pins, if not being used as simple digital input or output pins. Even the analog input pins can be use as digital input or digital output pins if desired.

How on Earth can anyone send bytes over two connected inputs??? How does the master send anything over an analog input? Thank you for your answers in advance!

Once those two pins are turned into I2C clock and data signals, they are no longer analog input pins. And the way I2C communications works, the single I2C data pin can be both an input pin to receive data or an output data to send data, it's said to be a bidirectional signal pin. You really don't have to understand it down to the gory details to utilize I2C modules with your arduino. It's main advantage is that it can be wired to up to 127 external I2C modules/devices/chips and sharing those same to I2C control signal pins, as each device has a unique I2C hardware address that allows the master I2C device (usually the arduino) to manage all those devices without conflicts.
Lefty

... it seems to defy logic to connect two analog inputs ...

When I2C is activated it "takes over" those pins for the I2C functions.

Thank you very much! Now it all makes sense. So much to learn...

When in doubt, read the Data sheet!

// Per.

Hello,

On my quest to find the right way to write a code for I2C i found your post.

I'm a begginer and i just want to write a simple code just to read the data from a sensor which only uses I2C
so at the end i can get e.g.

Serial.println(sensordata);

I see that you guys have a complete comprehension on that topic that's why i post here instead of opening a new post that might have already been opened.

Thank you in advance.

With respect,

Minas