I have 4 UNOs and 1 Mega2560 in an I2C bus. I setup 20x4 and 16x4 I2C LCD displays
1.) Master to Slave: I send an x value 1 to 6 to the 5 devices.
Slave 1: LED 13 on x = 1
Slave 2: LED 13 on x = 2
2560 : LED 13 on x = 3
Slave 3 LED 13 on x = 4
Slave 4: LED 13 on x = 5
All LED 13 on x = 6, x resets to 0. It has a 7 segment LED with SN74HC595 to display 1-6
What I want to do next
2.) Slave to Master
I want to put a photo resistor on each slave. Setup a 4 x 2 array, First column the slave number, second column A0 reading 0 to 1000. Send it to the master that can display each one on the 16x2 I2C LCD.
I have been reading Ardiuno books and can't find much on I2C. It is possible to send and receive on the I2C bus?
It is possible to send and receive on the I2C bus?
From reading your description at stage (1), I can't quite figure if there is a 6th device that is the "master" on the I2C bus sending messages to each of the 5 slaves to get them to turn on/off their LED's.
The I2C bus can be a multi-master bus but I think it will just add a level of complication to your project that isn't needed. You already write to each slave device over the I2C bus, so why not add in messages to request the value from the photo resistor?
Every Arduino board in I2C Slave mode can be a Master as well. However, a multi-master bus is a fairy tale (just my opinion).
The Master could send a command to a Slave that it has 1 second to send data. That is bound to go wrong.
A good solution is the Master polling the Slaves a few times per second for new data. Your I2C bus should be 100% reliable anyway, so why not use it.
It is possible to add a 'interrupt' wire to the I2C bus. Then a Slave can signal the Master that it has new data.
There are strict rules to make the onReceive and onRequest handlers for the Slave (no delay, no Serial functions). Most will fail there. Can you use Serial RX/TX communication between the Arduino boards ?
The best solution is to use a single Arduino board for your project. With millis() it is possible to do multiple things at the same time. If there is a possibility that you can do you project with just one Arduino board, then you should do that.
Yes, there is an old protocol called token passing. On a local area network, token passing is a channel access method where a signal called a token is passed between nodes to authorize that node to communicate. In contrast to polling access methods, there is no predefined "master" node. If nobody has the token anybody can create it but that needs to be properly defined.
That is a problem. This is not a network, this is about the I2C bus. That properly defining with the I2C bus is not going to work. You can spend a year trying to make it, and I will spot a problem in your code in 5 minutes.