8 years, 9 months ago.

Continiuos Error code 2

I use Nucleo F072RB, and Am2302 sensor. Updated DHT library causes continuous Err 2. Previous version of library DHT works sometimes but often results in Err 6. The code I used is:

main.cpp

#include "mbed.h"
#include "DHT.h"
 
DigitalOut myled(LED1);
 
DHT sensor(D7,AM2302); // Use the AM2302 sensor
 
int main() {
    int err;
    printf("\r\nDHT Test program");
    printf("\r\n******************\r\n");
    wait(1); // wait 1 second for device stable status
    while (1) {
        myled = 1;
        err = sensor.readData();
        if (err == 0) {
            printf("Temperature is %4.2f C \r\n",sensor.ReadTemperature(CELCIUS));
            printf("Humidity is %4.2f \r\n",sensor.ReadHumidity());
        } else
            printf("\r\nErr %i \n",err);
        myled = 0;
        wait(2);
    }
}

Any ideas how to improve this error?

Question relating to:

/ DHT
Temp and Humidity sensor device driver. DHT11, DHT22

1 Answer

8 years, 1 month ago.

Hi Aleksander,

Im Renan from Brazil, some days ago a have the same problem. But i found a solution by looking the library and the datasheet of this sensor.

i have change the wait(1) for wait_us(500) in line 81 of dht.cpp, and my problem is solved.