#include <Wire.h>
int address, deviceFound, error;
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.print("I2C bus device addresses:");
for (address = 0; address < 128; address++ ) {
Wire.beginTransmission(address);
if (!Wire.endTransmission()) {
showHex(address);
deviceFound++;
}
else if (error == 4) {
Serial.print(" Error at");
showHex(address);
}
}
if (!deviceFound)
Serial.println(" No I2C devices found.");
}
void loop() {}
void showHex(int hex) {
Serial.print(" 0x");
if (hex < 0x10)
Serial.print(0);
Serial.print(hex, HEX);
}