NodeMCU - Master and UNO - Slaves (I2C communication)

1. There is no hardware I2C Interface inside NodeMCU like the UNO. Therefore, you have to emulate the I2C Interface within NodeMCU by including the following code in setup() function. And connect NdeMCU and UNO-1 and UNO-2 as per diagram of Fig-1.

Wire.begin(D4, D3);   //D4 (GPIO-2) -= SDA, D3 (GPI-0) = SCL ; you can use other GPIO pins


Figure-1:

2. Upload the followinh test sketches in NodeMCU, UNO-1/SLve-1, and UNO-2/Slave-2.

NodeMCU Sketch:

#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
  byte x = Wire.read();
  Serial.print("Reading 1-byte from SLve-1: ");
  Serial.println(x, HEX);
  //-----------------------
  Wire.requestFrom(9, 1);    // request  bytes from slave device #8
  byte y = Wire.read();
  Serial.print("Reading 1-byte from Slave-2: ");
  Serial.println(y, HEX);
  //------------------------
  delay(1000);
}

UNO-1/Slave-1 Sketch:

#include<Wire.h>

void setup()
{
  Serial.begin(9600);
  Wire.begin(8);  ////UNO-Slave Address
  Wire.onRequest(sendEvent);
}

void loop()
{  

}

void sendEvent()
{
  Wire.write(0x13);
}

UNO-2/Slave-2 Sketch:

#include<Wire.h>

void setup()
{
  Serial.begin(9600);
  Wire.begin(9);  ////UNO-Slave Address
  Wire.onRequest(sendEvent);
}

void loop()
{

}

void sendEvent()
{
  Wire.write(0x27);
}

3. Check that Serial Monitor of NodeMCU shows the following message that describes that NodeMCU is corretly acquiring data from bothe slaves.

Reading 1-byte from Slave-2: 27
Reading 1-byte from SLve-1: 13
Reading 1-byte from Slave-2: 27
Reading 1-byte from SLve-1: 13
Reading 1-byte from Slave-2: 27
Reading 1-byte from SLve-1: 13
Reading 1-byte from Slave-2: 27
Reading 1-byte from SLve-1: 13
Reading 1-byte from Slave-2: 27
Reading 1-byte from SLve-1: 13
Reading 1-byte from Slave-2: 27
Reading 1-byte from SLve-1: 13
Reading 1-byte from Slave-2: 27

4. Now, correct/modify your sketches of Post-1 in the light of the sketces of this post.