I2C Master-Slave with NodeMCU and Arduino UNO

Hi everyone,

I have a question and need suggestion about master and slave setup.

In a setup with NodeMCU as master and 2 Arduino UNO's as slaves, slaves should receive data from i2c sensors and send that to master. When I check the individual serial monitors of each slave, I can see the sensors data. But when I check the master's serial monitor, I can only see the slave 1 data but not slave 2.

Could you please find out what's wrong with my code? and give me a solution for my problem. Would really appreciate for inputs on this.

Slave 1 - Arduino UNO

#include <Wire.h>
#include <avr/wdt.h>


////////////////////////scd
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
SCD30 airSensor;
/////////////////////////////////////////bmp
//
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // use I2C interface
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
float array3[1];

////////////////////////////////////
//
//--INA219 current sensor--------------------------
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float power_mW = 0;
float loadvoltage = 0;
float array1[3];
////------------------------------------------------

float co2 = 0;
float co2hum = 0;
float co2temp = 0;
float pressure = 0;

char co2s[7];
char co2temps[5];
char co2hums[5];
char pressures[5];

//MQ8 variables
float MQ8sensorValue;
float array2[3];

#define         MQ_PIN                       (A0)     //define which analog input channel you are going to use
#define         RL_VALUE                     (10)    //define the load resistance on the board, in kilo ohms
#define         RO_CLEAN_AIR_FACTOR          (70)  //RO_CLEAR_AIR_FACTOR=(Sensor resistance in clean air)/RO,
//which is derived from the chart in datasheet

/***********************Software Related Macros************************************/
#define         CALIBARAION_SAMPLE_TIMES     (50)    //define how many samples you are going to take in the calibration phase
#define         CALIBRATION_SAMPLE_INTERVAL  (500)   //define the time interal(in milisecond) between each samples in the
//cablibration phase
#define         READ_SAMPLE_INTERVAL         (50)    //define how many samples you are going to take in normal operation
#define         READ_SAMPLE_TIMES            (5)     //define the time interal(in milisecond) between each samples in 
//normal operation

/**********************Application Related Macros**********************************/
#define         GAS_H2                      (0)
/*****************************Globals***********************************************/
float           H2Curve[3]  =  {2.3, 0.93, -1.44};   //two points are taken from the curve in datasheet.
//with these two points, a line is formed which is "approximately equivalent"
//to the original curve.
//data format:{ x, y, slope}; point1: (lg200, lg8.5), point2: (lg10000, lg0.03)

float           Ro           =  15;                  //Ro is initialized to 10 kilo ohms
/*****************************************************************/
/*****************************************************************/


#define MUX_Address 0x70 // TCA9548A Encoders address



// Initialize I2C buses using TCA9548A I2C Multiplexer
void tcaselect(uint8_t i2c_bus) {
  if (i2c_bus > 7) return;
  Wire.beginTransmission(MUX_Address);
  Wire.write(1 << i2c_bus);
  Wire.endTransmission(true);
}

// But please don't sue me if it doesn't work.
bool Would_I2C_Hang(int SDAPin, int SCLPin) {
  bool wouldHang = false;
  pinMode(SDAPin, INPUT);
  pinMode(SCLPin, INPUT);
  if ( digitalRead(SDAPin) != 1 ) {
    Serial.println("SDA pin is low");
    wouldHang = true;
  }
  if ( digitalRead(SCLPin) != 1 ) {
    Serial.println("SCL pin is low");
    wouldHang = true;
  }
  return wouldHang;
}

void setup() {
  Serial.begin(230400);

  for (int i = 5; i > 0; i--) {
    Serial.print(i);
    delay(1000); // I sometimes need a few seconds to restart the serial console.
    wdt_enable(WDTO_4S);
  }

  Serial.println();
  if ( Would_I2C_Hang(20, 21) ) { // Adafruit Feather M0 sda and sdl arduino pins.
    Serial.println("The I2C bus will hang if we try to use it. Disabling it.");
  } else {
    Serial.println("Mark the I2C devices as ready to be tested.");
  }

  Wire.begin(0x02);
  SensorInit(); // Initialize the displays
  Wire.onRequest(Request);
}

