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. Troubleshooting
  3. HumiditySensor code does not compile

HumiditySensor code does not compile

Scheduled Pinned Locked Moved Troubleshooting
3 Posts 2 Posters 2.4k Views 1 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.
  • P Offline
    P Offline
    phil83
    wrote on last edited by
    #1

    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

    BulldogLowellB 1 Reply Last reply
    0
    • P phil83

      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

      BulldogLowellB Offline
      BulldogLowellB Offline
      BulldogLowell
      Contest Winner
      wrote on last edited by BulldogLowell
      #2

      @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
      }
      
      
      
      1 Reply Last reply
      0
      • P Offline
        P Offline
        phil83
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        14

        Online

        11.7k

        Users

        11.2k

        Topics

        113.0k

        Posts


        Copyright 2019 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