bidirectional communication by I2C

Hello,

I just start to set up automation of my house by Arduino.

The idea is to have one main controler Arduino that sends data to Mysqldatabase on internet.
This part works fine already.
And having local controlers that control one process, for example heating system.

But I wonder how to use I2C for communication :

actually I use MasterReader/Slave writer, to collect measurement data from each local controler to sent it by I2C to main controler (that will sent it to internet).

But how can I sent data from main controler back to local controler (for example a start or stop order for heating system comming from a control pannel)?

Is it possible to mix up MasterReader/SlaveWriter and MasterWriter/SlaveReader with same I2C Communication ?

Thanks for your ideas

Armin

I2C has one master and may have several slaves. The master requests everything, so he may write to the slaves or request data from them. If you want to send data from the slaves to the master, the master has to poll for the information.

Theoretically it's possible to have multiple master on one I2C bus but I don't know of any such setup that works reliably, so I strongly recommend against that. The Arduino standard library for I2C doesn't support multimaster either.

Please keep in mind that the maximum wire length for an I2C bus is about half a meter, so it's definitely not the ideal solution for a home automation system. You should consider RS-485 as an alternative that doesn't have the same restrictions.

Thanks a lot, I tested to use MasterWriter and MasterReader with same Arduino, it works fine.

For line length, I found line booster modules to extend to 300m.

Is RS-485 a better/cheaper solution ?

best regards

Armin

emailarmin:
Is RS-485 a better/cheaper solution ?

best regards

Check the price of RS485 modules on eBay and compare it the price of the I2C line booster you were looking at.

I don't know if this is a good fit for your problem, but I use I2C_Anything library to send data bidirectionally between slave and master Arduinos on an I2C bus.

Basically, all participating Arduinos define the identical data structure in their sketch (and I think the size of this struct is limited to 32 bytes or something small like that, but you could always define multiple structs). The master controls the timing, of course. The master can send the struct to a slave, and can command the slave to send the struct back again.

But the slave can modify selected items in the struct before sending it back. So the slave and master can communicate bidirectionally: the slave could send sensor values to the master, for example, and the master could send user-settable parameters to the slave(s).

So you could make a struct containing, say, 4 floats; the master might write one, and the slave might write 3. Or the master might write nothing to one slave, and just tell the slave always to send, while writing instructions to another slave and getting data back... This mechanism is central to my 2-Leonardo USB controller & has been pretty solid.