When a request is made by master, this function write data from slave device.Afterward, bytes to be transmitted are queued using write () function and these bytes are transmitted using endTransmission() function. This command initiates the transmission of bytes with slave device of given address. “Address” is the address of a specific slave device from which a request is to be made and “quantity” specify the number of bytes to be requested. “Available ()” and “read ()” functions can be used for collecting these bytes afterward. This command is used by the Master device for requesting the bytes from a slave device. In case it is not specified device joins the bus as Master. This address consists of seven bits for the slave devices. The wire library is initiated using this command and join the I2C bus as master or slave. Following are important functions of this library. The “wire” library is used for I2C communication in Arduino. The communication between specific devices using two wires is accomplished by the fact that each device has its own unique device ID or address and using this address master can choose any specific device to communicate. Each slave device which is connected with the bus will have a unique 8-bit address. These lines are open-drain lines which means these need to be connected to pull up resistors if devices are active low. One wire is SCL (serial clock line) which synchronizes the transmission of data between devices and the other wire is SDA (serial data) which carries the actual data to be transmitted. The distinguishing feature of I2C over SPI is that it uses only two wires to carry out communication. It is only applicable for short distance data transmission.
Many Sensors use this serial communication protocol to transfer their data to microcontrollers or through this protocol different slave circuits are able to communication with master circuits. I2C bus supports multiple slave devices and multiple master devices. Devices that want to communicate with each connects through an I2C bus.