What is I2C
I2C is a serial protocol for a two-wire interface to connect low-speed electronic devices / modules such as microcontrollers, EEPROMs, A / D and D / A converters, I / O interfaces and other similar peripherals in embedded systems.
The I2C protocol was created by Philips and is now used by almost all major IC manufacturers. Each slave I2C device needs an address in order to communicate with the I2C master device which acts as a data communication controller.
Advantages of I2C Protocol
- The system is simpler because it only uses two-wire (two-wire) to communicate with many peripherals. With the condition that each device / peripheral has a different I2C Address.
- Saves I / O port from Microcontroller / Minimum System because it only uses I2C port.
Often I2C electronic equipment / modules on the market do not include information about the address. Though I2C Address is the main prerequisite so that we can access and communicate with the equipment or module.
At the end of this article, we include an Arduino sketch or program code to detect or find the I2C Address of a module or electronic device for which we do not know the I2C Address.
Examples of Electronic Devices / Modules Using the I2C Protocol
The following are examples of some electronic devices / modules whose interfaces use the I2C protocol and its program examples :
- I2C LCD Backpack
- I2C OLED LCD
- Example Program RTC DS3231 Module
- Example Program I2C ADC ADS1115 Module
- Example Program Light Sensor BH1750 Using Arduino
- 16 Channel PWM/Servo Driver PCA9685
- dll
Program Code
// I2C Scanner // Written by Nick Gammon // Date: 20th April 2011 #include <Wire.h> void setup() { Serial.begin (9600); // Leonardo: wait for serial port to connect while (!Serial) { } Serial.println (); Serial.println ("I2C scanner. Scanning …"); byte count = 0; Wire.begin(); for (byte i = 1; i < 120; i++) { Wire.beginTransmission (i); if (Wire.endTransmission () == 0) { Serial.print ("Found address: "); Serial.print (i, DEC); Serial.print (" (0x"); Serial.print (i, HEX); Serial.println (")"); count++; delay (1); // maybe unneeded? } // end of good response } // end of for loop Serial.println ("Done."); Serial.print ("Found "); Serial.print (count, DEC); Serial.println (" device(s)."); } // end of setup void loop() {}
+++++++ May be Useful +++++++
Leave a Reply