// Initialize the displays
void SensorInit() {

  tcaselect(0);  // channel 0 --> SCD30
  Serial.println("Channel 1 of Mux");
  Serial.println("SCD30 Example");
  Wire.begin();


  if (airSensor.begin() == false)
  {
    Serial.println("Air sensor not detected. Please check wiring. Freezing...");
    while (1)
      ;
  }

  tcaselect(3);  // channel 2  INA219 --> BMP280
  ina219.begin();
  ina219.setCalibration_16V_400mA(); // set measurement range to 16V, 400mA






  tcaselect(7);  // channel 7 --> BMP280
  ////////pressure///////////////
  Serial.println(F("BMP280 Sensor event test"));

  if (!bmp.begin(0x76)) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    delay(10);
  }


  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

  bmp_temp->printSensorDetails();

}
void loop() {
  MQ8(array2);
  tcaselect(0);  // channel 0 --> SCD30
  if (airSensor.dataAvailable())
  {
    Serial.print("co2(ppm):");
    Serial.print(airSensor.getCO2());
    co2 = airSensor.getCO2();

    Serial.print(" temp(C):");
    Serial.print(airSensor.getTemperature(), 1);
    co2temp = airSensor.getTemperature();

    Serial.print(" humidity(%):");
    Serial.print(airSensor.getHumidity(), 1);
    co2hum = airSensor.getHumidity();
    Serial.println();
    Serial.println();

    Serial.println();
    Serial.print(" Pre-stream data");
    Serial.println();
    Serial.print(co2);
    Serial.println();
    Serial.print(co2temp);
    Serial.println();
    Serial.print(co2hum);
    Serial.println();
  }

  tcaselect(3);
  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  power_mW = ina219.getPower_mW();
  loadvoltage = busvoltage + (shuntvoltage / 1000);

  Serial.println();
  Serial.println();
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  Serial.println("");
  Serial.println();
  Serial.println();
  array1[0] = busvoltage;
  array1[1] = shuntvoltage;
  array1[2] = loadvoltage;
  array1[3] = current_mA;

  tcaselect(7);  // channel 7 --> BMP280
  sensors_event_t temp_event, pressure_event;
  bmp_temp->getEvent(&temp_event);
  bmp_pressure->getEvent(&pressure_event);

  Serial.println();
  Serial.println();
  Serial.print(F("Temperature = "));
  Serial.print(temp_event.temperature);
  Serial.println(" *C");

  Serial.println();
  Serial.print(F("Pressure = "));
  Serial.print(pressure_event.pressure);
  Serial.println(" hPa");
  Serial.println();

  array3[1] = temp_event.temperature;
  delay(1000);


  wdt_reset();

}

//MQ8 readings function
void * MQ8(float array2[3])
{
  MQ8sensorValue = analogRead(A0);
  Serial.print("H2 Concentration:");
  float ppm = MQGetGasPercentage(MQRead(MQ_PIN) / Ro, GAS_H2);
  Serial.print(ppm );
  Serial.print( "ppm" );
  Serial.print("\n");
  array2[0] = MQ8sensorValue;
  array2[1] = ppm;
  //delay(15000);
}
//****************** MQResistanceCalculation ****************************************

float MQResistanceCalculation(int raw_adc) {
  return ( ((float)RL_VALUE * (1023 - raw_adc) / raw_adc));
}

/
float MQCalibration(int mq_pin) {
  int i;
  float val = 0;

  for (i = 0; i < CALIBARAION_SAMPLE_TIMES; i++) {      //take multiple samples
    val += MQResistanceCalculation(analogRead(mq_pin));
    delay(CALIBRATION_SAMPLE_INTERVAL);
  }
  val = val / CALIBARAION_SAMPLE_TIMES;                 //calculate the average value

  val = val / RO_CLEAN_AIR_FACTOR;                      //divided by RO_CLEAN_AIR_FACTOR yields the Ro
  //according to the chart in the datasheet

  return val;
}

//////////////////////////////////////////////////////////////////////

float MQRead(int mq_pin) {
  int i;
  float rs = 0;

  for (i = 0; i < READ_SAMPLE_TIMES; i++) {
    rs += MQResistanceCalculation(analogRead(mq_pin));
    delay(READ_SAMPLE_INTERVAL);
  }

  rs = rs / READ_SAMPLE_TIMES;

  return rs;
}


int MQGetGasPercentage(float rs_ro_ratio, int gas_id) {
  if ( gas_id == GAS_H2) {
    return MQGetPercentage(rs_ro_ratio, H2Curve);
  }
  return 0;
}


