RobTillaart / DHT20

Arduino library for DHT20 I2C temperature and humidity sensor.
MIT License
21 stars 6 forks source link

DHT20::read() Need Time out #12

Closed 1220951120 closed 1 year ago

1220951120 commented 1 year ago
int DHT20::read()
{
  //  do not read to fast == more than once per second.
  uint32_t temp ;
  if (millis() - _lastRead < 1000)
  {
    return DHT20_ERROR_LASTREAD;
  }

  int status = requestData();
  if (status < 0) return status;
  //  wait for measurement ready
  temp = millis();
  while (isMeasuring())
  {
    if(millis()-temp >=1000)
    {
      Serial.print("DHT20 Time Out\n");
      return 0;
    }
    yield();
  }
  //  read the measurement
  status = readData();
  if (status < 0) return status;

  //  convert it to meaningful data
  return convert();
}

Thanks!

(updated code tags for syntax highlighting)

RobTillaart commented 1 year ago

Thanks for the issue. What is the problem exactly? What platform(s) did it occur?

RobTillaart commented 1 year ago

Note: Error code is already defined: DHT20_ERROR_READ_TIMEOUT in the DHT20.h file

But it should be not -14 but e.g. -300 as it should be clear it is an invalid temperature..

RobTillaart commented 1 year ago

Fixed in 0.2.3 release