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 toDHT::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
-
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:
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!
Suggested Topics
-
Day 1 - Status report
Announcements • 23 Mar 2014, 22:45 • hek 24 Mar 2014, 20:12 -
Forum Search not working?
Troubleshooting • 4 Oct 2023, 23:33 • Gibber 2 Sept 2024, 20:28 -
Compiling Sensor code using BME280 and ESP8266
Troubleshooting • 26 Feb 2025, 00:32 • dpcons 26 Feb 2025, 06:22 -
DHT22 wrong sensor type in Home Assistant
Troubleshooting • 14 days ago • Commodoreuno 9 days ago -
Ghost Child
Troubleshooting • 15 Mar 2025, 07:44 • FcNanoLed 18 Mar 2025, 18:36 -
JSN-SR04T-V3.0 Coax cable extended
Troubleshooting • 19 Mar 2025, 21:00 • bocalexandru 21 Mar 2025, 12:05