DS1820, DS18B20 single and multi sensor OS6 compliant. Based on Erik's original code. Tested on ST's F767 and H743 platforms. Using single and multiple sensors up to 15 meters of cable length.

Dependencies:   DS1820

Files at this revision

API Documentation at this revision

Comitter:
star297
Date:
Tue Dec 29 13:08:22 2020 +0000
Child:
1:1aaf20a93f36
Commit message:
Initial commit

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-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1820.lib	Tue Dec 29 13:08:22 2020 +0000
@@ -0,0 +1,1 @@
+DS1820#a43dcf6ca539
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 29 13:08:22 2020 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include "DS1820.h"
+
+DigitalOut led(LED1);
+
+#define DATA_PIN        A0
+#define MAX_PROBES      16
+DS1820* probe[MAX_PROBES];
+
+Timer t;
+
+int     DS;
+float   Temp[16]; 
+
+int main(){
+
+    printf("\033[0m\033[2J\033[HInitialise...!\n\n");
+
+    while (DS1820::unassignedProbe(DATA_PIN)) {
+        probe[DS] = new DS1820(DATA_PIN);
+        DS++;
+        if (DS == MAX_PROBES) {
+            break;
+        }
+    }
+    
+    if (!DS) {        
+        printf("No Sensors found!\n\n");
+        ThisThread::sleep_for(chrono::milliseconds(1000));
+        NVIC_SystemReset();
+    }
+
+    // set each probe resolution, default is 12bit (750ms)
+    probe[0]->setResolution(9);
+//    probe[0]->setResolution(10);
+//    probe[0]->setResolution(11);
+//    probe[0]->setResolution(12);
+//    probe[1]->setResolution(9);
+//    probe[2]->setResolution(10);
+
+    t.start();
+
+    while(1) {
+        
+        printf("\033[0m\033[2J\033[HDS Sensor data..\n\n");
+
+        int DS_error = 0;
+        for (int i = 0; i < DS; i++) {
+            Temp[i] = probe[i]->temperature();
+            if(Temp[i]==-1000) {
+                Temp[i] = probe[i]->temperature();  // get read temp again if error
+                DS_error++;
+            }
+            printf("Probe %d:  %3.2f %cc\r\n",i,Temp[i],0xb0);
+        }
+        printf("\nDS errors:  %d\n\n", DS_error);
+
+        printf("Start conversion\n");
+        t.reset();
+        // don't wait for conversion, but do something that takes at least 750ms before reading the sensors
+        //if(DS>0){probe[0]->convertTemperature(0, DS1820::all_devices);}
+        
+        // wait for conversion, can take up to 750ms(12 bit mode)
+        if(DS>0){probe[0]->convertTemperature(1, DS1820::all_devices);}        
+        
+        printf("\nConvert process time: %0.6f Seconds\n", chrono::duration<float>(t.elapsed_time()).count());
+
+        ThisThread::sleep_for(chrono::milliseconds(1000));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Tue Dec 29 13:08:22 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/armmbed/mbed-os/#84d991342a41011fc417aab62c0f5a8832f1d18f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Tue Dec 29 13:08:22 2020 +0000
@@ -0,0 +1,11 @@
+
+{   
+    "target_overrides": {
+        "*": {
+            "target.printf_lib": "std",
+            "platform.stdio-baud-rate": 115200,
+            "platform.stdio-convert-newlines": true
+        }
+    }    
+    
+}
\ No newline at end of file