GSOE Belueftung DS18B20

Dependencies:   LCD_i2c_GSOE DS1820

Files at this revision

API Documentation at this revision

Comitter:
hudakz
Date:
Sun Jan 20 10:13:38 2019 +0000
Parent:
3:eb195375cde7
Child:
5:4f7330bb1b64
Commit message:
Updated.

Changed in this revision

DS1820.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/DS1820.lib	Fri Mar 27 12:37:34 2015 +0000
+++ b/DS1820.lib	Sun Jan 20 10:13:38 2019 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/hudakz/code/DS1820/#8dfdd1603e4d
+http://developer.mbed.org/users/hudakz/code/DS1820/#b02fa18b294a
--- a/main.cpp	Fri Mar 27 12:37:34 2015 +0000
+++ b/main.cpp	Sun Jan 20 10:13:38 2019 +0000
@@ -9,25 +9,36 @@
 #include "mbed.h"
 #include "DS1820.h"
 
-Serial serial(USBTX, USBRX);
+Serial      pc(USBTX, USBRX);
+DigitalOut  led(LED1);
+DS1820      ds1820(p8);    // substitute p8 with actual mbed pin name connected to the DS1820 data pin    
+float       temp = 0;
+int         result = 0; 
  
 int main() {
-    DS1820  ds1820(PA_9);    // substitute PA_9 with actual mbed pin name connected to the DS1820 data pin    
                              
     if(ds1820.begin()) {
-        ds1820.startConversion();   // start temperature conversion
-        wait(1.0);                  // let DS1820 complete the temperature conversion
         while(1) {
-            serial.printf("temp = %3.1f\r\n", ds1820.read());     // read temperature
-            ds1820.startConversion();     // start temperature conversion
-            wait(1.0);                    // let DS1820 complete the temperature conversion
+            ds1820.startConversion();  // start temperature conversion from analog to digital
+            wait(1.0);                 // let DS1820 complete the temperature conversion 
+            result = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC)
+            switch(result) {
+            case 0:    // no errors -> 'temp' contains the value of measured temperature
+                pc.printf("temp = %3.1f%cC\r\n", temp, 176);
+                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");
+            } 
+            led = !led;
         }
     } else
-        serial.printf("No DS1820 sensor found!\r\n");
+        pc.printf("No DS1820 sensor found!\r\n");
 }
 
-
-// You can create an array of sensors:
+// Array of sensors:
 
 //int main() {
 //    DS1820  ds1820[3] = {DS1820(PA_8), DS1820(PA_9), DS1820(PC_7)};
--- a/mbed.bld	Fri Mar 27 12:37:34 2015 +0000
+++ b/mbed.bld	Sun Jan 20 10:13:38 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file