Pages: [1]   Go Down
Author Topic: DHT22 Timeout error - Digistump Digix with level-shifter  (Read 950 times)
0 Members and 1 Guest are viewing this topic.
Indianapolis, IN USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am having timeout issue with DHT22 sensor.  Sensor is connected to 5 volts on pin 1, pin 2 has 10K ohm resistor connected to pin 1 --pin 2 output goes to A3 on level-shifter.  There is no connection on pin 3, and pin 4 is grounded.

Sensor is known good; works correctly on Arduino Mega 2560.  Humidity and Temperature readings are correct on the Mega.

Digistump Digix   84 MHz Clock Speed
32-bit ARM Processor (AT91SAM3X8E)

Wondering if there has to be library modifications...  I have tried idDHTlib and Adafruit Unified BMP025 libraries.  Both produce timeout error messages.

William
Logged

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

- http://playground.arduino.cc/Main/DHTLib -
is confirmed to work on a DUE, which is also 84Mhz

please let me know if it works/fails.
Logged

Rob Tillaart

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

Indianapolis, IN USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My apologizes for not proofing my post.

Should have stated robtillaart's DHTlib, instead of the Adafruit_BMP085_unified library.  Both idDHTlib and DHTlib (V1.08 dated Jan. 2014) produce timeout error and no readings, just the error message.

Unknown if related; I am using the Digistump Level-Shifter Shield with the Digistump Digix.  Wondering if the Level-Shifter sheild is affecting rise and fall timing of the data signal  --I am no expert on data signals.

DHT22 sensor works correctly with earlier DHT library for Arduino Uno with an Arduino Mega 2560.  No Level-Shifter Sheild.

update 2/5/2014:  Tried without Level-Shifting Shield @ 3.3 volts;  same, time out error message.

William
« Last Edit: February 05, 2014, 09:40:39 am by Techno500 » Logged

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

possible cause:

can you test/print in a sketch the value of  (F_CPU/1600) 

The code uses F_CPU/1600 to calculate the timeout, if there is no F_CPU it will return 0 causing a timeout.

can you report?



Logged

Rob Tillaart

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

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



a quick look at the core files of the digistamp shows that the digistump has a -  SystemCoreClock - variable

you might try to change the line (in the .cpp file of my lib)

Code:
#define TIMEOUT (F_CPU/1600)

to

Code:
#define TIMEOUT (SystemCoreClock /1600)
Logged

Rob Tillaart

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

Indianapolis, IN USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
can you test/print in a sketch the value of  (F_CPU/1600)
   Returns value 52500.

Will modify .cpp of your library to: 
Quote
#define TIMEOUT (SystemCoreClock /1600)

William
Logged

Indianapolis, IN USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
you might try to change the line (in the .cpp file of my lib)

Code:

#define TIMEOUT (F_CPU/1600)


to

Code:

#define TIMEOUT (SystemCoreClock /1600)

Made the above modification to dht.cpp code.

Ran your example:  dht22_test.ino; still producing Time Out Error
Logged

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

Quote
can you test/print in a sketch the value of  (F_CPU/1600)
   Returns value 52500.
That indicates that F_CPU is supported and 52500  should be a good value.

Analysis version of the read function. I replaced all TIME_OUT with an unique number.

Can you please report which number it returns so we can see where it timeouts in the library

Code:
// return values:
// DHTLIB_OK
// DHTLIB_ERROR_TIMEOUT
int dht::read(uint8_t pin)
{
// INIT BUFFERVAR TO RECEIVE DATA
uint8_t cnt = 7;
uint8_t idx = 0;

// EMPTY BUFFER
for (uint8_t i=0; i< 5; i++) bits[i] = 0;

// REQUEST SAMPLE
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
delay(20);
digitalWrite(pin, HIGH);
delayMicroseconds(40);
pinMode(pin, INPUT);

    // TODO rewrite with miros()?
// GET ACKNOWLEDGE or TIMEOUT
unsigned int loopCnt = TIMEOUT;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return -100;

loopCnt = TIMEOUT;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return -101;

// READ THE OUTPUT - 40 BITS => 5 BYTES
for (uint8_t i=0; i<40; i++)
{
loopCnt = TIMEOUT;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return -102;

unsigned long t = micros();

loopCnt = TIMEOUT;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return -103;

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

return DHTLIB_OK;
}
//
// END OF FILE
//

The real solution should be a microseconds based TIMEOUT, need some time to write that.
Logged

Rob Tillaart

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

Indianapolis, IN USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does this code go into the .cpp library file?  Does it replace code or is it additional code?  Nothing different, than when I run DHT@@_test.ino example. -- "DHT22 ,Time out error -999.0 -999.0"

Not sure if what I tried with this code, is what you want...  Please clarify.

Willing to help, thank you for taking time to look into this issue.

William
Logged

Indianapolis, IN USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

digistump, over @ Digix Digistump forum suggested trying DHT22 at 3.3 Volts without Level-Shifter Shield --it works.   

Put the Level-Shifter Shield back on the Digix with the I2C bus and DHT22 connected to the Level-Shifter Shield.  DHT22 produces Time out error.  I2C bus is working with DS1307 and BMP085 attached.

@robtillaart

If I can still be of assistance trying code, I will be happy to test code.

William


* Reply_digistump.JPG (42.13 KB, 546x415 - viewed 27 times.)
Logged

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

digistump, over @ Digix Digistump forum suggested trying DHT22 at 3.3 Volts without Level-Shifter Shield --it works.   

Put the Level-Shifter Shield back on the Digix with the I2C bus and DHT22 connected to the Level-Shifter Shield.  DHT22 produces Time out error.  I2C bus is working with DS1307 and BMP085 attached.

@robtillaart

If I can still be of assistance trying code, I will be happy to test code.

William
Good to hear it now works, So you confirm that the dhtlib works as is with the digistump, at least I can add that to the article and reference this thread.

but still strange that the level shifter corrupts the signal.
What is the type of level shifter?
is it possibly a one way device?

Thanks for the offer to test, I appreciate the offer and  I'll make a mental note. The easiest way to know there is a new version of the DHTlib  is to clock notify on this thread .



Logged

Rob Tillaart

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

Indianapolis, IN USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Good to hear it now works, So you confirm that the dhtlib works as is with the digistump, at least I can add that to the article and reference this thread.

but still strange that the level shifter corrupts the signal.
What is the type of level shifter?
is it possibly a one way device?

Link to Digistump Level-Shifter Shield:  http://digistump.com/wiki/digix/tutorials/levelshifter

Shield has both input and output capabilities, as I understand.  There is a tutorial at the above link on the Digistump Level-Shifter Shield.

I do not have the specifications or data sheets to provide more details.

William

Logged

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

from the link you send.
Note: The Level Shifter shield is not capable of high current output and is not suitable for driving LEDs and similar.
So the sensor might not be triggered due to this; could explain it all.
Logged

Rob Tillaart

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

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

added a link to this thread in the playground article - http://playground.arduino.cc//Main/DHTLib -
Logged

Rob Tillaart

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

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

@techno500
I am investigating some timing issues in the dht library and I would ask you to do a small test.

in dht.cpp there is a line delay(20)
can you replace that with delay(1)
and check if it still works?

I did this on my UNO - DHT22 (short 10 cm wires) and the sensor still works.

Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: