Go Down

Topic: Twin SHT21 sensors (Read 834 times) previous topic - next topic

mrjonny2

the code and design is from Misenso

Code: [Select]
/*
*  Read the relative humidity and temperature values from two SHT21 sensors
*  with JeeLabs "Ports" library used for software I2C:
*  http://cafe.jeelabs.net/sw/library_-_ports/
*
*/
#include <Ports.h>
#include "PortsSHT21.h"
SHT21 hsensor1 (1);
SHT21 hsensor2 (2);
float h, t;
void setup()
{
  Serial.begin(9600);
  Serial.println("Dual SHT21 Demo (softi2c)");
}
void loop()
{
  // Get data from first sensor
  Serial.print("Sensor1 - ");
  hsensor1.measure(SHT21::HUMI);
  hsensor1.measure(SHT21::TEMP);
  hsensor1.calculate(h, t);
   
  Serial.print("Humi(%RH): ");
  Serial.print(h, 1);
  Serial.print("   Temp(C): ");
  Serial.println(t, 1);
   
  // Get data from second sensor
  Serial.print("Sensor2 - ");
  hsensor2.measure(SHT21::HUMI);
  hsensor2.measure(SHT21::TEMP);
  hsensor2.calculate(h, t);
 
  Serial.print("Humi(%RH): ");
  Serial.print(h, 1);
  Serial.print("   Temp(C): ");
  Serial.println( t, 1);
  Serial.println();
 
  delay(4000);
}


http://www.misenso.com/prototyping/two-sht21-softi2c-arduino/76/


can someone break down the code and please explain what is going on?

PaulS

Quote
can someone break down the code and please explain what is going on?

Seems pretty straightforward to me. What part(s) don't you understand?

EmilyJane

Quote
I would like to add a second sensor but the SHT21s have fixed I2C addresses that are all the same.


In the example from the Misenso site, the sensors have their own pair of ports.

Go Up