1 2 Previous Next 15 Replies Latest reply on Nov 13, 2014 3:51 AM by AlexT_Intel

    DHT11 Temperature Sensor Issue

    Dan.McCulley

      I was trying to get a simple temperature sensor hooked up and working today on my Galileo using the standard libraries (https://www.virtuabotix.com/reference/index.php?title=DHT11_Wiki).

       

      I get a consistent sensor time out when using the Galileo.  Everything works fine when I switch back to the Arduino.

       

      Anyone have any guesses what might be wrong?dht11

        • 1. Re: DHT11 Temperature Sensor Issue
          ek

          I observed same problem. I tried several libraries including one in Arduino.cc without success. Arduino Playground - DHT11Lib

           

          Every time I try, Galileo times out and reports 0% humidity. DHT11 and Galileo are not communicating over serial line, correctly. Library modification is necessary. But, I don't know how. In general, timing critical serial communication do not work very well on Galileo.

           

          I hope somebody is aware of work around, since DHT11 is a popular humidity sensor (same problem on DHT22 and AM2302).

          • 2. Re: DHT11 Temperature Sensor Issue
            AlexT_Intel

            Hello everyone,

             

            Have you been able to solve this problem since then?

             

            Looking at the DHT11's datasheet (section 5.2) I see that the DHT11's response signal is 80us at low level and then 80us at high level. DHT11Lib ek is referring to uses two loops below to detect that:

             

            // ACKNOWLEDGE or TIMEOUT
            unsigned int loopCnt = 10000;
            while(digitalRead(pin) == LOW)
            if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
            
            loopCnt = 10000;
            while(digitalRead(pin) == HIGH)
            if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
            
            
            

             

            I don't have an actual sensor to try it live, but I suspected the digitalRead() may be taking too long compared to those 80us, so I've run a completely unscientific experiment of reading an unconnected pin on my Galileo many times and then averaging the time digitalRead() takes to return. The code is at the bottom of this post.

             

            And it turned out it's 2215 us. So my guess would be that the function is taking too long on Galileo, so it misses the DHT11's preamble.

            It would be highly interesting to see what this program says on the actual Arduino, where DHT11Lib does work. If it's less than those 80us - then my suspicion is true, if not - we've ruled out one possibility :-)

             

            Could someone give it a try to confirm or disprove my version of the root cause?

             

            On a side note, looking at the sources provided with Intel Arduino IDE, I see the following call chain for digitalRead:

            digitalRead (wiring_digital.c) -> sysfsGpioGet (sysfs.c) -> usual POSIX lseek() + read() pair.

            We could instrument these a little bit to see how much does each stage take, if my version of the root cause is confirmed. There's also some tracing facility I see there, which I couldn't get to output to Syslog right away :-), but I can dig further later.

             

            Sketch to measure how much time digitalRead() takes (you need to open the IDE's Serial Monitor within 5 seconds after starting the sketch to see the output), takes about a minute to run:

             

            An attempt to measure the time digitalRead() takes on Galileo

             

            Message was edited by: Alex T, Something wrong is going on here, trying to get past the message stuck in the "awaiting moderation" status + adjusted formatting.

            1 of 1 people found this helpful
            • 3. Re: DHT11 Temperature Sensor Issue
              Clayton Hofrock

              Running your test on one of my android compatible boards yeilds this output:

               

              Starting the loop...

              Ran digitalRead() 10000 times

              Overall duration: 40980 microseconds

              One digitalRead() duration (approximate, subject to micros() function limitations): 4 microseconds

              Finished

               

              In general, I think the Galileo has 100-1000x slower I/O speed. In this example it is ~500x slower which makes the sensor unusable. I hope there is a software fix for this.

               

              I have been playing with a python library that uses linux file accesses to control the GPIO pins (which are mapped to the Arduino pins) and with that library I get the same performance as running the Arduino sketch.

              1 of 1 people found this helpful
              • 4. Re: DHT11 Temperature Sensor Issue
                ek

                I agree with observatioins by Alex.T and Chofrock.

                 

                When I instrumented signal line between DHT11 and Galileo, DHT11 was trying to pull down the line, while Galileo was driving it up; causing the signal to go down only to the half. It was caused by the mechanism, Alex explained. I had given up using G. for my environmental sensor project.

                • 5. Re: DHT11 Temperature Sensor Issue
                  AlexT_Intel

                  @chofrock thanks for checking, yeah, so it's just taking too long, maybe because it goes through that  POSIX layer of file operations and that just takes its time. The python library is most probably using the same mechanism thus the same result.

                   

                  It would be interesting to see a comment from someone in Galileo team, if it's at all possible to do something with this (custom kernel driver? just some tuning of the call tree? just wild guesses).

                  1 of 1 people found this helpful
                  • 6. Re: DHT11 Temperature Sensor Issue
                    Bryan

                    After setting the pinmode from INPUT to INPUT_FAST, I get the following results:

                     

                    Starting the loop...

                    Ran digitalRead() 10000 times

                    Overall duration: 503572 microseconds

                    One digitalRead() duration (approximate, subject to micros() function limitations): 50 microseconds

                    Finished

                     

                    Does this resolve this issue?

                     

                    Im new to Arduino & Galileo, and even with PinMode set to INPUT_FAST & OUTPUT_FAST, I am still not able to get the DHT22 to work. Perhaps I am doing something incorrect, but I thought I would share my findings incase this helps someone else to get it to work. In that case, please share your code? Thanks!

                    • 7. Re: DHT11 Temperature Sensor Issue
                      AlexT_Intel

                      That's quite interesting information and definitely much better result, like 40x less.

                       

                      But I think it's still not enough. The sensor's preamble, per datasheet is 80us, 50 us is in the same ballpark and then I guess if Galileo needs to do some other actual work (all those things the library does in addition to just digitalRead()) it may get too close to those 80 to fail detection.

                       

                      And then that's just a preamble, looking further into the datasheet, I see that bit value "0" is 50us "low"+26-28us "high" - this is where it would fail anyway with those 50us achieved with INPUT_FAST. bit value "1" is a bit better - 50us "low"+70 us "high", but still too close.

                       

                      For robust detection the board's timing must be noticeably less than the sensor protocol timings. Like those 4us chofrock measured a couple of posts above.

                       

                      By the way, which pins have you connected the sensor to? I wonder if we could push it below 50us by using pins 2 and 3 (those right after UART TX & RX), which are connected directly to Quark and not to Cypress extender...

                      • 8. Re: DHT11 Temperature Sensor Issue
                        Bryan

                        Hi Alex, I happened to already be using pin2, so that's probably about as fast as it will get.

                         

                        I stumbled across the mentioning of INPUT_FAST in another forum posting. Do you know where I could find documentation for these sorts of things?

                         

                        BTW. Your description seems spot on as I think it is failing right where you said it would. If I remember correctly from last night, it failed on the second digital read ("while(digitalRead(pin) == HIGH)").

                        • 9. Re: DHT11 Temperature Sensor Issue
                          Bryan

                          I modified your test to run on all pins. Pins 2 & 3 were about 50us with INPUT_FAST and all the other pins were right about 2200us

                          • 10. Re: DHT11 Temperature Sensor Issue
                            AlexT_Intel

                            I see, good information. That INPUT_FAST rings a bell, but I don't seem to recall where I've seen that though :-) Apparently somewhere in the docs, which you can find in the Documentation section of this community.

                             

                            I'll look around and post back when I find that.

                            • 11. Re: DHT11 Temperature Sensor Issue
                              manoelramon

                              event FAST_INPUT or FAST_OUT put will make this library works.. I am trying to find a solution. If you need a temperature sensor I recommend use TMP35 that costs around 3 US$.

                               

                              http://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor

                               

                               

                              I try to see if we can speed up the pins 2 and 3 with mmap.

                              • 12. Re: DHT11 Temperature Sensor Issue
                                Alex_Ynema

                                What Library are you guys using I don't even get that far with the Galileo.

                                If I try and load the DHT library using the Intel Arduino IDE I get the following.

                                 

                                C:\Users\alex\Documents\Arduino\libraries\DHT_sensor_library\DHT.cpp: In member function 'boolean DHT::read()':
                                C:\Users\alex\Documents\Arduino\libraries\DHT_sensor_library\DHT.cpp:110:7: error: 'cli' was not declared in this scope
                                C:\Users\alex\Documents\Arduino\libraries\DHT_sensor_library\DHT.cpp:140:7: error: 'sei' was not declared in this scope
                                
                                • 13. Re: DHT11 Temperature Sensor Issue
                                  mmm

                                  Could you point me to the python library or any known working code in any language/script, please?  I have not been successful in finding any working solution to connecting a dht22 to the Galileo and I am about ready to give up on Galileo.   Thanks.

                                  • 14. Re: DHT11 Temperature Sensor Issue
                                    manoelramon

                                    I believe with current latencies in the IO will not work except if you change the ports. Even chaging the code to FAST input and output mode the speed necessary is not reached.

                                     

                                    Intel Galileo has two pins headers 2 and 3 connected directly to the SoC instead the Cypress.

                                     

                                    You need to reconfigure the kernel to support UIO and change the code to access the pin 2 and 3 using mmap(). You can read this article https://www.osadl.org/fileadmin/dam/rtlws/12/Koch.pdf

                                     

                                    If you will be able to do that when you will be able to communicate with this type of sensor…

                                     

                                    I would like to make this test but I believe I will have some time only in couple weeks.. you can use the TMP36 temporarily if you intention is only temperature. I got mine on ebay for 4 US$ and it is very easy to use and does not require any protocol using the digital IO.

                                     

                                     

                                    1 2 Previous Next