int  MQGetPercentage(float rs_ro_ratio, float *pcurve) {
  return (pow(10, ( ((log(rs_ro_ratio) - pcurve[1]) / pcurve[2]) + pcurve[0])));
}
////////////////////////////////////////////////////////////////
void Request()
{
  //Converting float value to char
  //The format (float, bytes, numbers of numbers after the decimal, char variable)
  delay(2000);
  dtostrf(co2, 7, 1, co2s);
  Wire.write(co2s); // appx 8 bytes
  Wire.write(",");
  dtostrf(co2temp, 4, 1, co2temps);
  Wire.write(co2temps); // appx 8 bytes
  Wire.write(",");
  dtostrf(co2hum, 4, 1, co2hums);
  Wire.write(co2hums); // appx 8
  Wire.write(",");
  dtostrf(pressure, 6, 4, pressures);
  Wire.write(pressures); // appx 8

  Wire.write("\n");


}

Slave 2 - Arduino UNO

#include <Wire.h>
#include <avr/wdt.h>

////////////////////////scd
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
SCD30 airSensor;
/////////////////////////////////////////bmp
//
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // use I2C interface
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
float array3[1];

////////////////////////////////////
//
//--INA219 current sensor--------------------------
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float power_mW = 0;
float loadvoltage=0;
float array1[3];
////------------------------------------------------

float co2 = 0;
float co2hum = 0;
float co2temp = 0;
float pressure = 0;


char co2s[7];
char co2temps[5];
char co2hums[5];
char pressures[5];


//MQ8 variables
      float MQ8sensorValue;
      float array4[3];
    
      #define         MQ_PIN                       (A0)     //define which analog input channel you are going to use
      #define         RL_VALUE                     (10)    //define the load resistance on the board, in kilo ohms
      #define         RO_CLEAN_AIR_FACTOR          (70)  //RO_CLEAR_AIR_FACTOR=(Sensor resistance in clean air)/RO,
      //which is derived from the chart in datasheet
      
      /***********************Software Related Macros************************************/
      #define         CALIBARAION_SAMPLE_TIMES     (50)    //define how many samples you are going to take in the calibration phase
      #define         CALIBRATION_SAMPLE_INTERVAL  (500)   //define the time interal(in milisecond) between each samples in the
      //cablibration phase
      #define         READ_SAMPLE_INTERVAL         (50)    //define how many samples you are going to take in normal operation
      #define         READ_SAMPLE_TIMES            (5)     //define the time interal(in milisecond) between each samples in 
      //normal operation
      
      /**********************Application Related Macros**********************************/
      #define         GAS_H2                      (0)
      /*****************************Globals***********************************************/
      float           H2Curve[3]  =  {2.3, 0.93, -1.44};   //two points are taken from the curve in datasheet.
      //with these two points, a line is formed which is "approximately equivalent"
      //to the original curve.
      //data format:{ x, y, slope}; point1: (lg200, lg8.5), point2: (lg10000, lg0.03)
      
      float           Ro           =  15;                  //Ro is initialized to 10 kilo ohms
 /*****************************************************************/
 /*****************************************************************/



#define MUX_Address 0x71 // TCA9548A Encoders address



// Initialize I2C buses using TCA9548A I2C Multiplexer
void tcaselect(uint8_t i2c_bus) {
    if (i2c_bus > 7) return;
    Wire.beginTransmission(MUX_Address);
    Wire.write(1 << i2c_bus);
    Wire.endTransmission(true); 
}

// But please don't sue me if it doesn't work.
bool Would_I2C_Hang(int SDAPin, int SCLPin) {
  bool wouldHang = false;
  pinMode(SDAPin, INPUT);
  pinMode(SCLPin, INPUT);
  if ( digitalRead(SDAPin) != 1 ) {
    Serial.println("SDA pin is low");
    wouldHang = true;
  }
  if ( digitalRead(SCLPin) != 1 ) {
    Serial.println("SCL pin is low");
    wouldHang = true;
  }
  return wouldHang;
}

