I2C using digital IO lines for SDA and SCL ?

In my project, I am running out of Analog In pins... and I still need to use 2 of them for an I2C device...

Is it possible (is there an available library?) to use digital IO lines for SDA and SCL? Why Analog in ports are usually used? Why not digital ports?

Thanks

Why Analog in ports are usually used? Why not digital ports?

Because generally people run out of digital pins before they run out of analog pins.

It's not that I2C generally uses analog pins. I2C always uses analog pins.

Thanks.
How difficult would be if I want to use digital lines?
Is it only a matter of modifying the original Wires library to manipulate digital lines instead of the ADC4/5 ports?

It might be easier to use an analog multiplexer chip or an external A/D chip.

How difficult would be if I want to use digital lines?
Is it only a matter of modifying the original Wires library to manipulate digital lines instead of the ADC4/5 ports?

http://arduino.cc/en/Main/ArduinoBoardUno

The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and the analogReference() function. Additionally, some pins have specialized functionality:

  • I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library.

Better get the soldering iron ready, too.

The ATmega's on-board I2C controller is hard wired to pins 4 and 5. This isn't an Arduino limitation. It is a ATmega trade-off.

You might be able to find (or write) a software-based I2C implementation to use different pins, but it will likely have some pretty significant trade-offs.

In my opinion, the multiplexer on the ATmega's A/D isn't all that good. Most of the trouble people have with the analog inputs are related to the built-in multiplexer. If you need more than one analog input, you might look at an external multiplexer or A/D.

There are plenty of I2C based ones on the market. :wink:

One could also use a "softI2C" library like on this page - http://www.misenso.com/prototyping/two-sht21-softi2c-arduino/76/

I just the ATmega328P manual and, as already commented, the SDA and SCL functions are tied to the pins corresponding to ADC4 and ADC5. Therefore, it is not only a matter of making a change at the current Wires library: there is a physical constraint.

However, it does not that it is not possible to create a new library, but it would be extremely time-consuming to develop all the TWI stuff from the scratch.

I will have to deal with my problem in a different direction.

Thanks for all the replies.