B4R Question Inline C for DHT11

pokhraj_d

Member
Hello All,
I am facing error while trying to compile DHT11 sensor for humidity.
I have copied DHT11 sensor library to "C:\Program Files (x86)\Arduino\libraries\DHT-sensor-library-master"

Then I try to compile to compile the below code. But I am facing error :

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Public Humid,temperature As Float
    Private pin10 As Pin
    Private timer1 As Timer
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    pin10.Initialize(10,pin10.MODE_OUTPUT)
    timer1.Initialize("timer1_Tick",1000)
    timer1.Enabled=True
    RunNative("setup",Null)
End Sub

Private Sub timer1_tick()
    RunNative("read", Null)
    Log("Humidity :",Humid)
    
End Sub


#if C
#include "dht.h"
DHT dht
void setup(B4R::Object* o){
dht.begin();
}
void read (B4R::Object* o) {
   b4r_main::_humid = dht.readHumidity();
   b4r_main::_temperature =dht.readTemperature();
}
#End if
 

Attachments

  • Compile_error.JPG
    Compile_error.JPG
    33.7 KB · Views: 301

pokhraj_d

Member
I have changed some codes and now the different error is coming up.
Please find below my new sketch....
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Public Humid,temperature As Float
    Private pin10 As Pin
    Private timer1 As Timer
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    pin10.Initialize(10,pin10.MODE_OUTPUT)
    timer1.Initialize("timer1_Tick",1000)
    timer1.Enabled=True
    RunNative("setup",Null)
End Sub

Private Sub timer1_tick()
    RunNative("read", Null)
    Log("Humidity :",Humid)
    
End Sub


#if C
#include "DHT.h"
#define DHTTYPE DHT11
DHT dht;
void setup(B4R::Object* o){
dht.begin();
}
void read (B4R::Object* o) {
   b4r_main::_humid = dht.readHumidity();
   b4r_main::_temperature =dht.readTemperature();
}
#End if

Please advice on this...

Thanks-
Pokhraj Das
 

Attachments

  • Compile_error.JPG
    Compile_error.JPG
    59.6 KB · Views: 332
Upvote 0

pokhraj_d

Member
Hello,
Please find the Library file from Arduino libraries...


Thanks-
Pokhraj Das
 

Attachments

  • DHT_sensor_library.zip
    6.5 KB · Views: 350
Upvote 0

pokhraj_d

Member
Hello All,
The issue has been fixed and Sketch is running fine. But the confusion is whether the Temperature is at F or C that I am not sure.
As per the manual the default is at F. Now how can I change it to C [Celcius].

Please advice.

Thanks-
Pokhraj Das
 
Upvote 0

pokhraj_d

Member
My Modified code that is running...

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Public Humid,temperature As Float
    Private pin10 As Pin
    Private timer1 As Timer
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    pin10.Initialize(10,pin10.MODE_OUTPUT)
    timer1.Initialize("timer1_Tick",1000)
    timer1.Enabled=True
    RunNative("setup",Null)
End Sub

Private Sub timer1_tick()
    RunNative("read", Null)
    Log("Humidity :",Humid)
    If Humid > 70 Then
        Log("Maximum Humidity")
    End If
    Log("Temperature :", temperature)
    
End Sub


#if C
#include "DHT.h"
#define DHTPIN 10
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup(B4R::Object* o){
dht.begin();
}
void read (B4R::Object* o) {
   b4r_main::_humid = dht.readHumidity();
   b4r_main::_temperature =dht.readTemperature();
}
#End if

Thanks-
Pokhraj Das
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Do you have the DHT library? See Here.
 
Upvote 0

pokhraj_d

Member
@mark35at .... NO... Iam not using the DHT lib you mentioned.... I m using adafruit DHT11 liab.... I already attached the lib at my previous post... just wanted to convert the temp from F to C (celcius). How to convert that...
Please advice

Thanks
Pokhraj Das
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Looking at the code in DHTtester.ino, as in your post:

B4X:
Line 41 temperature =dht.readTemperature()

gives Celcius

B4X:
Line 43 temperature =dht.readTemperature(TRUE)

returns Fahrenheit.
 
Upvote 0
Top