void setup(){
  Serial.begin(230400);

   for (int i = 5; i > 0; i--) {
    Serial.print(i);
    delay(1000); // I sometimes need a few seconds to restart the serial console.
    wdt_enable(WDTO_4S);
  }

  Serial.println();
  if ( Would_I2C_Hang(20, 21) ) { // Adafruit Feather M0 sda and sdl arduino pins.
    Serial.println("The I2C bus will hang if we try to use it. Disabling it.");
  } else {
    Serial.println("Mark the I2C devices as ready to be tested.");
  }


   Wire.begin(0x04);
    SensorInit(); // Initialize the displays 
    Wire.onRequest(Request); 
}

// Initialize the displays 
void SensorInit(){
  
    tcaselect(0);  // channel 0 --> SCD30
    Serial.println("Channel 1 of Mux");
    Serial.println("SCD30 Example");
    Wire.begin();


  if (airSensor.begin() == false)
  {
    Serial.println("Air sensor not detected. Please check wiring. Freezing...");
    while (1)
      ;
  }
   
   tcaselect(3);  // channel 2  INA219 --> BMP280
   ina219.begin();
   ina219.setCalibration_16V_400mA(); // set measurement range to 16V, 400mA

//   
   tcaselect(7);  // channel 7 --> BMP280
     ////////pressure///////////////
      Serial.println(F("BMP280 Sensor event test"));
    
      if (!bmp.begin(0x76)) {
        Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
        delay(10);
      }
     
    
     bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                      Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                      Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                      Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                      Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
    
      bmp_temp->printSensorDetails();

  
}

void loop(){

  while (0 <Wire.available()) {
    char d = Wire.read();      /* receive byte as a character */
    Serial.print(d);           /* print the character */
  }


        MQ8(array4);


   tcaselect(0);  // channel 0 --> SCD30
   if (airSensor.dataAvailable())
  {
     Serial.print("co2(ppm):");
    Serial.print(airSensor.getCO2());
    co2=airSensor.getCO2();
    

    Serial.print(" temp(C):");
    Serial.print(airSensor.getTemperature(), 1);
    co2temp=airSensor.getTemperature();
    

    Serial.print(" humidity(%):");
    Serial.print(airSensor.getHumidity(), 1);
    co2hum=airSensor.getHumidity();
    Serial.println();
  Serial.println();

  Serial.println();
    Serial.print(" Pre-stream data");
     Serial.println();
    Serial.print(co2);
    Serial.println();
    Serial.print(co2temp);
    Serial.println();
    Serial.print(co2hum);
    Serial.println();
   
  }
     
     tcaselect(3);
     shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  power_mW = ina219.getPower_mW();
  loadvoltage = busvoltage + (shuntvoltage / 1000);
 
  Serial.println();
  Serial.println();
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  Serial.println("");
  Serial.println();
  Serial.println();
    array1[0] = busvoltage;
    array1[1] = shuntvoltage;
    array1[2] =loadvoltage;
    array1[3] = current_mA;

     tcaselect(7);  // channel 7 --> BMP280
     sensors_event_t temp_event, pressure_event;
  bmp_temp->getEvent(&temp_event);
  bmp_pressure->getEvent(&pressure_event);
//  
  Serial.println();
  Serial.println();
  Serial.print(F("Temperature = "));
  Serial.print(temp_event.temperature);
  Serial.println(" *C");
//
  Serial.println();
  Serial.print(F("Pressure = "));
  Serial.print(pressure_event.pressure);
  Serial.println(" hPa");
  //float pressure_pascal=pressure_event.pressure/1000 - 0.90883;
  Serial.println();
    
     array3[1] = temp_event.temperature;
     delay(1000);
    //////////////////////
  
    delay(500);

      delay(500);
  wdt_reset();
  
}

