How to get two Arduinos to access one I2C device?

What must I do to to get two Arduinos to access the same I2C device? If necessary I have enough free I/O pins to create a traffic cop function so the Arduinos don't interrupt each other.

Is it necessary to have one Arduino as a master and the other as a slave? I don't need them to communicate to each other.

Thanks
Mike

You could use some kind of device reservation system. Use two pins on the Arduinos which you cross-connect to each other. The Arduino that wants access to the device looks for the reservation input pin. If it's LOW it puts it's reservation output pin to HIGH and check the input pin again. If it's still LOW it can use the I2C bus. Else it sets it's output pin LOW and waits for a random (!) time (some ms) to try the same again.

When one of the Arduinos is not actively using the I2C it's SDA and SCL pins must be configured as inputs. Keep in mind to install the pull-ups (3k3) only once for the whole bus.

it's SDA and SCL pins must be configured as inputs

I think he's safe there as the pins are OC and will not be driven at the same time if the handshaking works.


Rob

The two extra pins on each Arduino cross connected was my minimum plan.

Is the I2C bus protocol smart enough not to transmit if the bus is in use?

I assume it is advisable to have each Arduino with their own unique address.

Thanks
Mike

Is the I2C bus protocol smart enough not to transmit if the bus is in use?

No, but you are. Write the code so clashes don't occur.

I assume it is advisable to have each Arduino with their own unique address.

Your Arduinos are masters are they not? As such they don't need an address.


Rob

I2C is smart enough not to transmit if the bus is in use. It's called bus arbitration and the losing master will kick back an error to the calling application.

Still a good idea to employ a negotiation system if you don't want to leave things to chance.

Yes I'd forgotten about multi-master, and the AVR hardware supports it IIRC.


Rob

Great! Thanks for the input. I should be good to go...

Mike