Multiple I2C busses?

The Wire library for I2C uses analog pins 4 and 5. Is it possible somehow to initialize a second I2C bus using other pins, and have both connected and usable, with the Ard as master on both?

As to why you would want to do something so silly -- my current project looks to have some rather long cable runs and splitting it in two runs with the Ard in the middle would lessen any problems with I2C bus length.

Looking at the wire library (and the twi library it wraps), it appears that I2C is "fixed" at a hardware level on the ATMega to PORTC pins 4/5 (for the ATMega 8/168/328 - for others, it appears to use PORTD pins 0/1?).

I don't think it is possible to change it.

If you are having such difficulties with long runs, though, you might try an I2C buffer IC...? I don't know much about all of this, though, so I can't recommend any particular one; maybe someone else can?

:slight_smile:

A software Master (!) i2c is feasible, in fact even simple, as i2c is clocked and you can reduce your bitrate downto the 50k or whatever is possible with digitalWrite(). I did that for the Propeller 2 years ago; the code is not portable, but can be adapted....
It is more difficult for Slaves as you have to adapt to the possibly 400kHz clock, as clock stretching is rarely honored....

Hi,

As to why you would want to do something so silly -- my current project looks to have some rather long cable runs and splitting it in two runs with the Ard in the middle would lessen any problems with I2C bus length.

There is no need (electrically) that the I2C-Master has to be connected to the end of a cable.

Arduino-- Slave1 ---  Slave2 --- Slave3 --- Slave4
Slave1 ---  Slave2 --- Slave3 --- Arduino --- Slave4
Slave1 ---  Arduino --- Slave2 --- Slave3 --- Slave4

Each wiring scheme will work. Order doesn't matter on the I²C bus

Eberhard

To jump into the topic -- I'm wondering where I can get a cheap I2C multiplexer/switch in the form of a breakout board or at least in the DIP package for breadboard use?

All I'm googling/ebaying/amazoning up is basically a bulk order possibility from the manufacturers, and only a handful of affordable single-order possibilities on eBay -- but only as surface-mount devices. I seem to be at a dead end when it comes to simple, hobbyist-friendly breakout boards for use in my projects and breadboards...

I have 6 I2C devices and only 4 possible addresses. Any other solutions other than finally getting up off my lazy ass, earning to solder SMDs and making my own breakout boards?

TI has the "PCA9546A 4-CHANNEL I2C AND SMBus SWITCH WITH RESET FUNCTION" that seems to be purpose0built for your problem.

It's surface mount only, though.

If your soldering iron skills, soldering iron, and solder are decent you could solder one of these bad boys to a breakout board.

-j

I'm wondering where I can get a cheap I2C multiplexer/switch

Close to any AVR mcu should do. Atmega328P being one candidate you already know of. :wink:

Thanks, kg4wsv (speaking of user-friendly... you might wanna pick an easier handle ;D).

Found it on eBay as well, if someone is also looking for it... http://goo.gl/Jx9s.

I also found this helpful bugger to help with breadboarding the initial prototypes: http://goo.gl/qWZ4. Should be good enough for experimenting on the breadboard until my soldering gets good enough to surface-mount the sucker right into the finished prototype. :slight_smile:

Thanks!

I'm wondering where I can get a cheap I2C multiplexer/switch

Close to any AVR mcu should do. Atmega328P being one candidate you already know of. :wink:

;D Indeed... However, I'm a bit confused as to where you're going with this...

Meaning, I should:

a) use another Arduino to get another I2C bus? Brute force, I like it! :smiley:
b) somehow software-switch the devices as deSilva suggested? (didn't look into that one yet, will do)
c) other?

Anyway, the switch/multiplexer is already in the mail, so I'll give it a go the hardware way. :slight_smile:

However, I'm a bit confused as to where you're going with this...

When in the market for a special purpose IC (and not finding one), there is always the possibility to build this "IC" yourself from an mcu. An additional AtMega + a small program would give you a second I2C bus. When using an AtMega328P you could interface this second AtMega to your Arduino as an SPI or Serial device.

(speaking of user-friendly... you might wanna pick an easier handle ).

:slight_smile: At least it's unique.

Found it on eBay as well

hint: samples.

I also found this helpful bugger to help with breadboarding the initial prototypes: http://goo.gl/qWZ4.

Holy cow, that is cheap! If the quality is good enough, that's a real steal. Most of those I've found are more like US$100.

-j

However, I'm a bit confused as to where you're going with this...

When in the market for a special purpose IC (and not finding one), there is always the possibility to build this "IC" yourself from an mcu. An additional AtMega + a small program would give you a second I2C bus. When using an AtMega328P you could interface this second AtMega to your Arduino as an SPI or Serial device.

Wow. That's so elegant it hurts.

Do you know of any examples I could check out in the playground section or elsewhere (for any type of IC replacement -- I'm feeling exploratory)?

I also found this helpful bugger to help with breadboarding the initial prototypes: http://goo.gl/qWZ4.

Holy cow, that is cheap! If the quality is good enough, that's a real steal. Most of those I've found are more like US$100.

Yup, quite cheap! There's a lot of them in this price range on eBay. I'll let you know about the quality when I get it, and post some detailed pics!

hint: samples.

Good point.