//MQ8 readings function
void * MQ8(float array4[3])
{
      MQ8sensorValue = analogRead(A0);
      Serial.print("H2 Concentration:");
      float ppm=MQGetGasPercentage(MQRead(MQ_PIN) / Ro, GAS_H2);
      Serial.print(ppm );
      Serial.print( "ppm" );
      Serial.print("\n");
      array4[0] = MQ8sensorValue;
      array4[1] = ppm;
      //delay(15000);
}

      float MQResistanceCalculation(int raw_adc) {
        return ( ((float)RL_VALUE * (1023 - raw_adc) / raw_adc));
      }
      

      float MQCalibration(int mq_pin) {
        int i;
        float val = 0;
      
        for (i = 0; i < CALIBARAION_SAMPLE_TIMES; i++) {      //take multiple samples
          val += MQResistanceCalculation(analogRead(mq_pin));
          delay(CALIBRATION_SAMPLE_INTERVAL);
        }
        val = val / CALIBARAION_SAMPLE_TIMES;                 //calculate the average value
      
        val = val / RO_CLEAN_AIR_FACTOR;                      //divided by RO_CLEAN_AIR_FACTOR yields the Ro
        //according to the chart in the datasheet
      
        return val;
      }
     
    //////////////////////////////////////////////////////////////////////

      float MQRead(int mq_pin) {
        int i;
        float rs = 0;
      
        for (i = 0; i < READ_SAMPLE_TIMES; i++) {
          rs += MQResistanceCalculation(analogRead(mq_pin));
          delay(READ_SAMPLE_INTERVAL);
        }
      
        rs = rs / READ_SAMPLE_TIMES;
      
        return rs;
      }
      
   
      int MQGetGasPercentage(float rs_ro_ratio, int gas_id) {
        if ( gas_id == GAS_H2) {
          return MQGetPercentage(rs_ro_ratio, H2Curve);
        }
        return 0;
      }
      
   
      int  MQGetPercentage(float rs_ro_ratio, float *pcurve) {
        return (pow(10, ( ((log(rs_ro_ratio) - pcurve[1]) / pcurve[2]) + pcurve[0])));
      }
 ////////////////////////////////////////////////////////////////

 
void Request()
{

//Converting float value to char
//The format (float, bytes, numbers of numbers after the decimal, char variable)
    delay(2000);
    dtostrf(co2, 7, 1, co2s); 
    Wire.write(co2s); // appx 8 bytes
    Wire.write(",");
    dtostrf(co2temp, 4, 1, co2temps); 
    Wire.write(co2temps); // appx 8 bytes
    Wire.write(",");
    dtostrf(co2hum, 4, 1, co2hums); 
    Wire.write(co2hums); // appx 8 
    Wire.write(",");
    dtostrf(pressure, 6, 4, pressures); 
    Wire.write(pressures); // appx 8 

    Wire.write("\n");
 

}

Master - NodeMCU


#include "FirebaseESP8266.h"  // Install Firebase ESP8266 library
#include <esp8266wifi.h>//<ESP8266WiFi.h>
#define FIREBASE_HOST "********************************"
#define FIREBASE_AUTH "***********************************"
#define WIFI_SSID "****************"
#define WIFI_PASSWORD "************************"
FirebaseData firebaseData;

#include <Wire.h>

float co2ppm = 0;
float co2temp = 0;
float co2hum = 0;
float pressure = 0;

//////////////////// slave 2

float co2ppm2 = 0;
float co2temp2 = 0;
float co2hum2 = 0;
float pressure2 = 0;

void setup() {

  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(115200);  // start serial for output
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(300);
  }
  Serial.println();
  Serial.print("Connected with IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);


}

