Pages: [1]   Go Down
Author Topic: DHT22 not working with 8mhz clockspeed?  (Read 1241 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 252
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been unable to get the DHT22 temp/humid sensor to work at 8mhz on a homemade board... I know it works with my UNO, I know it works with my home made board at 16mhz... But I could not get it to work using the internal 8mhz clock or an external 8mhz crystal on the homebrewuino.

Again, 16mhz Uno and home brew works as intended. Without changing the wiring, I burn a 8mhz bootloader on the home brew and the sensor always reads 0% humidity, 0 degree temp without a "failed read" error. If I pull the signal pin, then I get a failed read error. So the sensor is getting sending information, just not the correct information.

I peeked into the library (adafruit DHT lib) and didn't see anything that would change performance based on clock speed... but then again, I'm a noob....

Thanks

-Rob
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you select the 8 MHz homebrewino board and upload the sketch again?  If you select a 16 MHz board and upload to an 8 MHz board it will run at half speed.  The calls to "delay()" and "delayMicroseconds()" will be slow and that might be enough to screw up the receive timing. 

The code (https://github.com/adafruit/DHT-sensor-library/blob/master/DHT.cpp) measures pulse widths and looks for a count > 6.  Perhaps that value will have to be adjusted down because the code outside the "delayMicroseconds(1)" is running slower.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Sr. Member
****
Karma: 0
Posts: 252
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe I did up-load the sktech after loading the bootloader. I can try it again.

I'm kinda confused with the fact that the mcu doesn't know that at 8mhz, one time unit will be twice the amount as 16mhz...

I'm going to go home and change the count > 6 to count > 3 for giggles and see what happens.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

> I'm kinda confused with the fact that the mcu doesn't know that at 8mhz, one time unit will be twice the amount as 16mhz...

The mcu doesn't know how fast it's running.   It thinks in instruction cycles.  Regardless of the clock rate each instruction takes the same number of instruction cycles so to the mcu it's all the same.

The Arduino core uses the F_CPU value set in boards.txt to measure time based on instruction cycles.

> I'm going to go home and change the count > 6 to count > 3 for giggles and see what happens.

Remember that "delayMicroseconds(1)" automatically adjusts when you switch from a 16 MHz Arduino to an 8 MHz one.  It's all the other instructions that will take twice as long.  Try values from 5 to 2 to see which ones give the desired results.  If more than one value gives the desired results, pick one in the middle.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

my DHT lib - http://arduino.cc/playground/Main/DHTLib - uses the micros() to measure the duration of pulses so it should be CPUclock insensitive in theory ...

(I crossposted this on another DHT thread 2 seconds ago)

Please let me know if it works.
Logged

Rob Tillaart

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 252
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the link! I will give it a try.

I DID get the adafruit lib working also.

solution:

Code:
Change this in DHT.cpp
// shove each bit into the storage bytes
      data[j/8] <<= 1;
      if (counter > 6)

To this
// shove each bit into the storage bytes
      data[j/8] <<= 1;
      if (counter > 3)
Logged

Bologna
Offline Offline
Newbie
*
Karma: 0
Posts: 42
L'anima sta all'uomo come l'uomo sta alla macchina
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you, adafruit's patch worked for me, too.
Logged

twitter: @shineangelic

Pages: [1]   Go Up
Jump to: