I2C HUMIDITY AND TEMPERATURE SENSOR

Dependents:   dashboard_f1

Files at this revision

API Documentation at this revision

Comitter:
mcm
Date:
Mon Feb 05 12:51:46 2018 +0000
Parent:
2:18c159179b08
Commit message:
The library was completed and tested, it works as expected ( NUCLEO-L152RE was used for testing )

Changed in this revision

SI7021.h Show annotated file Show diff for this revision Revisions of this file
diff -r 18c159179b08 -r 75cece7f7329 SI7021.h
--- a/SI7021.h	Mon Feb 05 12:34:35 2018 +0000
+++ b/SI7021.h	Mon Feb 05 12:51:46 2018 +0000
@@ -22,7 +22,76 @@
 /**
     Example:
 
-[todo]
+#include "mbed.h"
+#include "SI7021.h"
+
+
+SI7021  myTempRHsensor      ( I2C_SDA, I2C_SCL, SI7021::SI7021_ADDRESS, 400000 );
+Serial pc                   ( USBTX, USBRX );
+
+Ticker newReading;
+DigitalOut myled1           ( LED1 );
+
+
+
+SI7021::SI7021_vector_data_t     myData;
+SI7021::SI7021_status_t          mySI7021status;
+uint32_t                         myState;
+
+
+void readDATA ( void )
+{
+    myState++;
+}
+
+
+int main()
+{
+    pc.baud ( 115200 );
+
+    // Reset the device
+    mySI7021status   =   myTempRHsensor.SI7021_SoftReset ();
+    wait_ms ( 15 );
+
+
+    // Configure the device
+    mySI7021status   =   myTempRHsensor.SI7021_Conf ( SI7021::SI7021_RESOLUTION_RH_12_TEMP_14, SI7021::SI7021_HTRE_DISABLED );
+
+    // Get the Electronic Serial Number
+    mySI7021status   =   myTempRHsensor.SI7021_GetElectronicSerialNumber ( &myData );
+
+    // Get the Firmware revision
+    mySI7021status   =   myTempRHsensor.SI7021_GetFirmwareRevision       ( &myData );
+
+    // Plot all the information through the srial port.
+    pc.printf( "Electronic Serial Number: %16x %16x\nFirmware Revision: %02x\r\n", myData.ElectronicSerialNumber_MSB, myData.ElectronicSerialNumber_LSB, myData.FirmwareRevision );
+
+
+    newReading.attach( &readDATA, 0.5 );                                          // the address of the function to be attached ( readDATA ) and the interval ( 0.5s )
+
+
+    // Let the callbacks take care of everything
+    while(1) {
+        sleep();
+
+        if ( myState == 1 ) {
+            // Trigger a new Humidity conversion ( the temperature conversion is triggered by default )
+            myled1    =  1;
+
+            mySI7021status   =    myTempRHsensor.SI7021_TriggerHumidity       ( SI7021::SI7021_NO_HOLD_MASTER_MODE );
+        } else if ( myState == 2 ) {
+            // Read Humidity and Temperature result
+            mySI7021status   =    myTempRHsensor.SI7021_ReadHumidity          ( &myData );
+            mySI7021status   =    myTempRHsensor.SI7021_ReadTemperatureFromRH ( &myData );
+
+            // Send it through the UART
+            pc.printf( "Temp: %0.5f C, RH: %0.5f\r\n", myData.Temperature, myData.RelativeHumidity );
+
+            myState   =  0;                                                     // Reset state
+            myled1    =  0;
+        }
+    }
+}
 
 */