DHT22 lib working on 1Mhz?



  • I tested a DHT22 clone with a ProMini (3.3V) using basically the Sensebender sketch which reduces clock frequency to 1Mhz.
    Without clock frequency reduction I get consistent readings from the DHT22 on 3.3V.
    When going down to 1MHz only the first couple of readings are ok then I get NaNs.
    Right now I am using the library from Mark Ruys.

    What library is known to work 1Mhz?

    Cheers,
    Thomas


  • Hero Member

    I'm working with the library that is provided with the mysensors download.
    Works with an internal clock set to 1 MHz for me.



  • Actually, I am using the same lib.
    I found a thread in the Arduino forum which explains that it can not work in principle: http://forum.arduino.cc/index.php?topic=291695.0

    Hmmm, quite interesting that it seems to work at least in certain cases.



  • how about 2 or 4MHz if 8 is too high?



  • @Stric said:

    how about 2 or 4MHz if 8 is too high?

    Will try and report back.



  • I tried it. Even on 4Mhz only the first 4 transmits show readings. Then it only returns errors.
    So it only work on 8Mhz for me.



  • So after 2 weeks fiddling around with the different libraries at different clock frequencies, I have some conclusions I would like to share with you.

    I tested with a ProMini and two DHT22 sensors, one from Adafruits and one from China.
    As I already reported, I had problems with clock frequencies below 8MHz with all different libraries. After switching to 8MHz, I realized another problem. Temperature readings did not change. They stayed the same value, only when I reset the ProMini I had a correct reading.
    I had this behaviour with the Adafruit and the library included in the MySensors project.

    Since yesterday evening I am testing the library from Rob Tillaart (http://arduino.cc/playground/Main/DHTLib) which is working correctly giving me correct readings.
    I am presuming that this is related to sleeping the ProMini and may be the low power mode the DHT22 is going into, I don't know...(at least in Rob's lib there is a wakeup delay which seems to address that point)

    Anyway, it seems I have at least now a working solution. I will re-try to lower the clock frequency with that library.

    Apart from that I also realized that the DHT library included in MySensor will perform a sensor read for a call to readTemperature and readHumidity which means that you would need to put a delay of 2s between a readTemperature and readHumidity. Since the sensor delivers the values in a "single" read this is rather unfortunate for battery powered sensor.


  • Admin

    If it verifies ok you could perhaps create a pull request with the new library and update the DHT example sketch accordingly?



  • Ok. I'll do that. Might however take a couple of days.



  • I retried again with Rob Tillaart's DHT22 library whether I can reduce clock frequency.
    The results:

    • 1 MHz -> wrong readings, like -100 C
    • 2 MHz -> "
    • 4 MHz -> from time to time wrong reading

    Overall, I would state that you need to run the DHT22 with the libraries I tested on 8 Mhz.


  • Admin

    Ok, thanks for the update.


  • Admin

    @tomkxy

    Are you compiling for the different clock frequencies in arduino? Or is it compiled for 8/16Mhz target, and then you switch frequency in the sketch?



  • I used the Sensebender sketch which switches in the sketch.



  • Sorry for a stupid question, but how do you run at 1 Mhz?
    See http://www.mysensors.org/hardware/micro#comment-2196823229
    Are you able to switch to 1 Mhz at runtime?



  • Have a look at the sensebender sketch http://www.mysensors.org/hardware/micro#example-sketch

     
      if ((measureCount == 5) && highfreq) 
      {
        clock_prescale_set(clock_div_8); // Switch to 1Mhz for the reminder of the sketch, save power.
        highfreq = false;
      } 
    
    

    The clock frequency is scaled down by software.


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 198
  • 10
  • 2
  • 5

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts