Pages: [1]   Go Down
Author Topic: Twin SHT21 sensors  (Read 816 times)
0 Members and 1 Guest are viewing this topic.
London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 190
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the code and design is from Misenso

Code:
/*
*  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?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 654
Posts: 50928
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: