The basis of the project was to utilize Inter-Integrated Circuit (I2C) protocol to send lighting animation commands from a central control board to other boards. Here is our schematic of the lighting display.
In a broad description, I2C protocol allows for a master board to communicate to other boards in the form of read and write requests. Each of these boards 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 board on the bus then automatically acknowledges the master with an acknowledge bit. Then the master loads one of the boards’ address into the TWI data register and then sends that onto the data line. If a board has an address that matches, that board sends an acknowledge bit. Then the master would load a data byte into the TWI data register, followed by sending that byte onto the data bus. This data is then loaded by the target board into its own TWI data register. The master then can repeatedly send data bytes to same address, send another start command to specify a new board 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 boards, you could connect that many chips or sensors, greatly expanding the capabilities of the central board with only two pins. It also is able to support multiple masters on a single data bus. Finally, the communication requires little resources from the sensor boards especially during a master 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 sensor board 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.