SoftI2CMaster Library Lets You Add I2C To Any Arduino Pin
[TodBot] shares his latest knoledge about I2C:
Ever wanted to use any pair of pins for I2C on Arduino, not just the dedicated pins on Analog 4 & 5? Me too, so I made a quick little Arduino library called “SoftI2CMaster”, available in the “blinkm-projects” Googlecode repository.
Get it here: SoftI2CMaster.h, SoftI2CMaster.cpp.
It’s still a work in progress, but it can write data pretty successfully and do it over longer cables than normal.
For the VIMBY/Scion Hackerspace Challenge, I created an array of BlinkM MaxM-powered accent lights for the device we made. Because the I2C cable was longer than a few feet, the normal Wire library that BlinkM_funcs.h uses to communicate with BlinkMs couldn’t be used. This is because the Wire library assumes a perfect bus. If there is any noise or other bus problems, the Wire library will currently lock up. For the SoftI2CMaster library, I wanted it to be very tolerant, even lazy, about bus problems and also have more tunable timing to let you slow the bus down. Of course, you still need pull-up resistors on the two lines. I’ve found using 2.2k resistors to be good.
We totally have to give it a try!
via [Todbot]
October 1st, 2010 at 10:45:38
I feel this may be very useful to me in the next few months. Things like this always seem to appear at the right 🙂
October 1st, 2010 at 11:46:33
I created something similar a couple months ago. I kept the API as close to the stock hardware TWI interface so that you can switch it in and out (only two initialization lines have to change). Right now I’m using it to communicate with a SparkFun compass and 6DOF IMU.
http://code.google.com/p/fivevolt/source/browse/Quadcopter/Arduino/Telemetry/SoftTWI.cpp
http://code.google.com/p/fivevolt/source/browse/Quadcopter/Arduino/Telemetry/SoftTWI.h
October 4th, 2010 at 18:43:09
Thank you for this great contribution. Wouldn’t it be possible to fix the original Wire library to be as robust as this one?
October 8th, 2010 at 11:24:18
Thanx for sharing this lib. Can it be used create an I2C Slave from an Arduino board?
Tia,
Rob
November 4th, 2010 at 07:00:19
nice work, tod!
i cannot wait to try it out.
January 26th, 2015 at 23:20:52
Joe Ferner, I’m trying to add more I2C ports on Arduino Uno.
I’m trying to use SoftI2C, but I don’t understand how it works to send and receive data.
Do you have another way to add more I2C ports on Arduino UNO?
My e-mail: nyckmaia@gmail.com
Thanks,
Nyck
July 5th, 2015 at 19:08:17
Davide, Thanks for the code! Do you have any example sketches that will help get me started? I want to add a second I2C device (BMP180) to my Arduino UNO using a soft I2C library (such as yours). Another contributor provided a library to the open source community, but it didn’t work for me. Thanks in advance!