@@ -51,13 +51,14 @@ bool SHTSensorDriver::readSample()
5151// class SHTI2cSensor
5252//
5353
54- const uint8_t SHTI2cSensor::CMD_SIZE = 2 ;
55- const uint8_t SHTI2cSensor::EXPECTED_DATA_SIZE = 6 ;
54+ const uint8_t SHTI2cSensor::CMD_SIZE = 2 ;
55+ const uint8_t SHTI2cSensor::EXPECTED_DATA_SIZE = 6 ;
5656
5757bool SHTI2cSensor::readFromI2c (uint8_t i2cAddress,
5858 const uint8_t *i2cCommand,
5959 uint8_t commandLength, uint8_t *data,
60- uint8_t dataLength)
60+ uint8_t dataLength,
61+ uint8_t duration)
6162{
6263 Wire.beginTransmission (i2cAddress);
6364 for (int i = 0 ; i < commandLength; ++i) {
@@ -70,6 +71,8 @@ bool SHTI2cSensor::readFromI2c(uint8_t i2cAddress,
7071 return false ;
7172 }
7273
74+ delay (duration);
75+
7376 Wire.requestFrom (i2cAddress, dataLength);
7477
7578 // check if the same number of bytes are received that are requested.
@@ -113,7 +116,7 @@ bool SHTI2cSensor::readSample()
113116 cmd[1 ] = mI2cCommand & 0xff ;
114117
115118 if (!readFromI2c (mI2cAddress , cmd, CMD_SIZE, data,
116- EXPECTED_DATA_SIZE)) {
119+ EXPECTED_DATA_SIZE, mDuration )) {
117120 return false ;
118121 }
119122
@@ -144,8 +147,8 @@ class SHTC1Sensor : public SHTI2cSensor
144147{
145148public:
146149 SHTC1Sensor ()
147- // Using clock stretching, high precision, T first
148- : SHTI2cSensor(0x70 , 0x7ca2 , -45 , 175 , 65535 , 100 , 65535 )
150+ // clock stretching disabled , high precision, T first
151+ : SHTI2cSensor(0x70 , 0x7866 , 15 , -45 , 175 , 65535 , 100 , 65535 )
149152 {
150153 }
151154};
@@ -158,16 +161,21 @@ class SHTC1Sensor : public SHTI2cSensor
158161class SHT3xSensor : public SHTI2cSensor
159162{
160163private:
161- static const uint16_t SHT3X_ACCURACY_HIGH = 0x2c06 ;
162- static const uint16_t SHT3X_ACCURACY_MEDIUM = 0x2c0d ;
163- static const uint16_t SHT3X_ACCURACY_LOW = 0x2c10 ;
164+ static const uint16_t SHT3X_ACCURACY_HIGH = 0x2400 ;
165+ static const uint16_t SHT3X_ACCURACY_MEDIUM = 0x240b ;
166+ static const uint16_t SHT3X_ACCURACY_LOW = 0x2416 ;
167+
168+ static const uint8_t SHT3X_ACCURACY_HIGH_DURATION = 15 ;
169+ static const uint8_t SHT3X_ACCURACY_MEDIUM_DURATION = 6 ;
170+ static const uint8_t SHT3X_ACCURACY_LOW_DURATION = 4 ;
164171
165172public:
166173 static const uint8_t SHT3X_I2C_ADDRESS_44 = 0x44 ;
167174 static const uint8_t SHT3X_I2C_ADDRESS_45 = 0x45 ;
168175
169176 SHT3xSensor (uint8_t i2cAddress = SHT3X_I2C_ADDRESS_44)
170177 : SHTI2cSensor(i2cAddress, SHT3X_ACCURACY_HIGH,
178+ SHT3X_ACCURACY_HIGH_DURATION,
171179 -45 , 175 , 65535 , 100 , 65535 )
172180 {
173181 }
@@ -177,12 +185,15 @@ class SHT3xSensor : public SHTI2cSensor
177185 switch (newAccuracy) {
178186 case SHTSensor::SHT_ACCURACY_HIGH:
179187 mI2cCommand = SHT3X_ACCURACY_HIGH;
188+ mDuration = SHT3X_ACCURACY_HIGH_DURATION;
180189 break ;
181190 case SHTSensor::SHT_ACCURACY_MEDIUM:
182191 mI2cCommand = SHT3X_ACCURACY_MEDIUM;
192+ mDuration = SHT3X_ACCURACY_MEDIUM_DURATION;
183193 break ;
184194 case SHTSensor::SHT_ACCURACY_LOW:
185195 mI2cCommand = SHT3X_ACCURACY_LOW;
196+ mDuration = SHT3X_ACCURACY_LOW_DURATION;
186197 break ;
187198 default :
188199 return false ;
0 commit comments