forked from winkj/arduino-sht
-
Notifications
You must be signed in to change notification settings - Fork 44
/
multiple-sht-sensors.ino
62 lines (52 loc) · 1.71 KB
/
multiple-sht-sensors.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Wire.h>
#include "SHTSensor.h"
// Note that all i2c devices sharing one bus must have distinct addresses. Thus
// this example only works with sensors that have distinct i2c addresses (e.g.
// SHT3x and SHT3x_alt, or SHT3x and SHTC3).
// Make sure not to use auto-detection as it will only pick up one sensor.
// Sensor with normal i2c address
// Sensor 1 with address pin pulled to GND
SHTSensor sht1(SHTSensor::SHT3X);
// Sensor with alternative i2c address
// Sensor 2 with address pin pulled to Vdd
SHTSensor sht2(SHTSensor::SHT3X_ALT);
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
delay(1000); // let serial console settle
// init on a specific sensor type (i.e. without auto detecting),
// does not check if the sensor is responding and will thus always succeed.
// initialize sensor with normal i2c-address
sht1.init();
// initialize sensor with alternative i2c-address
sht2.init();
}
void loop() {
// put your main code here, to run repeatedly:
// read from first sensor
if (sht1.readSample()) {
Serial.print("SHT1 :\n");
Serial.print(" RH: ");
Serial.print(sht1.getHumidity(), 2);
Serial.print("\n");
Serial.print(" T: ");
Serial.print(sht1.getTemperature(), 2);
Serial.print("\n");
} else {
Serial.print("Sensor 1: Error in readSample()\n");
}
// read from second sensor
if (sht2.readSample()) {
Serial.print("SHT2:\n");
Serial.print(" RH: ");
Serial.print(sht2.getHumidity(), 2);
Serial.print("\n");
Serial.print(" T: ");
Serial.print(sht2.getTemperature(), 2);
Serial.print("\n");
} else {
Serial.print("Sensor 2: Error in readSample()\n");
}
delay(1000);
}