From e69a910c92a4876566c78abf8e6cfe0d34d35e1c Mon Sep 17 00:00:00 2001 From: Dhruba Saha Date: Wed, 20 Sep 2023 06:45:14 +0530 Subject: [PATCH] Added ESP32, ESP8266 compatibility --- examples/ReadHumidity/ReadHumidity.ino | 5 ++++- examples/ReadPlot/ReadPlot.ino | 10 +++++++++- examples/ReadTempAndHumidity/ReadTempAndHumidity.ino | 10 +++++++++- examples/ReadTemperature/ReadTemperature.ino | 5 ++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/examples/ReadHumidity/ReadHumidity.ino b/examples/ReadHumidity/ReadHumidity.ino index 949e6f9..8d814c4 100644 --- a/examples/ReadHumidity/ReadHumidity.ino +++ b/examples/ReadHumidity/ReadHumidity.ino @@ -11,7 +11,10 @@ // Include the DHT11 library for interfacing with the sensor. #include -// Create an instance of the DHT11 class. The sensor is connected to digital I/O pin 2. +// Create an instance of the DHT11 class. +// - For Arduino: Connect the sensor to Digital I/O Pin 2. +// - For ESP32: Connect the sensor to pin GPIO2 or P2. +// - For ESP8266: Connect the sensor to GPIO2 or D4. DHT11 dht11(2); void setup() diff --git a/examples/ReadPlot/ReadPlot.ino b/examples/ReadPlot/ReadPlot.ino index 193aa38..cdbf93f 100644 --- a/examples/ReadPlot/ReadPlot.ino +++ b/examples/ReadPlot/ReadPlot.ino @@ -10,7 +10,10 @@ // Include the DHT11 library for interfacing with the sensor. #include -// Create an instance of the DHT11 class. The sensor is connected to digital I/O pin 2. +// Create an instance of the DHT11 class. +// - For Arduino: Connect the sensor to Digital I/O Pin 2. +// - For ESP32: Connect the sensor to pin GPIO2 or P2. +// - For ESP8266: Connect the sensor to GPIO2 or D4. DHT11 dht11(2); void setup() @@ -24,6 +27,11 @@ void loop() { // Attempt to read the temperature and humidity values from the DHT11 sensor. int temperature = dht11.readTemperature(); + + // If using ESP32 or ESP8266 (xtensa architecture), uncomment the delay below. + // This ensures stable readings when calling methods consecutively. + // delay(50); + int humidity = dht11.readHumidity(); // Check the results of the readings. diff --git a/examples/ReadTempAndHumidity/ReadTempAndHumidity.ino b/examples/ReadTempAndHumidity/ReadTempAndHumidity.ino index d3fed26..949272b 100644 --- a/examples/ReadTempAndHumidity/ReadTempAndHumidity.ino +++ b/examples/ReadTempAndHumidity/ReadTempAndHumidity.ino @@ -11,7 +11,10 @@ // Include the DHT11 library for interfacing with the sensor. #include -// Create an instance of the DHT11 class. The sensor is connected to digital I/O pin 2. +// Create an instance of the DHT11 class. +// - For Arduino: Connect the sensor to Digital I/O Pin 2. +// - For ESP32: Connect the sensor to pin GPIO2 or P2. +// - For ESP8266: Connect the sensor to GPIO2 or D4. DHT11 dht11(2); void setup() @@ -25,6 +28,11 @@ void loop() { // Attempt to read the temperature and humidity values from the DHT11 sensor. int temperature = dht11.readTemperature(); + + // If using ESP32 or ESP8266 (xtensa architecture), uncomment the delay below. + // This ensures stable readings when calling methods consecutively. + // delay(50); + int humidity = dht11.readHumidity(); // Check the results of the readings. diff --git a/examples/ReadTemperature/ReadTemperature.ino b/examples/ReadTemperature/ReadTemperature.ino index 451cb3c..07cf2f5 100644 --- a/examples/ReadTemperature/ReadTemperature.ino +++ b/examples/ReadTemperature/ReadTemperature.ino @@ -11,7 +11,10 @@ // Include the DHT11 library for interfacing with the sensor. #include -// Create an instance of the DHT11 class. The sensor is connected to digital I/O pin 2. +// Create an instance of the DHT11 class. +// - For Arduino: Connect the sensor to Digital I/O Pin 2. +// - For ESP32: Connect the sensor to pin GPIO2 or P2. +// - For ESP8266: Connect the sensor to GPIO2 or D4. DHT11 dht11(2); void setup()