Can't compile Humidity sketch 2.0 .. What DHT library do I need?



  • I'm trying to compile the Humidity sketch 2.0 and am getting an error. Here's the sketch I'm using:

    https://raw.githubusercontent.com/mysensors/MySensorsArduinoExamples/master/examples/HumiditySensor/HumiditySensor.ino

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * 
     * DESCRIPTION
     * This sketch provides an example how to implement a humidity/temperature
     * sensor using DHT11/DHT-22 
     * http://www.mysensors.org/build/humidity
     */
     
    // Enable debug prints
    //#define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DHT.h>  
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    void setup()  
    { 
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      metric = getConfig().isMetric;
    }
    
    void presentation()  
    { 
      // Send the Sketch Version Information to the Gateway
      sendSketchInfo("Humidity", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
    }
    
    void loop()      
    {  
      delay(dht.getMinimumSamplingPeriod());
     
      // Fetch temperatures from DHT sensor
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        send(msgTemp.set(temperature, 1));
        #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
        #endif
      }
      
      // Fetch humidity from DHT sensor
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          send(msgHum.set(humidity, 1));
          #ifdef MY_DEBUG
          Serial.print("H: ");
          Serial.println(humidity);
          #endif
      }
      
      sleep(SLEEP_TIME); //sleep a bit
    }
    

    The error I'm getting is this:

    
    Arduino: 1.6.6 (Windows 7), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"
    
    C:\Users\User\Documents\Arduino-new\sketch_jul17e\sketch_jul17e.ino:39:19: fatal error: DHT.h: No such file or directory
    
     #include <DHT.h>  
    
                       ^
    
    compilation terminated.
    
    exit status 1
    Error compiling.
    
    

    I noticed a case sensitive issue so I changed DHT.h to dht.h and I get a bit further but then hit an error on line:

    DHT dht;
    
    

    I changed that to dht dht; and get a bit further still:

    Arduino: 1.6.6 (Windows 7), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"
    
    C:\Users\User\Documents\Arduino-new\sketch_jul17e\sketch_jul17e.ino: In function 'void setup()':
    
    sketch_jul17e:55: error: 'class dht' has no member named 'setup'
    
       dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
           ^
    
    C:\Users\User\Documents\Arduino-new\sketch_jul17e\sketch_jul17e.ino: In function 'void loop()':
    
    sketch_jul17e:72: error: 'class dht' has no member named 'getMinimumSamplingPeriod'
    
       delay(dht.getMinimumSamplingPeriod());
    
                 ^
    
    sketch_jul17e:75: error: 'class dht' has no member named 'getTemperature'
    
       float temperature = dht.getTemperature();
    
                               ^
    
    sketch_jul17e:81: error: 'class dht' has no member named 'toFahrenheit'
    
           temperature = dht.toFahrenheit(temperature);
    
                             ^
    
    sketch_jul17e:91: error: 'class dht' has no member named 'getHumidity'
    
       float humidity = dht.getHumidity();
    
                            ^
    
    exit status 1
    'class dht' has no member named 'setup'
    
    

    As you've probably guessed, I'm just trying things to see if I can get it to work. I'm guessing it's a library thing and could use some guidance as to what library I should be using. Thanks!



  • Can someone please look at their libraries and tell me which one I need to use? Apparently installing Arduino IDE does not install this library by default and all the ones I've tried have failed. I don't see any documentation on which one to use.

    I've got a handful of sensors built but I can't program them until I get this resolved. I really appreciate your time and help. Thanks!


  • Hero Member

    @chuckconnors this is what I found as a working example on my system. I still don't understand why the DHT keeps being so popular. There are much better temp/hum sensors around..... But anyway, this one should work.

    Installation
    ------------
    
    Place the [DHT][download] library folder in your `<arduinosketchfolder>/libraries/` folder. You may need to create the `libraries` subfolder if its your first library. Restart the Arduino IDE. 
    
    [download]: https://github.com/markruys/arduino-DHT/archive/master.zip "Download DHT library"
    [example]: https://github.com/markruys/arduino-DHT/blob/master/examples/DHT_Test/DHT_Test.pde "Show DHT example"
    [header]: https://github.com/markruys/arduino-DHT/blob/master/DHT.h "Show header file"```

  • Hardware Contributor

    @AWI probably because its mentioned in the build page? But i agree - I now know as well there is better out there.


  • Hero Member

    @sundberg84 Do I hear volunteering for a revised build example? πŸ™‚ Or better a joint initiative?



  • @AWI said:

    @chuckconnors this is what I found as a working example on my system. I still don't understand why the DHT keeps being so popular. There are much better temp/hum sensors around..... But anyway, this one should work.

    Installation
    ------------
    
    Place the [DHT][download] library folder in your `<arduinosketchfolder>/libraries/` folder. You may need to create the `libraries` subfolder if its your first library. Restart the Arduino IDE. 
    
    [download]: https://github.com/markruys/arduino-DHT/archive/master.zip "Download DHT library"
    [example]: https://github.com/markruys/arduino-DHT/blob/master/examples/DHT_Test/DHT_Test.pde "Show DHT example"
    [header]: https://github.com/markruys/arduino-DHT/blob/master/DHT.h "Show header file"```
    

    Thanks for the reply. I'm pretty sure that's one of the ones I tried. I ended up finding an old install I had and copied the library from there and it's working now.


  • Admin

    @chuckconnors

    if you look at the "examples" repository, it both examples folder, and libraries that should work with the enclosed examples. Copy the library, that you want to use, to Arduino/libraries/... and the example to Arduino/... and try to compile them.



  • @tbowmo said:

    @chuckconnors

    if you look at the "examples" repository, it both examples folder, and libraries that should work with the enclosed examples. Copy the library, that you want to use, to Arduino/libraries/... and the example to Arduino/... and try to compile them.

    HOLY SMOKES! I totally missed the libraries directory. Thank you and sorry for the troubles.



  • @sundberg84 said:

    @AWI probably because its mentioned in the build page? But i agree - I now know as well there is better out there.

    Can you tell me what better sensors are out there? These DHT11's I have vary wildly with regards to relative humidity.


  • Hardware Contributor

    @chuckconnors - BMP180 or Bmp280 for example.



  • @sundberg84 said:

    @chuckconnors - BMP180 or Bmp280 for example.

    Those appear to be atmospheric pressure sensors. Looking for humidity sensors other than the DHT11/DHT22.


  • Hardware Contributor

    Hello,

    DHT22 is already much better than DHT11 which I think is complete garbage: wild variations in both temp and humidity between sensors, too unprecise and it's getting worse with time.
    I heave read somewhere (sorry don't remember where but it was a guy testing a lot of temp/humidity sensors) that the best one for humidity is BME280. It has also atmospheric pressure and temperature (but is not really good for temp) like BMP180/280.
    The Si7020 like on the sensebender micro seems pretty good too.

    Just don't expect the same price level πŸ˜„


  • Hero Member

    @Nca78 said:

    Just don't expect the same price level

    πŸ˜• Si7021 can be found for €2.65 (DHT22 €2.43) on ali-express. BME280 €4.07 including barometeric pressure.
    A link to a comparison in this post



  • Yes, BME280 seems pretty good for T, P, H. I did not have much luck with DHT22 and SI7021.



  • I'm dead in the water with the same issue. Downloading the lib from the location above yielded the same result.


  • Mod

    @r-nox did you download the library from MySensors or did you follow the link in the readme and download the upstream version of the library? Only the former will work.



  • @mfalkvidd

    I can't tell what I'm using anymore. Been at it all afternoon installing and un installing. I think I'm using these now (https://github.com/mysensors/MySensorsArduinoExamples/tree/master/libraries/DHT).

    Where do I start please?



  • https://github.com/markruys/arduino-DHT/

    This one worked for me.

    What a frustrating time that was.



  • I really like mysensors.org, but I've always had difficulties with the site organization. In my opinion, is not intuitive at all, although it has a great and appealing theme.

    Well, maybe it shouldn't, but this sets me back when trying to build anything... I know this excellent initiative for a couple of years now, and from time to time I try to do something but I end up de-motivated because it takes too long to find simple answers/solutions. At the moment, I have nothing built although I have all the equipment I need, including SenserBenders. Yes, frustrating like r-nox commented 2 years ago.

    Anyway, my point is: For the ones looking for a library that makes this DHT sketch work, mysensors have compiled a set of libraries that include this DHT.h and many others. Just go to https://www.mysensors.org/about/arduino#optional---install-external-mysensors-examples (yes, the name is not intuitive, maybe the keyword library would make it more obvious?), or jump directly to here and follow the standard library instructions. It took me two hours to find this, hope it saves time for future followers of mysensors like myself.

    Good luck!


Log in to reply
 

Suggested Topics

  • 4
  • 2
  • 3
  • 20
  • 8
  • 9

69
Online

11.4k
Users

11.1k
Topics

112.7k
Posts