winlinvip / SimpleDHT

Simple, Stable and Fast Arduino Temp & Humidity Sensors for DHT11 and DHT22. http://learn.adafruit.com/dht
MIT License
144 stars 61 forks source link

read2( ) which uses float temperature and humidity only return integer values. #54

Open DaleSchultz opened 1 year ago

DaleSchultz commented 1 year ago

I noticed that there are read2( ) functions that take float arguments.

I tried them but I only get integer results even though the DHT11 has a resolution of 0.1°C

This shows the issue:

#include <SimpleDHT.h>

void setup() {

  Serial.begin(115200);
  Serial.println(); 
}

void loop() {

    float temperature = 0;
    float humidity = 0;

  SimpleDHT11 dht11(-1);
    int err;
  if (dht11.read2(14, &temperature, &humidity, NULL) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err));
    //Serial.print(","); Serial.println(SimpleDHTErrDuration(err));

  }

  Serial.print(temperature); Serial.print("°C  ");Serial.print(humidity);Serial.println("%");
  delay (1500);
}