#include <Wire.h>
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); // SDA, SCL
delay(1000);
Serial.println("I2C Scanner Starting...");
}
void loop() {
byte error, address;
int devices = 0;
for (address = 1; address < 127; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("Device found at 0x");
if (address < 16) Serial.print("0");
Serial.print(address, HEX);
Serial.println(" !");
devices++;
}
}
if (devices == 0)
Serial.println("No I2C devices found");
else
Serial.println("Scan complete");
delay(5000);
}