Wire Library (I2C)


This library allows you to communicate with I2C / TWI devices. The library inherits from the Stream functions, making it consistent with other read/write libraries. I2C is a two wire interface using the SDA (Serial Data Line) and SCL (Serial Clock Line) pins to communicate over the serial bus. I2C uses a multi-master/multi-slave model where the master generates the clock and initiates communication with the slaves. A slave receives the clock and responds when addressed by the master. I2C is a common interface between a microcontroller and peripherals like sensors and displays.


There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it’s being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you’ll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127.

Demo Sketch


I2C is common in segment LCDs and different types of sensors. I2C is lower speed than some other protocols but is still very effective in communicating with multiple devices on one bus. Popular alternative protocols are SPI and UART.


Reference Home || Libraries Home