Skip to content
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. DHT22 lib working on 1Mhz?
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

DHT22 lib working on 1Mhz?

Scheduled Pinned Locked Moved Development
15 Posts 6 Posters 7.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tomkxy
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TimO
      Hero Member
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tomkxy
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Stric
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tomkxy
            wrote on last edited by
            #5

            @Stric said:

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

            Will try and report back.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tomkxy
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tomkxy
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                1
                • hekH Offline
                  hekH Offline
                  hek
                  Admin
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tomkxy
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      tomkxy
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • hekH Offline
                        hekH Offline
                        hek
                        Admin
                        wrote on last edited by
                        #11

                        Ok, thanks for the update.

                        1 Reply Last reply
                        0
                        • tbowmoT Offline
                          tbowmoT Offline
                          tbowmo
                          Admin
                          wrote on last edited by
                          #12

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

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            tomkxy
                            wrote on last edited by
                            #13

                            I used the Sensebender sketch which switches in the sketch.

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              tlustoch
                              wrote on last edited by
                              #14

                              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?

                              1 Reply Last reply
                              0
                              • T Offline
                                T Offline
                                tomkxy
                                wrote on last edited by
                                #15

                                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.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                14

                                Online

                                11.7k

                                Users

                                11.2k

                                Topics

                                113.0k

                                Posts


                                Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • OpenHardware.io
                                • Categories
                                • Recent
                                • Tags
                                • Popular