55. I2C Programming

Question.7

What will be printed on the Serial Monitor of Arduino 2?

Both Arduinos are initially configured as slaves.

Arduino 1 Code:

#include <Wire.h>
void setup() {
  Wire.begin(8);  
  delay(1000);
  
  Wire.beginTransmission(27);
  Wire.write("Hello, Slaves!");
  Wire.endTransmission();
}
void loop() {
}

 

Arduino 2 Code:

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


void loop() {
}


void receiveData(int byteCount) {
  while (Wire.available()) {
    char c = Wire.read();
    Serial.print(c);
  }
  Serial.println();
}


 

Select Answer