Pages: 1 ... 6 7 [8]   Go Down
Author Topic: Class for DHT11, DHT21 and DHT22 (temperature & humidity)  (Read 57953 times)
0 Members and 2 Guests are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sure I'm doing something stupid but I've ran out of sensible ideas now  smiley-confuse

Hardware
Arduino 2560
RHT03
10k resistor
I'm using the adafruit wiring to link a RHT03 (DHT22) to my 2560.
  • 5v pin for power
  • Gnd for ground
  • pin 23 for IO (also tried 22 and 24)
  • signal and 5v connect via 10k

Software
I am using the example code from within the github examples folder apart from the default switch clause will print the chk value also. I have also changed the timeout values within dht.cpp to be different to allow me to see where its failing.

Code:
while(digitalRead(pin) == LOW)
{
  if (--loopCnt == 0) return -100; //DHTLIB_ERROR_TIMEOUT;
}

loopCnt = DHTLIB_TIMEOUT;
while(digitalRead(pin) == HIGH)
{
  if (--loopCnt == 0) return -101; //DHTLIB_ERROR_TIMEOUT;
}

// READ THE OUTPUT - 40 BITS => 5 BYTES
for (uint8_t i = 40; i != 0; i--)
{
  loopCnt = DHTLIB_TIMEOUT;
  while(digitalRead(pin) == LOW)
  {
    if (--loopCnt == 0) return -102; //DHTLIB_ERROR_TIMEOUT;
  }

  uint32_t t = micros();

  loopCnt = DHTLIB_TIMEOUT;
  while(digitalRead(pin) == HIGH)
  {
    if (--loopCnt == 0) return -103; //DHTLIB_ERROR_TIMEOUT;
  }

  if ((micros() - t) > 40)
  {
    bits[idx] |= mask;
  }
  mask >>= 1;
  if (mask == 0)   // next byte?
  {
    mask = 128;
    idx++;
  }
}

I am never receiving a reading only timeout values and the timeout values fluctuate pattern wise.
I receive two patterns of four readings but these patterns do not have an occurrence pattern.
Quote
Unknown -101 -999.0% -999.0*C
Unknown -101 -999.0% -999.0*C
Unknown -101 -999.0% -999.0*C
Unknown -102 -999.0% -999.0*C
Quote
Unknown -101 -999.0% -999.0*C
Unknown -101 -999.0% -999.0*C
Unknown -102 -999.0% -999.0*C
Unknown -102 -999.0% -999.0*C

I'm going to get the multimeter out now and see if I can see anything weird but I'm just losing hope now.
Any ideas what could be inhibiting?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13903
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how long are your wires?

The 5V pin of the DHT22 should be connected directly to 5V  not through a 10K

only the data line needs a 10K pullup (if lines are > 1 meter a 4K7 could be used.)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Solved it within a few minutes of getting out the multimeter  smiley
Thank you Rob

You were right to suspect power with the leads and such.
Leads are 10cm from power pins to breadboard then another 10cm to DHT22.
10k is connected between power line and signal only.
The arduino is running over USB which I thought maybe a problem but it is producing 5.3V directly (not sure how that works  smiley-eek ). I've  found that my breadboard has rather high resistance along its power tracks (~10M) so I've moved the wires on the breadboard to be closer together rather than trust the rail to provide power properly.

So if DHTLib is producing nothing but timeout errors and you know everything is connected right and you are using an example sketch CHECK voltage at the chip.
Logged

Pages: 1 ... 6 7 [8]   Go Up
Jump to: