Skip to content

Commit 12057cf

Browse files
authored
sync DS18B20_RT (#21)
- sync DS18B20_RT (GND error)
1 parent fa4d53e commit 12057cf

File tree

7 files changed

+81
-23
lines changed

7 files changed

+81
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.3.5] - 2026-01-24
10+
- sync DS18B20_RT (GND error)
11+
912
## [0.3.4] - 2026-01-02
1013
- update GitHub actions
1114
- update examples

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,38 @@ Note: thicker wires require smaller resistors (typically 1 step in E12 series)
187187
\* = no info, smaller?
188188

189189

190+
### Diagnostic notes
191+
192+
It was noted that the library sometimes give unexpected values, and keep
193+
sending these values.
194+
195+
This is due to the fact that by default the CRC is not checked to speed up reading.
196+
In fact, only the two temperature registers are read.
197+
198+
Table of known "strange values" and actions one could take.
199+
It is meant to start some diagnosis.
200+
201+
(note these are all known errors, not perse for this library)
202+
203+
| value | possible cause | optional action |
204+
|:--------|:------------------------------------|:------------------|
205+
| 0.0000 | data line has no pull up | use pull up
206+
| -0.0625 | data line is constantly pulled HIGH | check GND
207+
| -127 | DISCONNECTED | check wires
208+
| -128 | CRC error | wrong pull up, bad sensor ? |
209+
| -129 | POR error | no convert done after power up. redo convert call.
210+
| -130 | GND error | if parasitic mode, check Vdd must be connected to GND.
211+
212+
If a value occurs only once in a while, wiring is often the cause,
213+
or it can be caused by e.g. induction e.g. switching on a motor while
214+
sensor is read.
215+
216+
Additional notes:
217+
218+
- https://github.com/milesburton/Arduino-Temperature-Control-Library/pull/289
219+
220+
221+
190222
## Performance
191223

192224
To elaborate connected state.

examples/DS18B20_performance/DS18B20_performance.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: DS18B20_performance.ino
33
// AUTHOR: Rob Tillaart
4-
// PURPOSE: DS18B20 lib getAddress demo
4+
// PURPOSE: measure performance
55
// URL: https://github.com/RobTillaart/DS18B20_INT
66

77

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"version": "^2.3.5"
2424
}
2525
],
26-
"version": "0.3.4",
26+
"version": "0.3.5",
2727
"license": "MIT",
2828
"frameworks": "*",
2929
"platforms": "*",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DS18B20_int
2-
version=0.3.4
2+
version=0.3.5
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Library for DS18B20 restricted to a single sensor per pin.

src/DS18B20_INT.cpp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: DS18B20_INT.cpp
33
// AUTHOR: Rob.Tillaart
4-
// VERSION: 0.3.4
4+
// VERSION: 0.3.5
55
// DATE: 2017-07-25
66
// PURPOSE: library for DS18B20 temperature sensor - integer only.
77
// URL: https://github.com/RobTillaart/DS18B20_INT
@@ -51,8 +51,8 @@ bool DS18B20_INT::isConnected(uint8_t retries)
5151
_oneWire->reset_search();
5252
_deviceAddress[0] = 0x00;
5353
_oneWire->search(_deviceAddress);
54-
_addressFound = _deviceAddress[0] != 0x00 &&
55-
_oneWire->crc8(_deviceAddress, 7) == _deviceAddress[7];
54+
_addressFound = (_deviceAddress[0] != 0x00) &&
55+
(_oneWire->crc8(_deviceAddress, 7) == _deviceAddress[7]);
5656
}
5757
return _addressFound;
5858
}
@@ -85,16 +85,25 @@ bool DS18B20_INT::isConversionComplete(void)
8585
}
8686

8787

