30 lines
584 B
C++
30 lines
584 B
C++
#include <Wire.h>
|
|
|
|
void setup() {
|
|
Wire.begin();
|
|
Serial.begin(9600);
|
|
while (!Serial);
|
|
Serial.println("I2C Scanner");
|
|
}
|
|
|
|
void loop() {
|
|
byte error, address;
|
|
int count = 0;
|
|
|
|
for (address = 1; address < 127; address++) {
|
|
Serial.println("Scanning address {address}");
|
|
Wire.beginTransmission(address);
|
|
error = Wire.endTransmission();
|
|
Serial.print(error);
|
|
|
|
if (error == 0) {
|
|
Serial.print("I2C device found at 0x");
|
|
Serial.println(address, HEX);
|
|
count++;
|
|
}
|
|
}
|
|
|
|
if (count == 0) Serial.println("No I2C devices found");
|
|
|
|
delay(2000);
|
|
} |