6 years, 2 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;
    myled1 = 0;
void blinkGreen()
    myled2 = 1;
    myled2 = 0; 

int main(void){
    int error = 0;
    float f =0.0f;
        error = sensor.readData();
        if (0 == error){
            f = sensor.ReadTemperature(FARENHEIT);
            serial.printf("It's Working!\r\n");
            serial.printf("Temperature: %4.2f\r\n",f);
        } else {
            serial.printf("Error: %d\r\n", error);

Question relating to:

1 Answer

5 years, 6 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 {

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!