Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 3 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:
1 Answer
9 years, 8 months 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.