Introduction to I2C#

I2C stands for Inter-Integrated Circuit. It is a popular communication protocol used by several peripherals like accelerometer and gyroscopes, OLED Displays, etc. Arduino refers to I2C as Wire, which is a shorter form of the term Atmel uses (Two Wire Interface or TWI). Here are some salient features of I2C −

  • It uses only two lines: One for data (SDA) and one for clock (SCL). I2C is synchronous because it uses a clock.

  • The slaves are not selected via a slave select line, but via address bits.

  • The first byte sent by the master contains a seven-bit address and a read/ write bit indicating whether the next bytes will come from the master or should come from the slave. Thus a maximum of 127 slaves with unique addresses can be connected to a single master.

  • After each byte, the receiver must send a 0 to acknowledge the reception of the byte

  • If the master wants to receive the data, it only generates clock pulses. The slave has to make sure that the next bit is ready when the clock pulse arrives

  • The data and clock lines are pulled up, i.e. two resistors pull the bus to a high level and the devices only send low levels. If they want to send high level, they simply release the bus.

  • Start/Stop sequence is required to signal start and end of communication

On Arduino Uno, there is I2C support. The following pins are generally used for I2C −

  • SDA − A4

  • SCL − A5

built-in Wire library#

Arduino has a built-in Wire library. The important functions of this library are given below −

  • Wire.begin() − Initialize Wire

  • Wire.beginTransmission(address) − Initiate transmission with the slave identified by address

  • Wire.endTransmission() − End a transmission initiated by beginTransmission()

  • Wire.SetClock(frequency) − Set the clock speed to frequency (in Hz)

  • Wire.write(byte) − Queue bytes for transmission from master to slave, or write data from slave in response to request from master

  • Wire.read() − If a master send requestFrom() to slave, then it will read the returned byte using this function. Alternatively, if master transmitted bytes to a slave, this function on the slave will be used to read the bytes

Tutorials#

Arduino I2C Tutorial: Communication between two Arduino Boards

Wire (I2C) | Reference | Particle

I2C — Arduino-ESP32 2.0.6 documentation

I2C Hub#

I2C Hub Grove接口扩展板-淘宝网