I2C Scanner Program To Know I2C Addresses From Electronic Devices or Modules

Spread the love

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 :

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;
   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 (")");
       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 +++++++

Be the first to comment

Leave a Reply

Your email address will not be published.