52. I2C Scenarios

Question.4

What will be printed on the Serial Monitor of slave 1 and slave 2? (after executing the following code).

Note: As we can see, two slave devices are connected, having the same slave address.

Master Arduino Code:

#include <Wire.h>
void setup() {
  Wire.begin();
  delay(1000);
}


void loop() {
  Wire.beginTransmission(8); 
  Wire.write(100);            
  Wire.endTransmission();
  while(1);
}

 

Slave Arduino Code:

Note: The same code (As it is) are uploaded in both slaves.

#include <Wire.h>
void setup() {
  Wire.begin(8);
  Serial.begin(9600);
  Wire.onReceive(receiveData);
}

void loop() {
}

void receiveData(int byteCount) {
  while (Wire.available()) {
    byte receivedData = Wire.read();
    Serial.print("Slave received: ");
    Serial.println(receivedData);
  }
}

 

 

 

Select Answer