B4R Question DHT 11 Example for ESP32

viriato

Member
Licensed User
Longtime User
Hi,
I just got my ESP32 NodeMCU and tried the basic examples and all work , including DS1820
But I have issues with DHT11 example , I started with working ESP8266 example it works correctly but not with ESP32 , always get temperature 0 , Humidity 0...

Any help with example or Lib will be welcome
Thanks a lot

Viriato
 

viriato

Member
Licensed User
Longtime User
Hi Erel,
I am using the same program and library (rDht (Version 2.00) for the 3 kits Arduino Uno , ESP8266 , ESP32
Only ESP32 is not working ..

I am probably missing something .... but what
Thanks
 
Upvote 0

rbghongade

Active Member
Licensed User
Longtime User
Dear friend,
Try this code:
B4X:
Sub Process_Globals
    Public Serial1 As Serial
        Public Timer1 As Timer
          Public Interval As Int
    Dim HUMIDITY,TEMPERATURE As Double
   
End Sub

Private Sub AppStart
   
    Serial1.Initialize(115200)
    Log("AppStart")
    Interval=2
        Timer1.Initialize("Timer1_Tick",Interval*1000)
    RunNative("setup",Null)
    Timer1.Enabled = True
End Sub

Sub Timer1_Tick
    TEMPERATURE=0
    RunNative("read",Null)
    Log("  Temperature =",NumberFormat(TEMPERATURE,2,1), " ºC")
    Log("  Humidity =",NumberFormat(HUMIDITY,2,1), " %RH")

End Sub

#if C
#include "DHT.h"

#define DHTPIN 22     // what digital pin we're connected to

#define DHTTYPE DHT22   // DHT 22 

DHT dht(DHTPIN, DHTTYPE);
void setup(B4R::Object* o){
dht.begin();
}
   
void read (B4R::Object* o) {
   b4r_main::_humidity  = dht.readHumidity();
   b4r_main::_temperature = dht.readTemperature();
}

#End if
Note:
1)Make sure you have Arduino library for DHT11/22 installed
2)Replace references to DHT22 by DHT11
 
Upvote 0

viriato

Member
Licensed User
Longtime User
Hi,
Thank you for the information
I tried your example , but now i have different issue during compile process (see below)
The libraries work since they are the same for Arduino and ESP8266 , correct ?
Any other suggestion ?
Thank very much

Viriato

Preparing boards...
Verifying...
b4r_main.cpp:18: error: 'DHT' does not name a type
DHT dht(DHTPIN, DHTTYPE);
^
C:\Users\fvict\DOCUME~1\B4R\NOUVEA~1\Objects\bin\sketch\b4r_main.cpp: In function 'void setup(B4R::Object*)':
b4r_main.cpp:20: error: expected unqualified-id before '.' token
dht.begin();
^
C:\Users\fvict\DOCUME~1\B4R\NOUVEA~1\Objects\bin\sketch\b4r_main.cpp: In function 'void read(B4R::Object*)':
b4r_main.cpp:24: error: expected primary-expression before '.' token
b4r_main::_humidity = dht.readHumidity();
^
b4r_main.cpp:25: error: expected primary-expression before '.' token
b4r_main::_temperature = dht.readTemperature();
^
exit status 1
 
Upvote 0

viriato

Member
Licensed User
Longtime User
Hi,
The Arduino library is installed ,
Oups, i just forgot to unchecked rDHT .
but not sure I am using the right library ...
now I have different error ..

Preparing boards...
Verifying...
In file included from C:\Program Files (x86)\Arduino\libraries\DHT\DHT_U.cpp:22:0:
C:\Program Files (x86)\Arduino\libraries\DHT\DHT_U.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory
compilation terminated.
exit status 1
 
Upvote 0
Top