Will there ever be a SoftI2C Library?

Since there is a soft serial, is there any plans for softI2C?
How difficult/important is it to bit bang the I2C protocol? I have seen applications where it is needed, eg. to utilize 2 wiimotes, where changing the address is difficult. I have a few other applications but I was wondering if it is the community's list of priorities.

Hm.. i am not quite sure about this, but have you ever looked into the twi.c? as far as i understand it there the pins for the twowire protocol are defined, maybe by copying the library and doing the neccessary changes one could add a second or maybe a third i2c portpair to the arduino.. but i am more than unsure about it...
also i stumbled upon a library (http://jump.to/fleury) for I2C on an Atmel.. maybe this may help you about this whole subject.

twi.c and Peter Fleury's library both use the hardware module. I'm currently trying to sniff some i2c traffic, and was planning on writing a softi2c kind of library when I got a chance.

OK I am Interested in writing the softI2C, I would would liek to know who assisted in the actual I2C or anyone who has knowledge to help me bit bang it. People with Soft Serial knowledge would also be great. Any takers?

The atmega168 datasheet has a pretty good explanation of the physical protocol. I have my sniffer working, but it uses the hardware SPI module and an INT pin - not exactly SoftI2C.

Do you just need master mode, or will the Arduino be addressed as a slave too?

This is an app note and project source from Atmel on how to implement software i2c in assembly.


take it for what its worth

Do you need I2C master or slave in software?
What devices must this software-I2C-lib talk to?

I guess that a TWI master is very easy, simply create the START condition with two pins, then use shiftOut(dataPin, clockPin, bitOrder, value) to write the 7bit address and r/w bit, followed by 8bit data and then create the STOP condition on the two pins...

Receiving data is another topic.

There's a TWI bit-banging master in my Ports library, at:
Look in Ports.h and Ports.cpp for the PortI2C and DeviceI2C classes (you can define multiple devices on one Port).

The PortsBMP085.* files contain an example of their use as described here:

Not sure it's of any use, but feel free to use/re-use/alter as you like.


I don't know what exact features you need, but I posted a modified i2c (master) library here, which might be easier to hack. It still uses the hardware i2c module though :

My purpose for soft I2c is actually just master, I am building a robotics kit that may use multiple sensors with similar non-modifiable i2c addresses. In fact it is the Lego Mindstorms NXT robotics kit sensors - primarily the Ultrasonic sensor for now. So hopefully this I2C master should do the trick!
Having a slave would be pretty interesting as to the capabilities i would be able to do hmmmm - chain robots - communicating over I2C :stuck_out_tongue:

FWIW, the links in my March post have changed to:

(so much for trying to maintain valid links all over the web...)