void loop() {
  delay(5000);
  Wire.requestFrom(0x02, 23);
  delay(2000);
  String datastream1, co2ppms, co2temps, co2hums, pressures;
  do   // slave may send less than requested
  {
    char c = Wire.read(); // receive a byte as character

    datastream1 = datastream1 + c; //Keep saving whatever is comming

    co2ppms = datastream1.substring(0, 7); //slpit String from 0 to 8
    co2temps = datastream1.substring(8, 12); // Split from 9 to the End of String
    co2hums = datastream1.substring(13, 17);
    pressures = datastream1.substring(18, 23);

  } while (Wire.available());
  Serial.print("Recieving float as String...");
  Serial.println();
  Serial.println();
  Serial.print("Datastream...");
  Serial.println();
  Serial.println();
  Serial.print(datastream1);
  Serial.println();
  Serial.println();
  Serial.print("CO2 PPM: ");
  Serial.print(co2ppms);
  Serial.println();
  Serial.println();
  Serial.print("CO2 TEMP: ");
  Serial.print(co2temps);
  Serial.println();
  Serial.println();
  Serial.print("CO2 HUM: ");
  Serial.print(co2hums);
  Serial.println();
  Serial.println();
  Serial.print("Pressure: ");
  Serial.print(pressures);
  Serial.println();
  Serial.println();
  Serial.print("Converting string to float...");
  Serial.println();
  Serial.println();
  co2ppm = co2ppms.toFloat();
  Serial.print("CO2 PPM: ");
  Serial.print(co2ppm);
  Serial.println();
  co2temp = co2temps.toFloat();
  Serial.print("CO2 TEMP: ");
  Serial.print(co2temp);
  Serial.println();
  co2hum = co2hums.toFloat();
  Serial.print("CO2 HUM: ");
  Serial.print(co2hum);
  Serial.println();
  pressure = pressures.toFloat();
  Serial.print("PRESSURE: ");
  Serial.print(pressure);
  Serial.println();

  //-firebase-----------------------------------------------
  ////////////////////////////////////// Firebase data//////////////////////
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);   // connect to firebase
  Firebase.reconnectWiFi(true);

  ///////////////Variable one - CO2 PPM//////////////

  if (Firebase.setFloat(firebaseData, "/Reactors/Slave1/CO2 PPM", co2ppm)) {    // On successful Write operation, function returns 1
    Serial.println("Value Uploaded Successfully");
    Serial.print("CO2 PPM= ");
    Serial.println(co2ppm);
    Serial.println("\n");

    //val++;


  }

  else {
    Serial.println(firebaseData.errorReason());
  }


  Serial.println();

  ///////////////Variable 2 - CO2 TEMP//////////////

  if (Firebase.setFloat(firebaseData, "/Reactors/Slave1/CO2 Temp", co2temp)) {    // On successful Write operation, function returns 1
    Serial.println("Value Uploaded Successfully");
    Serial.print("CO2 TEMP= ");
    Serial.println(co2temp);
    Serial.println("\n");

    //val++;


  }

  else {
    Serial.println(firebaseData.errorReason());
  }


  Serial.println();

  ///////////////Variable 3 - CO2 HUM//////////////

  if (Firebase.setFloat(firebaseData, "/Reactors/Slave1/ CO2HUM", co2hum)) {    // On successful Write operation, function returns 1
    Serial.println("Value Uploaded Successfully");
    Serial.print("CO2 HUM= ");
    Serial.println(co2hum);
    Serial.println("\n");

    //val++;


  }

  else {
    Serial.println(firebaseData.errorReason());
  }

  ///////////////Variable 4 - Pressure//////////////

  if (Firebase.setFloat(firebaseData, "/Reactors/Slave1/ Pressure", pressure)) {    // On successful Write operation, function returns 1
    Serial.println("Value Uploaded Successfully");
    Serial.print("Pressure= ");
    Serial.println(pressure);
    Serial.println("\n");

    //val++;


  }

  else {
    Serial.println(firebaseData.errorReason());
  }


  Serial.println();

delay (1000);
  /////////////////////////////
  //  ///2nd slave
  //  /////////////////////////////
  delay(5000);
  Serial.println();
  Serial.println();
  Serial.print("Recieving from slave 2...");
  Serial.println();

  //////////////////////////

  Wire.requestFrom(0x04, 23);
  String datastream2, co2ppms2, co2temps2, co2hums2, pressures2;
  do   // slave may send less than requested
  {
    char d = Wire.read(); // receive a byte as character

    datastream2 = datastream2 + d; //Keep saving whatever is comming

    co2ppms2 = datastream2.substring(0, 7); //slpit String from 0 to 8
    co2temps2 = datastream2.substring(8, 12); // Split from 9 to the End of String
    co2hums2 = datastream2.substring(13, 17);
    pressures2 = datastream2.substring(18, 23);

  } while (Wire.available());
  Serial.print("Recieving float as String...");
  Serial.println();
  Serial.println();
  Serial.print("Datastream...");
  Serial.println();
  Serial.println();
  Serial.print(datastream2);
  Serial.println();
  Serial.println();
  Serial.print("CO2 PPM: ");
  Serial.print(co2ppms2);
  Serial.println();
  Serial.println();
  Serial.print("CO2 TEMP: ");
  Serial.print(co2temps2);
  Serial.println();
  Serial.println();
  Serial.print("CO2 HUM: ");
  Serial.print(co2hums2);
  Serial.println();
  Serial.println();
  Serial.print("Pressure: ");
  Serial.print(pressures2);
  Serial.println();
  Serial.println();
  Serial.print("Converting string to float...");
  Serial.println();
  Serial.println();
  co2ppm2 = co2ppms2.toFloat();
  Serial.print("CO2 PPM: ");
  Serial.print(co2ppm2);
  Serial.println();
  co2temp2 = co2temps2.toFloat();
  Serial.print("CO2 TEMP: ");
  Serial.print(co2temp2);
  Serial.println();
  co2hum2 = co2hums2.toFloat();
  Serial.print("CO2 HUM: ");
  Serial.print(co2hum2);
  Serial.println();
  pressure2 = pressures2.toFloat();
  Serial.print("PRESSURE: ");
  Serial.print(pressure2);
  Serial.println();

  //-firebase-----------------------------------------------
  ////////////////////////////////////// Firebase data//////////////////////
