Go Down

Topic: DHT22 Timeout error - Digistump Digix with level-shifter (Read 1 time) previous topic - next topic

Techno500

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

robtillaart

- 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.
Rob Tillaart

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

Techno500

#2
Feb 05, 2014, 01:58 am Last Edit: Feb 05, 2014, 03:40 pm by Techno500 Reason: 1
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

robtillaart

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?



Rob Tillaart

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

robtillaart



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: [Select]
#define TIMEOUT (F_CPU/1600)

to

Code: [Select]
#define TIMEOUT (SystemCoreClock /1600)
Rob Tillaart

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

Techno500

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

Techno500

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

robtillaart


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: [Select]

// 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.
Rob Tillaart

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

Techno500

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

Techno500

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

robtillaart


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 .



Rob Tillaart

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

Techno500

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


robtillaart

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.
Rob Tillaart

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

robtillaart

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

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

robtillaart

@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.

Rob Tillaart

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

Go Up