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, 10 months ago.
Using Arch GPRS V2, and the DHT library, Having trouble configuring DHT22 sensor
I'm using the SEN51035P, Grove - Temperature&Humidity Sensor Pro (Seeed Studio) and an Arch GPRS V2 mbed development board.
My output is error 7 = no_patience. I'm using the code below. Any insight or suggestions?
include the mbed library with this snippet
#include "mbed.h"
#include "USBSerial.h"
#include "DHT.h"
USBSerial serial;
// defines internal LEDS
DigitalOut myled1(LED2);
DigitalOut myled2(LED3);
DHT sensor(P0_4 , 22);
void blinkRed()
{
myled1 = 1;
wait(1);
myled1 = 0;
wait(1);
}
void blinkGreen()
{
myled2 = 1;
wait(1);
myled2 = 0;
wait(1);
}
int main(void){
int error = 0;
float f =0.0f;
while(1){
wait(5);
error = sensor.readData();
if (0 == error){
blinkGreen();
f = sensor.ReadTemperature(FARENHEIT);
serial.printf("It's Working!\r\n");
serial.printf("Temperature: %4.2f\r\n",f);
} else {
blinkRed();
serial.printf("Error: %d\r\n", error);
}
}
}
Question relating to:
1 Answer
10 years, 2 months ago.
Hi Michael,
Not sure if this question is still active but I just ran into the same problem today.
The problem I had was that the time library does not seem to work on Arch GPRS V2. Inside DHT.cpp you will see:
time_t currentTime = time(NULL);
DigitalInOut DHT_io(_pin);
for (i = 0; i < DHT_DATA_BIT_COUNT; i++) {
bitTimes[i] = 0;
}
if (!_firsttime) {
if (int(currentTime - _lastReadTime) < 2) {
err = ERROR_NO_PATIENCE;
return err;
}
} else {
_firsttime=false;
_lastReadTime=currentTime;
}
So it is checking that currentTime is at least two seconds after _lastReadTime. It does this with the time function. I don't know the details of this function, or its library, or how it works on other platforms... but I do know it just does not work on my Arch GPRS V2. Regular printouts show that it just stays on 0. Now, 0 - 0 = 0 < 2, so the check will always fail and you will get ERROR_NO_PATIENCE.
(Actually, the first time it runs, you will probably get a different error, due to the _firsttime check.)
I got around this by commenting out the check. A bit dirty but it will do the job for the moment!