53. I2C Concepts 1

Question.4

What will be printed on the Serial Monitor of Master? (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();
  Serial.begin(9600);
  delay(1000); 
}


void loop() {
  Wire.requestFrom(8, 1); 
  while (Wire.available()) {
    byte receivedData = Wire.read();
    Serial.print("Master received: ");
    Serial.println(receivedData);
  }
  delay(1000); 
}

 

Slave 1 Arduino Code:

#include <Wire.h>

void setup() {
  Wire.begin(8);  
  Wire.onRequest(sendData); 
}

void loop() {
}

void sendData() {
  byte dataToSend = 14; 
  Wire.write(dataToSend); 
}


Slave 2 Arduino Code:

#include <Wire.h>

void setup() {
  Wire.begin(8);
  Wire.onRequest(sendData);
}

void loop() {
}

void sendData() {
  byte dataToSend = 3; 
  Wire.write(dataToSend);  
}


 

Select Answer