Running 2 i2c instances simaltaneusly

Hello! Does anybody know if it's possible to run two I2C instances with the Arduino and Wire.h simultaneously?

It may sound stupid, but once I get some i2c Eeprom, I want to try to run the (i2c) Wii Nunchuck and 12c Eeprom for datalogging.

Thanks!

I2C supports multiple devices on a single line as long as each has it's unique address.

Don't know much about the numchuck, but for example you can hang 2 EEPROMS off of a single I2C. It's like a network for chips.

Thanks! I guess I'll just have to wait for my eeprom to come to test it out.

Do you mean that both the i2c thingies work on the wire library default, analog 4 and 5, or can you use analog pins, say, 1 and 2?

If they both double up on the same pins, how does it work?

If you can use other analog pins besides 4 and 5, how do you program that? From what I've seen in examples, they all use, as default, analog 4 and 5.

The SDA and SCL (A4 + A5) plus common GND (and you might as well use a common +) can have up to 121 i2c devices on the same bus (SDA SCL), so long as they all have different addresses.

So you don't need extra pins, just keep adding devices to SDA, SCL and GND. Then use the wire library code examples to talk to each device :slight_smile:

Whoa, I made a lot of misspellings on my first post. Ah well.

Anyway, thanks! That's actually really cool. Is the programming any different for doubling up on the same pin?

Also, how can you find the address?

The example from the Arduino wiki about i2c eeprom says, (Arduino Playground - HomePage) just says: Wire.beginTransmission(deviceaddress);

while others say things like: Wire.beginTransmission (0x52);

The address will be found in the data sheet of the device. Sometimes their are some pins that allow you to customise a small portion of the address (normally 3 bits)

Some devices also allow you to change the address over I2C, as well.

For example, the HMC6343 tilt-compensated compass from Honeywell stores its I2C slave address in EEPROM (at location0x00, default 0x32). Since it provides a write to EEPROM command, you can change the default if you should want two of these things on the same net.

Not that I have ever had a reason to do this. :slight_smile:

Sorry to resurrect a long dead thread, but similar desires. Aware of the multiple devices with different address's, but have a situation where I have two slaves with identical address's that I can't change that I need to communicate with simultaenously (they are both 0x52).

What is the best approach ? mux the SDA line somehow, or can I bit-bang I2C on another set of pins (without reinventing the wheel? )

Seems like you are stuck bit banging I2C of a different set of pins... to me.

@Pwillard, are you saying that you can't multiplex the I2C SDA line?
I would guess that you could switch the i2c lines using something like a cd4052 multiplexer/de-multiplexer. I wonder if someone has tried this with Arduino.

@pwillard: that was my first thought too when struck with the problem, but it seems such a waste... plus, it means I'll spend the next week trying to bludgeon someones code into working :wink: (since I will be relying on the age old method of "find and reengineer" to get it to work :wink: )

@mem: heh - I was out at the local chip-pimp yesterday, thought about getting a 4052 and then thought I already had enough to play with. Bugger!

So in theory, sticking that on the two devices SDA lines and then just pining SDL to the bus as usual should allow me to "Read/Shift/Read" to harvest the two sets of data from both I2C devices?

Not that this is probably relevant, but I'm trying to get both a Wii Nunchuck and a Wii MotionPlus working - the problem is the MP switches to the same slave address as the Nunchuck..(0x52) so I really need to mux it properly so I can init both devices and then just switch their 'RX' pins so to speak.... this will give me a cheap and nasty IMU suitable for the purposes I want :wink:

@Adr1an, I figured that is what you wanted to do. This thread caught my eye because I plan on doing something similar when I get hold of a MotionPlus.

I would think you could use the 4052 to connect either the nunchuck or the MotionPlus to the I2C pins. I expect that both would need to have the pull-up resistors remain connected all the time. As long as the switching was done before any read or write I would think it would work. Perhaps next time you see your pimp you can pick up an analog switch and give it a try.

My next post will contain a link to a solution to your question.

Check out:
www.wiimoteproject.com/tech-chat/2-nunchuck-with-arduino-help/

Got solution for 2 simultaneous nunchucks.
Sorry for the broken post but I guess I'm too noob to post links :slight_smile:

@eastons: Yes mate, thanks - I've seen that one. I can't recall specifically, but besides the Mosfets being a pain to source locally (dont ask... >:( ) there was some issues/limitations with the setup that I actually can't think of right now (so maybe they weren't so major anyway....). Plus, the 4052, if it works, cost me $1.25 (in Australian Peso's ;D , so that'd be about $US0.75, or $EU0.60... )

@mem: Picked up a 4052 today, will have a play and let you know if it works.

The post from eastons made me realize that only the SDA line needs to be switched. The CLK lines can go to both i2c devices. So you only need to connect the two SDA lines to the 4052 .

Looking forward to reading about how you get on.

BTW, I would think the circuit in eastons link would work with BJT transistors. If so, that solution may be cheaper.

What you need is an I2C address spoofer. :smiley:

It has an SCL pass-through and an SDA in and an SDA out. A register inside holds the address of the device that has duplicate addresses and the spoofer itself has A0-A3 sub-address pins and a base address that puts it out of the way of most things. Then it's a simple matter for the spoofer to insert the register address at the correct time and pass the other data through unchanged when it's appropriate.

:sunglasses: :sunglasses: :sunglasses:

What you need is an I2C address spoofer.

Got a part number?

We keep ours in the cabinet next to the cable stretchers and spare bit buckets. :slight_smile:

-j

I can never remember that number but mine are in the same drawer with the round tuits. :wink: