HumiditySensor code does not compile



  • Hi everyone,

    I tried to compile the code for the HumiditySensor but it does not work. I downloaded the latest Arduino-master from Github, added all libraries but when I compile the code of the HumiditySensor, I get this answer:

    HumiditySensor.cpp.o: In function loop': /Users//Desktop/Desktop/HumiditySensor.ino:38: undefined reference to DHT::getTemperature()'
    /Users//Desktop/Desktop/HumiditySensor.ino:51: undefined reference to DHT::getHumidity()' HumiditySensor.cpp.o: In function setup':
    /Users//Desktop/Desktop/HumiditySensor.ino:22: undefined reference to `DHT::setup(unsigned char, DHT::DHT_MODEL_t)'

    I tried other sensors (for example distance) and they compile and work.
    I'm using a Mac, any other things of relevance?

    Thanks a lot,
    Philipp


  • Contest Winner

    @phil83

    compliles fine for me... Arduino Version 1.6.3; my sensors version 1.4 (latest release)

    you have the DHT library in your arduino library folder:

    Screen Shot 2015-04-29 at 2.15.19 PM.png

    Code:

    #include <SPI.h>
    #include <MySensor.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)
    
    MySensor gw;
    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()  
    { 
      gw.begin();
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Humidity", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      
      metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    {  
      delay(dht.getMinimumSamplingPeriod());
    
      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);
        }
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
      
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
      }
    
      gw.sleep(SLEEP_TIME); //sleep a bit
    }
    
    
    


  • @BulldogLowell I just reinstalled arduino and now it is working... thank you for testing and telling me!


Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 3
  • 15
  • 24
  • 10

24
Online

11.2k
Users

11.1k
Topics

112.5k
Posts