Go Down

Topic: Connecting multiple HDC100x sensors using I2C (Read 574 times) previous topic - next topic

rocksdontfly

I am trying to connect and read 5 individual HDC100x Temperature and Humidity sensors using I2C. The first problem is making the arduino recognize each of the sensors. I have used the A0 and A1 pins, so the arduino sees four separate sensors (addresses are 40, 41, 42, and 43). It cannot find the 5th sensor because there is no way to put voltage on the A0 and A1 pins to differentiate it from the other 4. Is there another way I can wire/program so that it can find all 5 sensors?

The second problem is getting the arduino to read from multiple sensors. I have found programs that read off of multiple heat sensors like a TC74. There are also programs for reading a single HDC100x, but not multiple. Specifically, I am looking for a way to call for the sensor by address and read its temperature.

Multiple sensors: http://www.electroschematics.com/9798/reading-temperatures-i2c-arduino/
Single HDC100x sensor: http://platformio.org/lib/show/1102/Adafruit-HDC1000





#include <Adafruit_HDC1000.h>
#include <Wire.h>


int add0 = 40;
int add1 = 41;
int add2 = 42;
int add3 = 43;

Adafruit_HDC1000 hdc = Adafruit_HDC1000();

void setup() {
  Serial.begin(9600);
  Wire.begin();     // create a wire object
}
 
void loop() {
  int c0 = read_temp(add0);
  delay(100);
  int c1 = read_temp(add1);
  delay(100);
  int c2 = read_temp(add2);
  delay(100);
  int c3 = read_temp(add3);
  delay(100); 
  Serial.print("Sensor 1: ");
  Serial.print(c0);
  Serial.print("C | ");
  Serial.print("Sensor 2: ");
  Serial.print(c1);
  Serial.print("C | ");
  Serial.print("Sensor 3: ");
  Serial.print(c2);   
  Serial.print("C");
  Serial.print("Sensor 1: ");
  Serial.print(c3);
  Serial.println("C | ");
  delay(500); 
}
 
int read_temp(int address) {
  //start the communication with IC with the address xx
  Wire.beginTransmission(address);
  //send a bit and ask for register zero
  Wire.write(0);
  //end transmission
  Wire.endTransmission();
  //request 1 byte from address xx
  Wire.requestFrom(address, hdc.readTemperature());
  //wait for response
  while(Wire.available() == 0);
  //put the temperature in variable c
  int c = Wire.read();   
  return c;
}

rocksdontfly

Update, a friend was able to figure out the code for the multiple readings:


/***************************************************
  This is an example for the HDC100x Humidity & Temp Sensor

  Designed specifically to work with the HDC1000 sensor from Adafruit
  ----> https://www.adafruit.com/products/2635

  These sensors use I2C to communicate, 2 pins are required to 
  interface
 ****************************************************/

#include <Wire.h>
#include "Adafruit_HDC1000.h"

// Connect Vin to 3-5VDC
// Connect GND to ground
// Connect SCL to I2C clock pin (A5 on UNO)
// Connect SDA to I2C data pin (A4 on UNO)

Adafruit_HDC1000 hdc = Adafruit_HDC1000();

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

Adafruit_HDC1000 hdc0 = Adafruit_HDC1000();
Adafruit_HDC1000 hdc1 = Adafruit_HDC1000();
Adafruit_HDC1000 hdc2 = Adafruit_HDC1000();
Adafruit_HDC1000 hdc3 = Adafruit_HDC1000();

void setup() {
  Serial.begin(9600);
  Serial.println("HDC100x test");

  if (!hdc0.begin(0x40)) {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
  if (!hdc1.begin(0x41)) {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
  if (!hdc2.begin(0x42)) {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
  if (!hdc3.begin(0x43)) {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
}


void loop() {
  Serial.print("Temp0: "); Serial.print(hdc0.readTemperature());
  Serial.print("\t\t temp1: "); Serial.print(hdc1.readTemperature());
  Serial.print("\t\t temp2: "); Serial.print(hdc2.readTemperature());
  Serial.print("\t\t temp3: "); Serial.println(hdc3.readTemperature());
  delay(500);
}

Go Up