Skip to content

Commit dafac43

Browse files
authoredJan 21, 2025
Merge pull request #267 from milesburton/fix/DS1820-support-accidentally-removed
Fix/ds1820 support accidentally removed
2 parents 3cfcb26 + ec506be commit dafac43

File tree

7 files changed

+41
-4
lines changed

7 files changed

+41
-4
lines changed
 

‎DallasTemperature.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extern "C" {
3636

3737
#define NO_ALARM_HANDLER ((AlarmHandler *)0)
3838

39+
// DSROM FIELDS
40+
#define DSROM_FAMILY 0
41+
#define DSROM_CRC 7
42+
3943
DallasTemperature::DallasTemperature() {
4044
_wire = nullptr;
4145
devices = 0;
@@ -554,6 +558,37 @@ int32_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress, ui
554558
| neg;
555559
}
556560

561+
/*
562+
DS1820 and DS18S20 have a 9-bit temperature register.
563+
564+
Resolutions greater than 9-bit can be calculated using the data from
565+
the temperature, and COUNT REMAIN and COUNT PER °C registers in the
566+
scratchpad. The resolution of the calculation depends on the model.
567+
568+
While the COUNT PER °C register is hard-wired to 16 (10h) in a
569+
DS18S20, it changes with temperature in DS1820.
570+
571+
After reading the scratchpad, the TEMP_READ value is obtained by
572+
truncating the 0.5°C bit (bit 0) from the temperature data. The
573+
extended resolution temperature can then be calculated using the
574+
following equation:
575+
576+
COUNT_PER_C - COUNT_REMAIN
577+
TEMPERATURE = TEMP_READ - 0.25 + --------------------------
578+
COUNT_PER_C
579+
580+
Hagai Shatz simplified this to integer arithmetic for a 12 bits
581+
value for a DS18S20, and James Cameron added legacy DS1820 support.
582+
583+
See - http://myarduinotoy.blogspot.co.uk/2013/02/12bit-result-from-ds18s20.html
584+
*/
585+
586+
if ((deviceAddress[DSROM_FAMILY] == DS18S20MODEL) && (scratchPad[COUNT_PER_C] != 0)) {
587+
fpTemperature = (((fpTemperature & 0xfff0) << 3) - 32
588+
+ (((scratchPad[COUNT_PER_C] - scratchPad[COUNT_REMAIN]) << 7)
589+
/ scratchPad[COUNT_PER_C])) | neg;
590+
}
591+
557592
return fpTemperature;
558593
}
559594

‎DallasTemperature.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef DallasTemperature_h
22
#define DallasTemperature_h
33

4-
#define DALLASTEMPLIBVERSION "4.0.1"
4+
#define DALLASTEMPLIBVERSION "4.0.2"
55

66
// Configuration
77
#ifndef REQUIRESNEW

‎examples/Simple/Simple.ino

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void loop(void)
3434
Serial.print("Requesting temperatures...");
3535
sensors.requestTemperatures(); // Send the command to get temperatures
3636
Serial.println("DONE");
37+
delay(1500);
3738
// After we got the temperatures, we can print them here.
3839
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
3940
float tempC = sensors.getTempCByIndex(0);

‎examples/Single/Single.ino

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void loop(void)
105105
Serial.print("Requesting temperatures...");
106106
sensors.requestTemperatures(); // Send the command to get temperatures
107107
Serial.println("DONE");
108+
delay(1500);
108109

109110
// It responds almost immediately. Let's print out the data
110111
printTemperature(insideThermometer); // Use a simple function to print out the data

‎examples/WaitForConversion/WaitForConversion.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ void loop(void)
6262
Serial.println(sensors.getTempCByIndex(0));
6363
Serial.println("\n\n\n\n");
6464

65-
delay(5000);
65+
delay(1500);
6666
}

‎library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{
3333
"paulstoffregen/OneWire": "^2.3.5"
3434
},
35-
"version": "4.0.1",
35+
"version": "4.0.2",
3636
"frameworks": "arduino",
3737
"platforms": "*"
3838
}

‎library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DallasTemperature
2-
version=4.0.1
2+
version=4.0.2
33
author=Miles Burton <mail@milesburton.com>, Tim Newsome <nuisance@casualhacker.net>, Guil Barros <gfbarros@bappos.com>, Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Miles Burton <mail@milesburton.com>
55
sentence=Arduino library for Dallas/Maxim temperature ICs

0 commit comments

Comments
 (0)