Hello,
I'm using an Arduino Mega and a number of ATTiny84 devices. Only 2 devices can be connected to the bus at any one time. When a device arrives, the Mega performs a scan to get the device's address so it can communicate.
The problem I'm having is that the devices often respond to the wrong address ping. About 50% of the time the reporting is correct, but the other half it seems they will respond to what seems to be a random address in the range, which is 100-112. The error codes on the failed scans are usually 2, but sometimes 4.
Things I have tried that didn't work:
- Slowing down the scanning with a delay between each address scan
- Removing the 4.7k resistors on the SDA/SCL lines and relying on the internal pull-ups
- Scanning each address multiple times
Here's my scanner code:
void scanForAddress() {
byte error, address;
Serial.print("Scanning ... ");
for (address = 100; address < 113; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
sampleAddresses = address; // Store the address
Serial.print("Found device at ");
Serial.println(address);
break;
} else {
Serial.print("Nothing found for ");
Serial.print(address);
Serial.print(", error code ");
Serial.println(error);
}
}
Is there something I'm missing here? Thanks for any suggestions!
No_u