88-
int16_t DS18B20_INT::getTempC(bool connectCheck)
88+
int16_t DS18B20_INT::getTempC(bool checkConnect)
8989
{
90-
if (connectCheck)
90+
ScratchPad scratchPad;
91+
if (checkConnect)
9192
{
9293
if (isConnected(3) == false)
9394
{
9495
return DEVICE_DISCONNECTED;
9596
}
9697
}
97-
int16_t rawTemperature = _readRaw();
98+
readScratchPad(scratchPad, 2);
99+
// Power On Reset 85C error cannot be tested here
100+
// the 127.94 error can be checked here
101+
if ((scratchPad[1] == 0x07) && (scratchPad[0] == 0xFF))
102+
{
103+
return DEVICE_GND_ERROR;
104+
}
105+
106+
int16_t rawTemperature = (((int16_t)scratchPad[1]) << 8) | scratchPad[0];
98107
rawTemperature >>= 4;
99108
if (rawTemperature < -55)
100109
{
@@ -123,18 +132,26 @@ uint8_t DS18B20_INT::getResolution()
123132

124133
int16_t DS18B20_INT::getTempCentiC(void)
125134
{
135+
ScratchPad scratchPad;
126136
if (isConnected(3) == false)
127137
{
128-
return DEVICE_DISCONNECTED;
138+
return DEVICE_DISCONNECTED * 100;
139+
}
140+
readScratchPad(scratchPad, 2);
141+
// Power On Reset 85C error cannot be tested here
142+
// the 127.94 error can be checked here
143+
if ((scratchPad[1] == 0x07) && (scratchPad[0] == 0xFF))
144+
{
145+
return DEVICE_GND_ERROR * 100;
129146
}
130-
int16_t rawTemperature = _readRaw();
147+
int16_t rawTemperature = (((int16_t)scratchPad[1]) << 8) | scratchPad[0];
131148
// rawTemperature = rawTemperature * 100 / 16;
132149
rawTemperature *= 25;
133-
rawTemperature >>= 2;
150+
rawTemperature >>= 4;
134151
// use at own risk. (not tested)
135152
if (rawTemperature < -5500)
136153
{
137-
return DEVICE_DISCONNECTED * 100;
154+
return DEVICE_DISCONNECTED;
138155
}
139156
return rawTemperature;
140157
}
@@ -144,16 +161,17 @@ int16_t DS18B20_INT::getTempCentiC(void)
144161
//
145162
// PRIVATE
146163
//
147-
int16_t DS18B20_INT::_readRaw(void)
164+
void DS18B20_INT::readScratchPad(uint8_t *scratchPad, uint8_t fields)
148165
{
149166
_oneWire->reset();
150167
_oneWire->select(_deviceAddress);
151168
_oneWire->write(READSCRATCH);
152169

153-
int16_t rawTemperature = ((int16_t)_oneWire->read());
154-
rawTemperature |= _oneWire->read() << 8;
170+
for (uint8_t i = 0; i < fields; i++)
171+
{
172+
scratchPad[i] = _oneWire->read();
173+
}
155174
_oneWire->reset();
156-
return rawTemperature;
157175
}
158176

159177

src/DS18B20_INT.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: DS18B20_INT.h
44
// AUTHOR: Rob.Tillaart
5-
// VERSION: 0.3.4
5+
// VERSION: 0.3.5
66
// DATE: 2017-07-25
77
// PURPOSE: Minimalistic library for DS18B20 temperature sensor
88
// uses only integer math (no float to minimize footprint)
@@ -25,13 +25,17 @@
2525
#include "OneWire.h"
2626

2727

28-
#define DS18B20_INT_LIB_VERSION (F("0.3.4"))
28+
#define DS18B20_INT_LIB_VERSION (F("0.3.5"))
2929

30-
// Error Code
31-
#define DEVICE_DISCONNECTED -127
30+
// Error Codes (not all used)
31+
const int DEVICE_DISCONNECTED = -127;
32+
const int DEVICE_CRC_ERROR = -128;
33+
const int DEVICE_POR_ERROR = -129;
34+
const int DEVICE_GND_ERROR = -130; // parasitic power Vdd must GND
3235

3336

3437
typedef uint8_t DeviceAddress[8];
38+
typedef uint8_t ScratchPad[9];
3539

3640

3741
class DS18B20_INT
@@ -43,9 +47,10 @@ class DS18B20_INT
4347
bool getAddress(uint8_t * buf);
4448

4549
void requestTemperatures(void);
46-
int16_t getTempC(bool connectCheck = true);
50+
int16_t getTempC(bool checkConnect = true);
4751
bool isConversionComplete(void);
4852

53+
// for getTempCentiC()
4954
bool setResolution(uint8_t resolution = 9);
5055
uint8_t getResolution(); // returns cached value
5156

@@ -58,7 +63,7 @@ class DS18B20_INT
5863
bool _addressFound;
5964

6065
uint8_t _resolution;
61-
int16_t _readRaw();
66+
void readScratchPad(uint8_t *scratchPad, uint8_t fields);
6267
void _setResolution();
6368
};
6469

0 commit comments

Comments
 (0)