How to receive data from two slave arduino to master arduino

I asked this question in other topic at end, but so far no one gives me idea.

I would like to get data that two slaves that will send similar data except two separate Adddress by I2C.

If I use Wire.onRecive, It will mix data by few seconds and get freeze. How can I collect them for per each address?

onRequest and onReceive works only one set arn’t they?

maybe a drawing to clarify your question ?

Or some translation of :

It will mix data by few seconds and get freeze. How can I collect them for per each address

I’ve tried to get multiple arduinos to communicate before too. It’s is a surprisingly small area of “research” There isn’t a lot of data on it. (wasn’t when I was working on it in 2010-11) I had seen code that will get a led to blink connected to a separate arduino, but wasn’t able to get similar results or pass multiple values back and forth.

I think the problem the OP is running into is that when the master requests data from the slaves, both respond at the same time. Everything gets jumbled and things freeze up. Frankly just have a single reply is farther than I ever got. To solve the simultaneous responses I think the slaves need to be addressed 1 and 2. The master needs to call each individually. IIRC this is how multiple ICs communicate using I2C. I’d love to see basic code for both the master and slave.

Good luck, I will be following this as I’d like to take this project up again in the near future.

/*
*  
*  | ......................................      |
*  | ----------       ------------------         |
*  ||            |--- |                    |-----|------|
*  || sensor     |    | mini arduino       |     |      |
*  ||            |--- |                    |-----|--- | |
*  | ----------       ------------------              | |
*  | ......................................      |    | |
*                                                     | |
*                                      
*  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
*  |.......................................| 
*  |.......................................|  
*  |.......................................|
*  |   same module                         | 
*  |.......................................|
*  |.......................................| 
*  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
*                                     
*                   
*  ---------------------  
*  |..................  |
*  | Master arduino     |  
*  |..................  |
*  ---------------------
*/

I hope you get idea. Resitors are not drawn, but there.

Sensors cannot be physically secured.

Two module are exactly same. Idea is pick any of two modules and plug to I2C bus and ready. (and remove)

Becasue that, I added mini arduino to take care offset adjustment for the sensor and also added address selector to differ eachother when hooked.

I learned onReceive and it works fine if I connect only one module, but not two. (which understandable)

I am looking for the way collect data alternatly between two. I just started play with arduino. Appreciate it for guidance.

Thanks

You cannot have asynchronous slaves on the I2C bus. On that bus the master is in control. The master must ask each slave for its data. You would therefore poll your sensor slaves in a “round robin” fashion. The slaves might respond with “I have no data right now” in which case the master will move on to the next. There is no way on the I2C bus to set up the master to just listen for whoever speaks up next.

  • Chip