DHT11 Temperature & Humidity Sensor features a temperature & humidity sensor complex with a calibrated digital signal output.

Files at this revision

API Documentation at this revision

Comitter:
mcm
Date:
Fri Aug 09 07:39:17 2019 +0000
Parent:
3:082a970dca06
Commit message:
An example was added in order to show how to use this driver.

Changed in this revision

DHT11.h Show annotated file Show diff for this revision Revisions of this file
--- a/DHT11.h	Fri Aug 09 07:32:18 2019 +0000
+++ b/DHT11.h	Fri Aug 09 07:39:17 2019 +0000
@@ -23,7 +23,98 @@
     Example:
 
 @code
+#include "mbed.h"
+#include "DHT11.h"
 
+DHT11 myDHT11 ( PB_8 );                                                         // DHT11 --> PB_8
+Serial pc     ( USBTX, USBRX );                                                 // tx, rx
+
+DigitalOut  myled   ( LED1 );
+Ticker      newAction;
+
+
+//@brief Constants.
+
+
+//@brief Variables.
+volatile uint32_t myState;                                                      // State that indicates when to perform a new sample  
+
+
+//@brief   FUNCTION PROTOTYPES
+void changeDATA ( void );
+
+
+//@brief FUNCTION FOR APPLICATION MAIN ENTRY.
+int main()
+{
+    char                  myChecksum[] = "Ok";
+    DHT11::DHT11_status_t aux;
+    DHT11::DHT11_data_t   myDHT11_Data;
+
+    pc.baud ( 115200 );
+
+    myled   =   1;
+    wait(3);
+    myled   =   0;
+
+    // DHT11 starts: Release the bus  
+    aux  =   myDHT11.DHT11_Init ();
+
+
+    myState  =   0UL;                                                           // Reset the variable
+    newAction.attach( &changeDATA, 1U );                                        // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
+
+
+    // Let the callbacks take care of everything
+    while(1) {
+        sleep();
+
+        if ( myState == 1UL ) {
+            myled = 1U;
+
+            // Get a new data 
+            aux  =   myDHT11.DHT11_GetData ( &myDHT11_Data );
+
+            // Check checksum to validate data  
+            if ( myDHT11_Data.checksumStatus == DHT11::DHT11_CHECKSUM_OK ) {
+                myChecksum[0]  =   'O';
+                myChecksum[1]  =   'k';
+            } else {
+                myChecksum[0]  =   'E';
+                myChecksum[1]  =   'r';
+            }
+
+            // Send data through the UART    
+            pc.printf ( "T: %d C | RH: %d %% | Checksum: %s\r\n", myDHT11_Data.temperature, myDHT11_Data.humidity, myChecksum );
+
+
+            // Reset the variables   
+            myState  =   0UL;
+            myled    =   0U;
+        }
+    }
+}
+
+
+ // @brief       changeDATA ( void  )
+ //
+ // @details     It changes myState variable
+ //
+ // @param[in]    N/A
+ //
+ // @param[out]   N/A.
+ //
+ // @return       N/A.
+ //
+ // @author      Manuel Caballero
+ // @date        24/June/2019
+ // @version     24/June/2019   The ORIGIN
+ // @pre         N/A
+ // @warning     N/A.
+void changeDATA ( void )
+{
+    myState  =   1UL;
+}
 @endcode
 */
 
@@ -125,7 +216,7 @@
     /** Delete DHT11 object.
      */
     ~DHT11();
-    
+
     /** It configures the GPIO peripheral.
       */
     DHT11_status_t DHT11_Init       ( void                    );
@@ -137,8 +228,8 @@
     /** It gets and calculates the current data: Temperature, Humidity and Checksum.
       */
     DHT11_status_t DHT11_GetData    ( DHT11_data_t* myData    );
-    
-    
+
+
 private:
     DigitalInOut _dht11Pin;
 };