I2C Communications w/ Multiple Slaves

I am working on connecting an Uno R3 to multiple slaves via I2C communication. The slaves include another Uno R3 that measures a digital sensor, and a Sparkfun Humidity Breakout board (HTU21D).

I’ve been trying for a while to piece together some source code from the manufacturers and from research on the topic, but have run into some issues. The two slaves can be called individually perfect - meaning they work fine when the other is commented out. However, when they are both in the code I get a repeated reading from the first slave called over and over. It doesn’t seem to ever get to the second slave in the code.

void loop()
//CO2 and Particle

//Humidity Board - HTU21D


void Slave2()
Wire.requestFrom(2, PAYLOAD_SIZE); //Wire.requestFrom(Node Address, Bytes Expected)
nodePayload[1] = Wire.read();
//Serial.println(nodePayload[1]); //Low
nodePayload[2] = Wire.read();
//Serial.println(nodePayload[2]); //High

unsigned long valCO2 = nodePayload[2] * 256 + nodePayload[1]; //Combine high byte and low byte with this formula to get value
Serial.print("Co2 [ppm] = ");


void Slave3()
float humd = readHumidity1();
//float temp = readTemperature();


 = ");

Serial.println(temp, 1);
  Serial.print("Humidity [%] = ");
  Serial.print(humd, 1);

float readHumidity1(void)
  //Request a humidity reading
  Wire.write(TRIGGER_HUMD_MEASURE_NOHOLD); //Measure humidity with no bus holding

//Hang out while measurement is taken. 50mS max, page 4 of datasheet.

//Comes back in three bytes, data(MSB) / data(LSB) / Checksum
  Wire.requestFrom(HTDU21D_ADDRESS, 3);

//Wait for data to become available
  int counter = 0;
  while (Wire.available() < 3)
    if (counter > 100) return 998; //Error out

byte msb, lsb, checksum;
  msb = Wire.read();
  lsb = Wire.read();
  checksum = Wire.read();

/* //Used for testing
  byte msb, lsb, checksum;
  msb = 0x4E;
  lsb = 0x85;
  checksum = 0x6B;*/

unsigned int rawHumidity = ((unsigned int) msb << 8) | (unsigned int) lsb;

//sensorStatus = rawHumidity & 0x0003; //Grab only the right two bits
  rawHumidity &= 0xFFFC; //Zero out the status bits but keep them in place

//Given the raw humidity data, calculate the actual relative humidity
  float tempRH = rawHumidity / (float)65536; //2^16 = 65536
  float rh = -6 + (125 * tempRH); //From page 14

return (rh);

Is there some break I need to add in order to get the second reading?



Weather_Master_05.ino (4.9 KB)

Sorry for posting with a quote instead of the code format. My mistake.