//  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);   // connect to firebase
//  Firebase.reconnectWiFi(true);

  ///////////////Variable one - CO2 PPM//////////////

  if (Firebase.setFloat(firebaseData, "/Reactors/Slave2/CO2 PPM", co2ppm2)) {    // On successful Write operation, function returns 1
    Serial.println("Value Uploaded Successfully");
    Serial.print("CO2 PPM= ");
    Serial.println(co2ppm2);
    Serial.println("\n");

    //val++;


  }

  else {
    Serial.println(firebaseData.errorReason());
  }


  Serial.println();

  ///////////////Variable 2 - CO2 TEMP//////////////

  if (Firebase.setFloat(firebaseData, "/Reactors/Slave2/CO2 Temp", co2temp2)) {    // On successful Write operation, function returns 1
    Serial.println("Value Uploaded Successfully");
    Serial.print("CO2 TEMP= ");
    Serial.println(co2temp2);
    Serial.println("\n");

    //val++;


  }

  else {
    Serial.println(firebaseData.errorReason());
  }


  Serial.println();

  ///////////////Variable 3 - CO2 HUM//////////////

  if (Firebase.setFloat(firebaseData, "/Reactors/Slave2/ CO2HUM", co2hum2)) {    // On successful Write operation, function returns 1
    Serial.println("Value Uploaded Successfully");
    Serial.print("CO2 HUM= ");
    Serial.println(co2hum2);
    Serial.println("\n");

    //val++;


  }

  else {
    Serial.println(firebaseData.errorReason());
  }

  ///////////////Variable 4 - Pressure//////////////
  //
  if (Firebase.setFloat(firebaseData, "/Reactors/Slave2/ Pressure", pressure2)) {    // On successful Write operation, function returns 1
    Serial.println("Value Uploaded Successfully");
    Serial.print("Pressure= ");
    Serial.println(pressure2);
    Serial.println("\n");

    //val++;

    //
  }

  else {
    Serial.println(firebaseData.errorReason());
  }


  Serial.println();



  delay(1000);

  Serial.println("");
}

I'm afraid you want too much. Stay with what you know. Can you do the whole project with a single nodeMCU or ESP32 ?

A few problems are:

  • The NodeMCU has a 3.3V I2C bus and the Arduino Uno has a 5V I2C bus. That means you have a voltage mismatch on the I2C bus.
  • You should have just one Master on the I2C bus, but you have three.
  • The onRequest handler (the Request() function) should be short and fast, it may not contain a delay.
  • Why make things complicated by adding a WatchDog timeout ?
  • It is unclear how the I2C multiplexer is in the circuit
  • and so on.

I can make that list a lot longer, and maybe others will help to solve a few problems here and there. That will not help. The overall setup of your project will not work.

Think of a different way, draw it on a piece of paper and ask us if it might work.

Hi Koepel,

Thank you for your reply. The reason for me going with this setup is, I will be needing 4 more slaves connected with 3 different I2C sensors(SCD30, INA219, BMP280) each via TCA9548A. So, the same set of sensors I am using for all the sensors.

I am powering all the UNO's separately through a 5V supply.

I have tried without a watchdog timer, but after certain readings, the UNO is freezing. This way I can continuously read out the sensors data.

The following sketch might give you a rough idea of my setup.

Is the SDA and SCL on the left side of the Uno the same as the SDA and SCL on the right side ?

Why do you need those I2C multiplexers ?

Can you give a broader view ? What is your project about ? How long are the distances between the Arduino Uno boards ?
Maybe a RS-485 would be a better solution for you.

You need that WatchDog because there is something seriously wrong.
I can tell everything that is wrong, but it is easier to say that this is not going to work.
Even the pullup resistors are too low in value, you don't have a normal I2C bus anymore.

@kpuvvala
Please, post a picture of your BMP280 sensor that you are using with UNO-1/UNO-2.