Skip to content

Commit 386efbc

Browse files
JHahn96abrauchli
authored andcommitted
Usage with multiple Sensors
* add sample code with description to README * sample code shows how to connect two SHT31 sensors
1 parent e8095e7 commit 386efbc

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,62 @@ void loop() {
6767
delay(1000);
6868
}
6969
```
70+
71+
### Usage with two SHT31 sensors
72+
73+
```c++
74+
#include <Wire.h>
75+
#include "SHTSensor.h"
76+
77+
// Sensor with normal i2c address
78+
// Sensor 1 with address pin pulled to GND
79+
SHTSensor sht1(SHTSensor::SHT3X);
80+
81+
// Sensor with alternative i2c address
82+
// Sensor 2 with address pin pulled to Vdd
83+
SHTSensor sht2(SHTSensor::SHT3X_ALT);
84+
85+
void setup() {
86+
// put your setup code here, to run once:
87+
Wire.begin();
88+
Serial.begin(9600);
89+
delay(1000); // let serial console settle
90+
91+
// init on a specific sensor type (i.e. without auto detecting),
92+
// does not check if the sensor is responding and will thus always succeed.
93+
94+
// initialize sensor with normal i2c-address
95+
sht1.init();
96+
97+
// initialize sensor with alternative i2c-address
98+
sht2.init();
99+
}
100+
void loop() {
101+
// put your main code here, to run repeatedly:
102+
// read from first sensor
103+
if (sht1.readSample()) {
104+
Serial.print("SHT1 :\n");
105+
Serial.print(" RH: ");
106+
Serial.print(sht1.getHumidity(), 2);
107+
Serial.print("\n");
108+
Serial.print(" T: ");
109+
Serial.print(sht1.getTemperature(), 2);
110+
Serial.print("\n");
111+
} else {
112+
Serial.print("Sensor 1: Error in readSample()\n");
113+
}
114+
// read from second sensor
115+
if (sht2.readSample()) {
116+
Serial.print("SHT2:\n");
117+
Serial.print(" RH: ");
118+
Serial.print(sht2.getHumidity(), 2);
119+
Serial.print("\n");
120+
Serial.print(" T: ");
121+
Serial.print(sht2.getTemperature(), 2);
122+
Serial.print("\n");
123+
} else {
124+
Serial.print("Sensor 2: Error in readSample()\n");
125+
}
126+
delay(1000);
127+
}
128+
```

0 commit comments

Comments
 (0)