I2C between several Arduinos

Good morning I am pretty new user of Arduino and I am amazed by its potential... I started to work on a project where several Arduinos need to communicate (according to the picture attached). I was thinking to use an I2C bus for this and I was wondering if it can work with the first following questions in mind: - is the highest frequency (12 bits sent every 5 ms) manageable? - is it possible to address same data simultaneously to 2 Arduinos or do we have to duplicate the data with the 2 addresses ? - what happens if several devices want to “talk” at the same time? - do you recommended a better alternative than I2C? I hope my questions are not too stupid… Thanks a lot. Raoul.

I tested out your questions by hooking two Arduino Unos together.

  • is the highest frequency (12 bits sent every 5 ms) manageable?

According to my tests, you can send 16 bits, plus the address of the slave, in 0.3 ms. Thus you should easily achieve this.

  • is it possible to address same data simultaneously to 2 Arduinos or do we have to duplicate the data with the 2 addresses ?

Yes, however the library doesn't directly support it. The spec says that I2C has a "broadcast address" of device 0. Thus, if a master sends to slave 0, all slaves get the message. The library defaults to that disabled. In my test I enabled it by setting the low-order bit of the TWAR register. Omit that line if you want a slave to ignore broadcasts.

  • what happens if several devices want to “talk” at the same time?

This is permitted as the devices enter arbitration mode. Only one of them will win. You can check the return code from Wire.endTransmission to see if you got a non-zero response. If so, you could retry after a short delay.

  • do you recommended a better alternative than I2C?

I think I2C will fit your requirements.

An image from the logic analayzer shows the timings involved. More details (source code, timing images) are in a post I made here:

http://www.gammon.com.au/forum/?id=10896

Thank you a lot Nick, the results you provided are promising. I will have to check if the Arduinos can manage the "communications" and their own task as well, but at helicopter view it seems feasible. Thank you again for spending time to support. Regards. Raoul.

One additional question: is the checking of the return code included in the timing you provided?

Well, no. The timings don’t include the time taken to gather or process the data, however I assume that would be minor compared to sending from one Arduino to another. As an example I added this code:

 volatile int x;
 
  for (int i = 0; i < 1000; i++)
   x = 3 ;

So that is doing another 1000 things (assigning a value, plus the looping itself). This added about 0.7 ms to the time between transmissions. So a simple check for the return code would be minor by comparison. You will eventually hit a limit, but you know better than me what you are trying to do between transmissions.

Nick Thank you again. Iwill do my own assessment based on the figures you provided. Raoul.