Yet another DS18B20 library - the minimal approach

First I am a great fan of the Dallas Temperature Control Library (DTCL) of Miles Burton, however some time ago I needed to strip it down to save a few dozen bytes.

Today I reworked that minimalistic version into a class called DS18B20. I added some examples to help people get started. The library is published on https://github.com/RobTillaart/Arduino/tree/master/libraries/DS18B20

The DS18B20 library supports only the DS18B20, only one sensor per pin, no parasite mode, no Fahrenheit and no alarm function. The only feature the class supports is the asynchrone way of working by means of the three functions:
requestTemperatures() --> isConversionAvailable() --> readTempC()
This allowed the class to be both minimal in size and still be non-blocking. Furthermore it has a begin() and a setResolution() function.

The DS18B20_simple.ino sketch (see below) which is quite similar to the DTCL simple.ino example, compiles about 1KB smaller using the IDE 1.8.1. for an Arduino Uno.

As the async mode is faster I added an example to see the timing to get a read compared to the "proposed delay times". In my testruns I saw 10% to almost 20% shorter times depending on resolution (this may depend on sensor used and/or temperature, not tested extensively)

As always remarks and comments are welcome,

Rob

//
//    FILE: DS18B20_simple.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.0.1
// PURPOSE: equivalent of DallasTemperature library Simple
//
// HISTORY:
// 0.0.1 = 2017-07-25 initial version

#include <OneWire.h>
#include <DS18B20.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DS18B20 sensor(&oneWire);


void setup(void)
{
  Serial.begin(115200);
  Serial.println(__FILE__);
  Serial.print("DS18B20 Library version: ");
  Serial.println(DS18B20_LIB_VERSION);

  sensor.begin();
}


void loop(void)
{ 
  sensor.requestTemperatures();
  
  while (!sensor.isConversionComplete());  // wait until sensor is ready
  
  Serial.print("Temp: ");
  Serial.println(sensor.getTempC());
}

I believe this will be quite useful for situations where you are using ICs with far less ROM available - particularly in power sensitive environments.

As per my email, I suggest we add a note to the README.md file on both libraries to make users aware.

-Miles

Added a readme.md

Hi Rob,
Nice job. I noticed a few minor typos in readme.md:
asynchrone -> asynchronous
synchronuous -> synchronous
This choice will learn -> This choice will teach
with relative few problems -> with relatively few problems

Pete

Thanks Pete,

Fixed them, never too old to learn :slight_smile: