#include "Wire.h"
TwoWire bus1(0);
TwoWire bus2(1);
void setup() {
Serial.begin(115200);
bus1.begin(17, 16);
bus2.begin(21, 20);
}
void loop() {
byte error, address;
int nDevices = 0;
delay(5000);
Serial.println("Scanning for I2C devices on bus 1...");
for (address = 0x01; address < 0x7f; address++) {
bus1.beginTransmission(address);
error = bus1.endTransmission();
if (error == 0) {
Serial.printf("I2C device found at address 0x%02X\n", address);
nDevices++;
} else if (error != 2) {
Serial.printf("Error %d at address 0x%02X\n", error, address);
}
}
Serial.println("Scanning for I2C devices on bus 2...");
for (address = 0x01; address < 0x7f; address++) {
bus2.beginTransmission(address);
error = bus2.endTransmission();
if (error == 0) {
Serial.printf("I2C device found at address 0x%02X\n", address);
nDevices++;
} else if (error != 2) {
Serial.printf("Error %d at address 0x%02X\n", error, address);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found");
}
}