DS18B20

Dependencies:   DS18B20 DS18S20 DebugTrace OneWire mbed

Fork of DS1820_HelloWorld by Erik -

Files at this revision

API Documentation at this revision

Comitter:
jack__zen
Date:
Wed Sep 06 05:37:29 2017 +0000
Parent:
4:01060b5e01b4
Commit message:
DS18B20

Changed in this revision

DS1820.lib Show diff for this revision Revisions of this file
DS18B20.lib Show annotated file Show diff for this revision Revisions of this file
DS18S20.lib Show annotated file Show diff for this revision Revisions of this file
DebugTrace.lib Show annotated file Show diff for this revision Revisions of this file
OneWire.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
--- a/DS1820.lib	Fri Jan 13 18:30:37 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/Sissors/code/DS1820/#c591209285e9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS18B20.lib	Wed Sep 06 05:37:29 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/jack__zen/code/DS18B20/#cf42e1112753
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS18S20.lib	Wed Sep 06 05:37:29 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/jack__zen/code/DS18S20/#d7eea3b21e1d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebugTrace.lib	Wed Sep 06 05:37:29 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/jack__zen/code/DebugTrace/#1934d9b9fd80
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OneWire.lib	Wed Sep 06 05:37:29 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/jack__zen/code/OneWire/#a47e8ec71a4e
--- a/main.cpp	Fri Jan 13 18:30:37 2017 +0000
+++ b/main.cpp	Wed Sep 06 05:37:29 2017 +0000
@@ -1,49 +1,61 @@
-#define MULTIPLE_PROBES
-#define DATA_PIN        A0
-
-
-#ifdef MULTIPLE_PROBES
-
-#include "mbed.h"
-#include "DS1820.h"
-
-#define MAX_PROBES      16
- 
-DS1820* probe[MAX_PROBES];
- 
-int main() {  
-    // Initialize the probe array to DS1820 objects
-    int num_devices = 0;
-    while(DS1820::unassignedProbe(DATA_PIN)) {
-        probe[num_devices] = new DS1820(DATA_PIN);
-        num_devices++;
-        if (num_devices == MAX_PROBES)
-            break;
-    }
-    
-    printf("Found %d device(s)\r\n\n", num_devices);
-    while(1) {
-        probe[0]->convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
-        for (int i = 0; i<num_devices; i++)
-            printf("Device %d returns %3.1foC\r\n", i, probe[i]->temperature());
-        printf("\r\n");
-        wait(1);
-    }
-    
-}
-
-#else
-#include "mbed.h"
-#include "DS1820.h"
- 
-DS1820 probe(DATA_PIN);
- 
-int main() {
-    while(1) {
-        probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
-        printf("It is %3.1foC\r\n", probe.temperature());
-        wait(1);
-    }
-}
-
-#endif
\ No newline at end of file
+/*
+* OneWireCRC/OneWireThermometer demo.
+*
+* Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk>
+*
+* This file is part of OneWireCRC/OneWireThermometer.
+*
+* OneWireCRC/OneWireThermometer is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+* 
+* OneWireCRC/OneWireThermometer is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with OneWireCRC/OneWireThermometer0.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+////////////////////////////////////////////////////////////////////
+// Test code to read temperature from a Maxim DS18B20 or DS18S20
+// 1-wire device 
+////////////////////////////////////////////////////////////////////
+
+#include <mbed.h>
+#include "DS18S20.h"
+#include "DS18B20.h"
+#include "OneWireDefs.h"
+
+//#define THERMOMETER DS18S20
+#define THERMOMETER DS18B20
+//Serial pc(USBTX, USBRX);
+int main()
+{
+    // device( crcOn, useAddress, parasitic, mbed pin )
+    THERMOMETER device(true, true, false, PA_9);
+    //pc.baud(9600);
+    while (!device.initialize());    // keep calling until it works
+    
+    while (true)
+    {
+        // changing the resolutions only affects the DS18B20. The DS18S20 is fixed.
+        device.setResolution(nineBit);
+        device.readTemperature(); 
+        wait(2);
+ /*       device.setResolution(tenBit);
+        device.readTemperature(); 
+        wait(2);
+        device.setResolution(elevenBit);
+        device.readTemperature(); 
+        wait(2);
+        device.setResolution(twelveBit);
+        device.readTemperature(); 
+        wait(2);
+ */      
+    }
+     
+    return EXIT_SUCCESS;
+}