SolderedElectronics / SHT21-Arduino-Library

Arduino library for SHT21 - temperature and humidity sensor. With checksum!
7 stars 11 forks source link

SHT reset error #5

Closed felixNilo closed 3 years ago

felixNilo commented 3 years ago

Hello. I'm working in a greenhouse automation system and using the SHT21 sensor in order to get the inside temperature and humidity. After several hours of getting measures, the sensor stops work sending the same measure, so I added a code block that reviews if is the sensor is sending the same measure. If is true I reset using the funcion of the library. I'm using Arduino DUE to read the sensor via I2C. The code block that I'm using to get the airTemperature is the following one:

` void getAirTemperature() {

  float aux = sht.getTemperature();
  delay(80); // only 45 ms is needed
  if (aux < 0) { //If the sensor disconnect by error
    sht.reset();
    delay (20);
  } else airTemperature = aux;  // get temp from SHT

  checkSensor(aux);

}`

The checkSensor funcion sned the measure to a buffer array as follows:

` void checkSensor(float measure) {

  shtBuffer[auxBuffer] = measure;
  if (isBugged()) {
    sht.reset();
    Serial.println("Reseting SHT");
    }
    delay(20);
  }
  auxBuffer += 1;
  if (auxBuffer > 9) auxBuffer = 0; //The array is initialized with a length of 10 so the last index is 9.
}`

The isBugged function, review the buffer, if the buffer has the same values returns a true, in other case returns a false.

boolean isBugged() { //Serial.println("Checking"); for (int i = 1 ; i < 10 ; i++) { if (shtBuffer[i - 1] != shtBuffer[i]) return false; } return true; }

The logic is working, in fact, the arduino tries to reset the SHT via the function, but it does not work. I have seen that if I reset the arduino the SHT starts working again, or if I disconnect the sensor and reconnect again, the sensor also start working.

Maybe the resetting function is not working?

Thank you guys.

PericR commented 3 years ago

Hello, I checked file sht21.cpp and it seams that reset function should work correctly, it only sends reset command using I2C and waits 15ms like it should according to datasheet.

https://github.com/e-radionicacom/SHT21-Arduino-Library/blob/master/SHT21.cpp#L39

Could it be that sensor isn't working properly?

PericR commented 3 years ago

Hello, I'm gonna close this now due to inactivity.