The basis of the project was to utilize Inter-Integrated Circuit (I2C) protocol to send lighting animation commands from a central master board to various slave boards. Here is our schematic of the lighting display.
In a broad description, I2C protocol allows for a master board to communicate to slaves in the form of read and write requests. Each slave can be assigned a unique address, allowing for the master to specify destinations for its commands. This protocol requires the use of inbuilt hardware, specifically the Twin Wire Interface (TWI) module on the atmel328p, to operate.
The above figure and following paragraph describes an ideal master to slave write transmission. First the master would send a start command onto the data bus. Each slave on the bus then automatically acknowledges the master with an acknowledge bit. Then the master loads a slave address into the TWI data register and then sends that onto the data line. If a slave has an address that matches, that slave sends an acknowledge bit. Then the master would load a data byte into the TWI data register, followed by send that byte onto the data bus. This data is then loaded by the target slave into it’s own TWI data register. The master then can repeatedly send data bytes to same address, send another start command to specify a new slave address, or send a stop command to relinquish control of the data bus.
Being able to utilize I2C protocol can be extremely powerful in the right circumstances. Certain sensors rely on I2C protocol. And given that a single bus can support up to 127 slave address, you could connect that many boards/chips/sensors, greatly expanding the capabilities of the chip utilizing only two pins. It also is able to support multiple masters on a single data bus. Finally, the communication requires little resources from the slave board especially during a master to slave write demonstrated above.
I2C does have its drawbacks. It is meant for communication between chips on the same board. Trying to communicate on a data bus longer than 2-3 feet results in misreads. The protocol does have an in-depth description within the data sheet, but when trying to implement we faced a lot of issues with the slave not sending acknowledgement bits.
If you want to learn more about how to implement I2C in your project, first check out a tutorial to wrap your head around the protocol. Then consult the documentation for your board to gain a specific understanding of I2C protocol for your board. It should be located under Twin Wire Interface (TWI). Your micro controller may even have multiple TWI modules, like the atmel328pb. Then I would recommend checking out this library to help with implementing your own I2C functions.