raw snippet

Snippet: Arduino I2C Scanner

Robert Eisele

To print all connected I2C device addresses run the following code on your Arduino

#include <Wire.h>

void setup() {

  byte count = 0;

  Serial.begin(9600);
  Serial.println("I2C scanner. Scanning ...");

  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);
    }
  }

  Serial.print("Found ");
  Serial.print(count, DEC);
  Serial.println(" device(s).");
}

void loop() {

}