Plant Monitoring Project

Dependencies:   mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820

Revision:
31:45f4bfde0b9a
Parent:
30:0a25c02e25d9
Child:
32:4bb8ec535357
diff -r 0a25c02e25d9 -r 45f4bfde0b9a main.cpp
--- a/main.cpp	Wed Dec 11 17:26:05 2019 +0000
+++ b/main.cpp	Thu Dec 12 16:01:01 2019 +0000
@@ -14,18 +14,28 @@
 }
 
 #ifdef FLOOR_TEMPERATURE
-float temp_sol()
+void temp_sol()
 {
-    DS.convertTemperature(true, DS1820::all_devices);
-    if (DS.unassignedProbe(D2)){
-        #ifdef DEBUG
-        pc.printf( "D3 not assigned\n\r");
-        #endif
+    int result = 0;
+    ds1820.begin();
+    ds1820.startConversion();   // start temperature conversion from analog to digital
+    wait(1.0);                  // let DS1820 complete the temperature conversion
+    result = ds1820.read(temperature_sol); // read temperature from DS1820 and perform cyclic redundancy check (CRC)
+    #ifdef DEBUG
+    switch (result) {
+        case 0:                 // no errors -> 'temp' contains the value of measured temperature
+            pc.printf("temp = %3.1f C\r\n", temperature_sol);
+            break;
+
+        case 1:                 // no sensor present -> 'temp' is not updated
+            pc.printf("no sensor present\n\r");
+            break;
+
+        case 2:                 // CRC error -> 'temp' is not updated
+            pc.printf("CRC error\r\n");
     }
-    #ifdef DEBUG
-    pc.printf("temp sol: %.1f\n\r", DS.temperature());
     #endif
-    return DS.temperature();
+    
 }
 #endif
 
@@ -114,7 +124,7 @@
     pc.printf("Reading Data\n\r");
     #endif
     #ifdef FLOOR_TEMPERATURE
-    temperature_sol = temp_sol();
+    temp_sol();
     #endif
     #ifdef FLOOR_HUMIDITY
     humidity_sol = fct_humidity_sol();