I corrected found two bugs in your library: _the temperature reading is incorrect (systematic error in subdegree, the division by two was not done correctly + trunc, see below for correction) _one variable, _power_mosfet, was left unitialized under some conditions

Dependencies:   LinkedList

Fork of DS1820 by Erik -

Files at this revision

API Documentation at this revision

Comitter:
florian
Date:
Fri Jan 30 11:07:10 2015 +0000
Parent:
9:3821ca0b7f14
Commit message:
correction of bugs compared to original library.; _Unitialized variable; _Wrong reading of temperature (when subdegree precision is required)

Changed in this revision

DS1820.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3821ca0b7f14 -r d297ce9ce422 DS1820.cpp
--- a/DS1820.cpp	Thu Jan 29 19:27:32 2015 +0000
+++ b/DS1820.cpp	Fri Jan 30 11:07:10 2015 +0000
@@ -361,18 +361,16 @@
         }
         answer = reading +0.0; // convert to floating point
         if ((FAMILY_CODE == FAMILY_CODE_DS18B20 ) || (FAMILY_CODE == FAMILY_CODE_DS1822 )) {
-            answer = answer / 8.0;
+            answer = answer / 16.0;
         }
         else {
             remaining_count = RAM[6];
             count_per_degree = RAM[7];
-            answer = answer - 0.25 + (count_per_degree - remaining_count) / count_per_degree;
+            answer = floor(answer/2.0) - 0.25 + (count_per_degree - remaining_count) / count_per_degree;
         }
-        if (scale=='C' or scale=='c')
-            answer = answer / 2.0;
-        else
+        if (scale=='F' or scale=='f')
             // Convert to deg F
-            answer = answer * 9.0 / 10.0 + 32.0;
+            answer = answer * 9.0 / 5.0 + 32.0;
     }
     return answer;
 }