B4R Question Inline C for DHT11

Discussion in 'B4R Questions' started by pokhraj_d, Sep 9, 2018.

  1. pokhraj_d

    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 :

    Code:
    #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
     

    Attached Files:

  2. pokhraj_d

    pokhraj_d Member

    I have changed some codes and now the different error is coming up.
    Please find below my new sketch....
    Code:
    #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
     

    Attached Files:

  3. pokhraj_d

    pokhraj_d Member

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


    Thanks-
    Pokhraj Das
     

    Attached Files:

  4. rbghongade

    rbghongade Active Member Licensed User

    DHT pin connection is not passed to inline code.
     
  5. pokhraj_d

    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
     
  6. pokhraj_d

    pokhraj_d Member

    Yes... @rbghongade .. This is absolutely correct. I have fixed the issue. Now How can I change the temperature value from F to C [Celcius].

    Please advice.

    Thanks,
    Pokhraj Das
     
  7. pokhraj_d

    pokhraj_d Member

    My Modified code that is running...

    Code:
    #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
     
  8. mark35at

    mark35at Well-Known Member Licensed User

    Do you have the DHT library? See Here.
     
  9. pokhraj_d

    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
     
  10. mark35at

    mark35at Well-Known Member Licensed User

    Looking at the code in DHTtester.ino, as in your post:

    Code:
    Line 41 temperature =dht.readTemperature()
    gives Celcius

    Code:
    Line 43 temperature =dht.readTemperature(TRUE)
    returns Fahrenheit.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice