|
| 1 | +// |
| 2 | +// FILE: SHT31_two_I2C.ino |
| 3 | +// AUTHOR: Rob Tillaart |
| 4 | +// VERSION: 0.1.0 |
| 5 | +// PURPOSE: demo |
| 6 | +// URL: https://github.com/RobTillaart/SHT31 |
| 7 | +// |
| 8 | +// NOTE: see issue #22 for details |
| 9 | +// originally written for a ATSAMD21G18A custom board. |
| 10 | +// |
| 11 | + |
| 12 | + |
| 13 | +#include "Wire.h" |
| 14 | +#include "SHT31.h" |
| 15 | + |
| 16 | + |
| 17 | +TwoWire myWire(&sercom5, 0, 1); |
| 18 | +// TwoWire myWire = Wire1; // test. |
| 19 | + |
| 20 | + |
| 21 | +// note: address reuse on second I2C bus |
| 22 | +#define SHT31_ADDRESS_1 0x44 |
| 23 | +#define SHT31_ADDRESS_2 0x45 |
| 24 | +#define SHT31_ADDRESS_3 0x44 |
| 25 | +#define SHT31_ADDRESS_4 0x45 |
| 26 | + |
| 27 | + |
| 28 | +SHT31 sht_1; |
| 29 | +SHT31 sht_2; |
| 30 | +SHT31 sht_3; |
| 31 | +SHT31 sht_4; |
| 32 | + |
| 33 | + |
| 34 | +bool b1, b2, b3, b4; |
| 35 | + |
| 36 | + |
| 37 | +void setup() |
| 38 | +{ |
| 39 | + Serial.begin(115200); |
| 40 | + Serial.println(__FILE__); |
| 41 | + Serial.print("SHT31_LIB_VERSION: \t"); |
| 42 | + Serial.println(SHT31_LIB_VERSION); |
| 43 | + |
| 44 | + Wire.begin(); |
| 45 | + Wire.setClock(100000); |
| 46 | + myWire.begin(); |
| 47 | + myWire.setClock(100000); |
| 48 | + |
| 49 | + // see datasheet for details |
| 50 | + pinPeripheral(0, PIO_SERCOM_ALT); |
| 51 | + pinPeripheral(1, PIO_SERCOM_ALT); |
| 52 | + |
| 53 | + b1 = sht_1.begin(SHT31_ADDRESS_1, &Wire); |
| 54 | + b2 = sht_2.begin(SHT31_ADDRESS_2, &Wire); |
| 55 | + b3 = sht_3.begin(SHT31_ADDRESS_3, &myWire); |
| 56 | + b4 = sht_4.begin(SHT31_ADDRESS_4, &myWire); |
| 57 | + |
| 58 | + // see if they are connected |
| 59 | + Serial.print("BEGIN:\t"); |
| 60 | + Serial.print(b1); |
| 61 | + Serial.print("\t"); |
| 62 | + Serial.print(b2); |
| 63 | + Serial.print("\t"); |
| 64 | + Serial.print(b3); |
| 65 | + Serial.print("\t"); |
| 66 | + Serial.print(b4); |
| 67 | + Serial.print("\t"); |
| 68 | + Serial.println(); |
| 69 | +} |
| 70 | + |
| 71 | + |
| 72 | +void loop() |
| 73 | +{ |
| 74 | + // read all sensors that are found |
| 75 | + if (b1) sht_1.read(); |
| 76 | + if (b2) sht_2.read(); |
| 77 | + if (b3) sht_3.read(); |
| 78 | + if (b4) sht_4.read(); |
| 79 | + |
| 80 | + Serial.print(sht_1.getTemperature(), 1); |
| 81 | + Serial.print("\t"); |
| 82 | + Serial.print(sht_2.getTemperature(), 1); |
| 83 | + Serial.print("\t"); |
| 84 | + Serial.print(sht_3.getTemperature(), 1); |
| 85 | + Serial.print("\t"); |
| 86 | + Serial.print(sht_4.getTemperature(), 1); |
| 87 | + Serial.print("\t"); |
| 88 | + Serial.print(sht_1.getHumidity(), 1); |
| 89 | + Serial.print("\t"); |
| 90 | + Serial.print(sht_2.getHumidity(), 1); |
| 91 | + Serial.print("\t"); |
| 92 | + Serial.print(sht_3.getHumidity(), 1); |
| 93 | + Serial.print("\t"); |
| 94 | + Serial.print(sht_4.getHumidity(), 1); |
| 95 | + Serial.println(); |
| 96 | + |
| 97 | + delay(1000); |
| 98 | +} |
| 99 | + |
| 100 | +// -- END OF FILE -- |
0 commit comments