Hi,
Thanks for the suggestion. I was trying to execute your example but getting the output on the master serial monitor as follows. Could you please tell me what went wrong?
Master - NodeMCU
#include <Wire.h>
void setup()
{
Wire.begin(D4, D3); //SDA=D4, SCL=D3
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(8, 1); // request 6 bytes from slave device #8
char c = Wire.read();
Serial.print("Reading 6-bytes from Slave-1: ");
Serial.println(c, HEX);
//-----------------------
Wire.requestFrom(9, 1); // request bytes from slave device #8
char d = Wire.read();
Serial.print("Reading 7-bytes from Slave-2: ");
Serial.println(d, HEX);
//------------------------
delay(1000);
}
Slave 1
#include<Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin(8); ////UNO-Slave Address
Wire.onRequest(sendEvent);
}
void loop()
{
}
void sendEvent()
{
Wire.write(0x13);
}
Slave 2
#include<Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin(9); ////UNO-Slave Address
Wire.onRequest(sendEvent);
}
void loop()
{
}
void sendEvent()
{
Wire.write(0x27);
}
Master - Serial Monitor
9:15:53.418 -> Reading 6-bytes from Slave-1: 13
19:15:53.418 -> Reading 7-bytes from Slave-2: FF
19:15:54.397 -> Reading 6-bytes from Slave-1: 13
19:15:54.443 -> Reading 7-bytes from Slave-2: FF
19:15:55.421 -> Reading 6-bytes from Slave-1: 13
19:15:55.421 -> Reading 7-bytes from Slave-2: FF
19:15:56.400 -> Reading 6-bytes from Slave-1: 13
19:15:56.447 -> Reading 7-bytes from Slave-2: FF
19:15:57.426 -> Reading 6-bytes from Slave-1: 13
19:15:57.426 -> Reading 7-bytes from Slave-2: FF
19:15:58.397 -> Reading 6-bytes from Slave-1: 13
19:15:58.444 -> Reading 7-bytes from Slave-2: FF
19:15:59.418 -> Reading 6-bytes from Slave-1: 13
19:15:59.465 -> Reading 7-bytes from Slave-2: FF
19:16:00.395 -> Reading 6-bytes from Slave-1: 13
19:16:00.441 -> Reading 7-bytes from Slave-2: FF
19:16:01.413 -> Reading 6-bytes from Slave-1: 13
19:16:01.459 -> Reading 7-bytes from Slave-2: FF
19:16:02.435 -> Reading 6-bytes from Slave-1: 13