1 2 Previous Next 29 Replies Latest reply on Sep 1, 2015 9:25 AM by mdanaher

    DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one

    DinoT_Intel

      The main reason the DHT temperature and humidity sensor does not work with the Galileo is because of the tight requirements of one-wire device like the DHT11 and DHT22 sensors.

       

      With just one wire, DHT and many other one-wire devices will not work with the Galileo because the Galileo takes too much time when switching a pin from one direction to another.

      This is because the Galileo uses IO expanders for the gpio that controls the pin direction and those IO expanders are connected to the Galileo via I2C.

       

      One way to get the Galileo to play well with one-wire devices is to use two wires. One dedicated for INPUT and another for OUTPUT.

      The workaround I am going to use only requires one extra hardware, a diode.

       

       

      DHTGal.PNG

      For this example, pin2 is connected to the DHT11.

      Cathode of the diode is connected to pin3.

      Anode of the diode is connected to the DHT.

       

       

      I modified the Adafruit DHT library to work with the Galileo using two pins which I have attached.

      I also had to modify replace delayMicroseconds() with a while loop because it is not very reliable for delays less than 200 us for the Galileo

       

      Also attached the modified sketch example.

       

      Errors are detected occasionally, when the bit pulses are not measured accurately but this is OK because it will fail checksum.

      DHTGalSerial.png

       

      Note that for the Galileo this will only work for pins 2 and 3 because those are the only pins that are fast enough.

      For the Galileo Gen2 this should work for all pins except 7 and 8.

       

      I have only tested this with the Galileo and DHT11.

      I left my Gen2 at my office cube so I will have to verify it on that tomorrow.

        • 1. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
          SpiderKenny
          This is because the Galileo uses IO expanders for the gpio that controls the pin direction and those IO expanders are connected to the Galileo via I2C.


          Hello, this is not strictly true.

          The GPIO Expander does PWM functions.

          Much of the rest of GPIO is handled natively. Just look at the schematics and you'll see.

          The main issue here is that you are trying to hardwire a 1-wire sensor to a computer system, not a processor.


          The Galileo is a computer system, the processor runs an operating system. Arduino Sketches are simply programs scheduled in the OS like any application on a PC for example.

          You may well get some success, but it will not be reliable or consistent as the OS has to schedule apps and system services and will not guarantee to schedule your app at the right moment.


          On Galileo you get non-deterministic timing. This is the same as for every linux box, windows PC and Apple Mac. How would you interface a DHT22 to them? You'd build a small (probably USB based) interface. So like I said before, to connect one wire devices properly to a computer system requires an interface. UART is an interface, but is probably not suitable for DHT22 and the like.


          If you need deterministic timing on raw GPIO use an Arduino UNO instead. Chose the right board and tools for the job!



          • 2. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
            DinoT_Intel

            You are correct much of the gpio are handled natively.

             

            Looking at the schematic the main reason pinMode() takes too long (I measure around 42ms) is because the muxing (IO2_MUX) is controlled by a pin connected to the Cypress on the Galileo.

            I verified that there is indeed an I2C transaction by probing the SDA and SCL lines of the Cypress everytime pinMode() is called.

             

             

            galMux.png galcyp.png

            • 3. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
              SpiderKenny

              Again, I say, you need an interface to connect things like DHT to a computer system.

              It's not a problem or fault with galileo, nor is it a weakness in Galileo design. NO computer system will give deterministic timing on IO pins, they just can't.

              Simple processor and microcontroller based UNO boards will give deterministic timing on GPIO, but then they can't run linux.

              • 4. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                ek

                Hi DinoT,

                I just want to let you know that this solution is working fine in my Gen1 and DHT11 environment.

                Thank you for describing the solution.

                 

                Failure happens rather frequently. But, it works

                Eiichi

                 

                Humidity: 34.00 % Temperature: 28.00 *C 82.40 *F Heat index: 81.13 *F

                Humidity: 34.00 % Temperature: 28.00 *C 82.40 *F Heat index: 81.13 *F

                Humidity: 34.00 % Temperature: 28.00 *C 82.40 *F Heat index: 81.13 *F

                Failed to read from DHT sensor!

                Humidity: 34.00 % Temperature: 28.00 *C 82.40 *F Heat index: 81.13 *F

                Humidity: 34.00 % Temperature: 28.00 *C 82.40 *F Heat index: 81.13 *F

                Failed to read from DHT sensor!

                Humidity: 34.00 % Temperature: 28.00 *C 82.40 *F Heat index: 81.13 *F

                Failed to read from DHT sensor!

                Failed to read from DHT sensor!

                Humidity: 34.00 % Temperature: 28.00 *C 82.40 *F Heat index: 81.13 *F

                Failed to read from DHT sensor!

                • 5. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                  ahmadto

                  Hey ek,

                   

                  can you tell me how did you use the DHT sensor on Intel galileo board please.

                  can you send for me the code and the circuit?

                  I have project and i must to finish it quickly .

                   

                  Please Please help me .

                  • 6. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                    ek

                    Hi Ahmadto,

                    I followed exactly what DinoT_Intel described above. The circuit diagram (in his picture) and code were described by DinoT on top of this thread. I didn't modify anything. Did you try that?

                     

                    Below is my breadboard setting. It shows exactly same configuration as DinoT's using DHT11 and Galileo Gen1. I used 10Kohm for pull up resistor and a general purpose diode which I had handy. I believe that any small general purpose diode should work.

                     

                    For software, you need to make a library directory to make it work (compile). There are some good Arduino sites which explain how to install a library. Let me know if you hit any problem.

                     

                    BTW, do you use DHT11 or DHT22 or ? Do you use Gen1 or Gen2?

                     

                    Good luck!

                    IMG_3422.JPG

                    • 7. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                      ahmadto

                      hallo thanks Alot for Ur answer.

                      i didnot buy the sensor till now , that's why  asked you which sensor should I buy , I use Galileo gn1 , and I sawed that code , but my question is if I will use this code it will work normally ? I use my board as webserver and I want to see the values of the temperature on webserver and to make them graphic , if u have any idea let me know how to make them graphic .

                      best regards

                      ahmadto

                      • 8. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                        ahmadto

                        Hi,

                        i treid like your project but i got ERROR :

                         

                        Arduino: 1.5.3 (Windows 7), Board: "Intel® Galileo"

                        dht_ende.ino:19:23: error: 'DHT11' was not declared in this scope

                        dht_ende.ino: In function 'void setup()':

                        dht_ende.ino:25:7: error: 'class DHT' has no member named 'begin'

                        dht_ende.ino: In function 'void loop()':

                        dht_ende.ino:34:17: error: 'class DHT' has no member named 'readHumidity'

                        dht_ende.ino:36:17: error: 'class DHT' has no member named 'readTemperature'

                        dht_ende.ino:38:17: error: 'class DHT' has no member named 'readTemperature'

                        dht_ende.ino:48:18: error: 'class DHT' has no member named 'computeHeatIndex'

                         

                        Can you tell please what should i do?

                         

                        HELP PLEASEEEEE

                        • 9. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                          ek

                          Ahmadto,

                           

                          The ERROR message is suggesting that you have not configured library, correctly. To configure a library on Arduino, follow instruction such as

                            http://arduino.cc/en/Guide/Libraries

                          or

                          Installing a Library on Windows | All About Arduino Libraries | Adafruit Learning System

                          I made libraries\DHT directory under sketch folder and unzipped DHT.h and DHT.cpp there (they are in the original post of this thread).

                           

                          BTW, if you *only* want to know temperature of your web server, you don't really need to use the sensor. There are two temperature sensors built in Galileo on CPU and ADC. You  can read them from Linux or from Arduino. They are a different from air environmental temperature, though. GalileoLinuxExamples.zip

                           

                          The DHT sensor example is useful only when you want an external sensor device with temperature and humidity.

                           

                          Hope this helps a little bit.

                          • 10. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                            ahmadto

                            hi ek,

                            First i am thanking you for the response, i Hope it will help me.

                            I want to measure the temp. and humdity for my room and  and put the value in webserver but graphic .I think that I did the library correct, but I will try it again and I will let you know the result.

                            btw do you have any idea about the date and time on webserver , how to put the actually time on Webserver . when I

                            am measuring I want to see the time and the date on webserver and them to make it graphical .

                            best regards

                            Ahmad

                            • 11. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                              ahmadto

                              Hey, I treid this code and it gave me 0 c and 0 %

                              dht1111.jpg

                              • 12. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                                ek

                                Ahmadto,

                                I see where you are. Solution is :

                                 

                                Go to top of this thread where DinoT described his circuit, posted code and library. Use exactly what he described (both circuit and program). That's what I did (without thinking ). You need a diode and resistor connected as shown in his diagram. I don't know what diode does. But, I know DHT11 won't work with Galileo without the diode (or using other sketch which I tried).

                                 

                                It's really easy if you could replicate his circuit and sketch.

                                Cheers!

                                • 13. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                                  ahmadto

                                  ek,

                                  i have already the diode and the resistor connected but it doeswork

                                  i am trying this expermiment everyday and without result .

                                  Please Help me

                                   

                                  regards

                                   

                                  Ahmadto

                                  • 14. Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
                                    ek

                                    But, your sketch is different from what Dino posted, originally. Did you try that, too?

                                    I don't think your code on September 10th. would work in the circuit Dino posted.

                                    1 2 Previous Next