Skip to content
  • MySensors
  • 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?

DHT22 lib working on 1Mhz?

Scheduled Pinned Locked Moved Development
15 Posts 6 Posters 8.1k 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
                • H Offline
                  H 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
                      • H Offline
                        H Offline
                        hek
                        Admin
                        wrote on last edited by
                        #11

                        Ok, thanks for the update.

                        1 Reply Last reply
                        0
                        • T Offline
                          T 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

                                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                With your input, this post could be even better 💗

                                Register Login
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                13

                                Online

                                12.0k

                                Users

                                11.2k

                                Topics

                                113.4k

                                Posts


                                Copyright 2025 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
                                • MySensors
                                • OpenHardware.io
                                • Categories
                                • Recent
                                • Tags
                                • Popular