Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Adafruit_DHT_Driver incorrect readings on long wires (10m) using DHT11 + possible code fix #49

@the-red-o

Description

@the-red-o

Adafruit_DHT_Driver incorrect reading on long wires.

I had a problem reading the temperature and humidity from the DHT11 connected to the Raspberry Pi using wires of 10 meters. The temperature reading was way too small and the humidity was in the 120-150% ranges. Various DHT11 was tested all with the same problem.

I then used Saleae Logic 16 logic analyser to inspect the signals coming into the rapberry pi. The signals coming from the DHT11 was correct. Due to a very short pulse high created by the DHT11 after the 500ms high and 20ms low and timing issues in the current driver software the error occurs. The code appends a high bit (1) to the data stream and drops the last bit which causes the error. The short high pulse is 19us for the long wires and 12us for the DHT11 directly connected to the raspberry pi.
I was able to correct the problem by adding 7 usec sleep to Adafruit_DHT.c:

data[0] = data[1] = data[2] = data[3] = data[4] = 0;
// inserted to compensate for long driving lines
usleep(7);

// wait for pin to drop?
while (bcm2835_gpio_lev(pin) == 1) {
usleep(1);
}

I hope that the above information might be helpful to others experiencing the same issue. If the above solution can be tested, adjusted and verified for the DHT22 and AM2302 it might even be included in the source.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions