Exploring I2C devices
We touched on I2C devices back in Chapter 4, Using Specialized Output Devices—you may have used an I2C LCD to display some data. You may have noticed that the I2C LCD was much easier to wire up, and had the same API as the non-I2C LCD. Luckily, this is because Johnny-Five strives to give every component a similar API, regardless of its implementation or protocol. But how does I2C work, and what makes it a useful protocol?
How I2C works
I2C, which stands for Inter-Integrated Circuit, is a protocol that input and output components can use to communicate with microcontrollers. It's very standardized, and nearly all I2C devices operate in the same way. I2C also has the major benefit of being recognized and implemented by many major microcontroller manufacturers—including Arduino. Any Arduino platform that is compatible with Johnny-Five is also compatible with I2C devices.
However, implementing an I2C device in Johnny-Five can be a tricky proposition. To understand why, we...