DS18B20 Libraries, a search

I was exploring the various libraries for the DS18B20 temp sensors. As a simple test, I complied the most basic, single sensor per pin sketch in each library and noted the memory and storage allocation. Results at end.

The one I have been using for quite a while is the DS18B20.h by Mathias Munk Hansen. It has been great except I recently discovered that a disconnected sensor reports 0 deg C. This happens to be a pretty common measurement for me and thus having the (sensorDisconnected) result in the middle of the range is difficult to filter out, should something go wrong.
DallasTemperature.h instead reports a -127. That's perfect as I will never run into that actual measurement. However, DallasTemperature.h is the largest complied library.

As it appears that Tillaart's DS18B20_INT.h is the smallest footprint and is derrived from Burton's DallasTemperature.h (which reports -127 on disconnect) I dug in there.
Compiling and uploading both the simple.ino and minimum.ino however, neither reports -127 on disconnect. minimum.ino reports a 0 on disconnect and simple.ino reports a -1 or a 0 depending on which pin is disconnected.

Even stranger is that on line 30 of DS18B20_INT.h is: "#define DEVICE_DISCONNECTED -127". Which should have something to do with reporting that value if the device is found to be disconnected. I thought perhaps that was not used in the "stripped down" versions of DS18B20_INT.h so I used the main example of the same title. It freeze on disconnect due to a while loop which I commented out, after which it only reported a 0.

Could I enlist your advice on selecting a library which is:
low in resources, has few features as I am only using one sensor on one pin (no alarms, bells, whistles, etc)
can be slow or fast read time, performance is not a constraint
reports an easily identifiable value when sensor disconnected

or any pointers to modify the DS18B20_INT library to do the same.

comparing ds18b20 libraries

DS18B20.h single.ino
by Mathias Munk Hansen
5162 b storage
301 b of memory

DS18B20_INT.h minimum.ino
by Rob Tillaart
3324 b storage
320 b memory

DS18B20_RT.h several
by Rob Tillaart, unsure of difference to DS18B20_INT.h
could not compile examples
missing library version etc..

DallasTemperature.h simple.ino
aka Arduino-Temperature-Control by Miles Burton
5670 b storage
401 b memory

MaximWire.h AnyDevice.ino
could not compile
missing nrf_gpio.h

microDS18B20.h one_pin_one_sensor.ino
4812 b storage
228 b memory

pick the one you like best. Are you running out of code space, if not do not worry about the memory usage. As you noted you get different features and different size files, it is a trade off unless you write your own.

Then you probably don't need a library.
Using a DS18B20 SHEEPDOG

1 Like

thanks. good read and neat to see it built up with explanation. Taking his newer version and compiling it results:
5486 b storage
344 b memory

putting it on par with DallasTemperature.h

I contacted Rob Tillaart on GitHub and he clarified that his library is similar to DallasTemperature but was mostly written from scratch. Here is the conversation and what he said about that:

Blockquote Not exactly, I started with a stripped down version of the library to see if I could meet my requirements (minimal footprint).
Then I rewrote it into DS18B20_RT, essentially from scratch, while preserving the function names.
From that one I derived an integer only version DS18B20_INT to prevent including the float math library.

He made a branch and update and I am testing it currently. It went from a 0 on disconnect to a -1. abs(-1) step closer to -127!

Something to consider, if you use floating point numbers anywhere else in your code, the floating point library will be included, so the size reduction from the DS18B20_INT library will be much less significant.

great point!

they dont float my boat for most projects. I normally do a decimal shift like using centi volts or deci seconds or whatever to avoid a float and fit it in a word or byte for extra points. Then I include the units in the variable name to keep things straight.

A DS18B20 library that returns the temperature as an int in 10ths or 100ths of a degree might be useful.

1 Like

Screen Shot 02-04-23 at 02.04 AM
.

Rob did it!
This version is currently in the DS18B20_INT develop branch
image

OneWire.h Library takes:
4092 bytes of Flash Memory
231 bytes of RAM Memory

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.