Arduino temperature control library

Dallas Temperature Control Library

Contents

Introduction

The DS18B20 is a very small thermometer which can be easily hooked into the Arduino MCU through any digital input! It requires very little in the way of additional support, a couple of resistors and some hookup cables and you’re set to go.

For more information on the DS18B20 check out [Maxim-IC].

The Library

This library is derived from some good work by the Arduino community. This library is, for the most part, purely a refactor version of the existing library. I found the original to be somewhat of a pain to implement and, like most Arduino libraries, code-seperation sucks.

The intention of this Library is to build on Jim Studt work and make it quick and easy for beginners to get started.

If you are interested [Beginning Arduino] covers this library in-depth for new users.

Supported Devices

  • DS18B20
  • DS1822
  • DS18S20*
  • DS1820

Additional devices can be implemented through different temperature strategies. Refer to the code for more information.

*Problems reported on this series

Limitations

  • The One-Wire library has a nasty look-up table for some associated commands. It isn’t directly related to this library but it may cause some problems.

Benefits

  • Simple and easy to use
  • No software limitation to the number of devices you may use

Installation

Very little in the way of «installation» is required. [Unrar] the contents of the library to sketchbook-location\libraries. You can look up the sketchbook-location in the Arduino software under «File > Preferences». After copying the oneWire folder into the libraries folder, restart the Arduino software. Now the library should show up under «Skech > Import library > Contributed». If you already have «OneWire» library, only copy over the DallasTemperature folder to \libraries. Make sure you delete any old versions before you continue (or if you’re testing a PRE version, move it out of the \libraries directory so it doesn’t conflict).

The IC itself has two modes, parasitism or powered mode. The latter can be found in the appropriate documentation. I commonly use the former as it reduces the number of wires I need to maintain.

You may power the IC using a technique known as a «Pull-up». You will need a pull-up resistor of about 5 KOhm between the 1-Wire data line and your 5V power. If you are using the DS18B20, ground pins 1 and 3. The centre pin is the data line (‘1-wire’).

Try out the example when you’ve loaded up the Arduino IDE

Comments

Niclas Hedhman has raised these very interesting point. Please consider his advice:

I have a lot of experience with this little bugger, all the way back to 1997. And it is NOT possible to run DS1820 sensors on a simple pull-up resistor. During the «Conversion» phase, it needs more power. And there are Application Note discussing this in length.

Conversion time on the 18B20 at max resolution is something like 1 second IIRC. Your library is «just waiting» meanwhile. I guess this is fine for hobbyistic projects, but it is really a waste of good CPU time. Do you have any thoughts on how to make that «multi tasking»? Something like, return immediately with some «Future» or «Promise» which I can poll for completion. I know that is not so straight forward in C, but I am sure you understand what I mean.

Example

The TCL library is intended to be simple and intuitive to use. You only need 3 fundamental commands for a single IC. (Following code taken from «Simple.pde» 3.1.0PRE)

Download

Code/Library

Github

Github will always have the latest code, however you can also access the TCL from the Arduino Library manager https://github.com/milesburton/Arduino-Temperature-Control-Library — A snapshot release. Please request commit access to contribute.

Archive

One Wire Library

OneWire 2 — I recommend you use OneWire 2, a spiritual successor to the original OneWire library. PJRC has developed this library to fix many of the original bugs found in OneWire. If you find OneWire to be unreliable I would highly recommend this drop-in replacement.

Datasheet

DS18B20 Datasheet — One of the better datasheets I’ve seen. Contains all the technical details you need to setup your IC

History

[1.0] First version

[1.5.0 Test] Includes negative temperature support

[2.0.0] Updated by Tim Newsome to include support for multiple ICs on the same OneWire

[2.0.1] A slightly leaner version of 2.0.0

[2.5.0] James Whiddon has re-factored the core code to provide accurate timings, increased sensor resolution, detect parasite power (etc).

[3.0.0] Another addition by James Whiddon. He has re-factored much of the original code and included a new example sketch.

[3.0.0b] Includes a fix for the S series of devices by Nic Johns

[3.1.0] Heavily re-factored version of 3.0.0b. Includes 4 new sketches and several additional functions to make sketches simple for new user who ‘just want to get going’

[3.2.0] Separated OneWire and DallasTemperature libraries so you only need to install one if you’ve already got OneWire installed (avoids those annoying conflicts). This includes full support for alarms and a supporting example. We have also included a couple of definitions should you want to remove the alarm functionality to save some memory

  • bool hasAlarm(void); This allows you to know if ANY device is reporting an alarm without having to scan each device on the bus.
  • void setAlarmHandler(AlarmHandler *); You can define a function that will be executed when an alarm condition

exists on a device. The function takes a device address as an argument. The handler is executed when processAlarms() is called.

  • void processAlarms(void); Used in loop(). Performs an alarmSearch() and calls the appropriate AlarmHandler for any devices with alarms.
  • AlarmHandler.pde example included.
  • private float calculateTemperature(uint8_t*, uint8_t*); This was done so the hasAlarm(uint8_t*) function didn’t have to read the scratchpad twice or include duplicate code for measuring the temperature. Change is invisible to the end user.
  • Updated keywords.txt

— Thanks James for another update

  • Fixed incorrect address array sizes in hasAlarm and processAlarms
  • setResolution now only reads the scratchpad once
  • setHighAlarmTemp and setLowAlarmTemp now read the scratchpad to ensure

the scratchpad contains the data for the device address you’re setting

  • Changed DEVICE_DISCONNECTED value to -127 so it can be passed as a

result in functions returning a char value

  • getLowAlarmTemp and getHighAlarmTemp now return DEVICE_DISCONNECTED if

the device is disconnected

  • Added typedef uint8_t DeviceAddress[8] (hopefully to help prevent

mistakes like were in hasAlarm and processAlarms)

  • Added typedef uint8_t ScratchPad[9]
  • Updated demo sketches to use DeviceAddress typedef
  • Guil Barros submitted two additional functions, GetTemperatureByIndex & GetTemperatureByAddress to make life a little easier
  • Device count is reset when you call the begin() method. This allows you to detect new ICs without resetting your MCU. Many thanks to two contributors for emailing me this fix! Great Work Peter Maag & Paolo Bosetti.
  • Rob Tillaart was kind enough to introduce a new revision to the library, asynchronous calls. When you request a temperature you can choose to manage the delay in your own code and continue processing other data. This code is still considered beta so if you spot any issues let me know.

[3.7.1] Daniel Seither has cleaned up some of the example files for better legibility, thanks Daniel.

If you have any comments or bugs, drop me a line at tmcs miles AT gmail dot com

Notes: Bugzilla removed for the moment

Troubleshooting

I’ve had several reports of issues where the temperature IC will return a odd result. This can be indicative of insufficient power. I have found after about 3 ICs a parasite power set-up can fail to provide enough current to produce an accurate result. The best way to fix this problem is to use the dedicated power pin (VCC). If you must use parasite mode, try dropping the pull-up resistance or reducing the frequency at which you poll the IC.

Each IC has a small capacitor which must be charged before you request a temperature. If this capacitor has insufficient charge the results may be invalid.

Media

License

Arduino Library for Dallas Temperature ICs, version 2.5.0 Credits

The OneWire code has been derived from

Miles Burton originally developed this library.

Tim Newsome added support for multiple sensors on

James Whiddon has refactored the core code to provide accurate timings, increased sensor resolution, detect parasite power (etc).

This library is free software; you can redistribute it and/or

modify it under the terms of the GNU Lesser General Public

License as published by the Free Software Foundation; either

version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public

License along with this library; if not, write to the Free Software

Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Источник

milesburton/Arduino-Temperature-Control-Library

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Arduino Library for Maxim Temperature Integrated Circuits

This library supports the following devices :

  • DS18B20
  • DS18S20 — Please note there appears to be an issue with this series.
  • DS1822
  • DS1820
  • MAX31820
  • MAX31850

You will need a pull-up resistor of about 5 KOhm between the 1-Wire data line and your 5V power. If you are using the DS18B20, ground pins 1 and 3. The centre pin is the data line ‘1-wire’.

In case of temperature conversion problems (result is -85 ), strong pull-up setup may be necessary. See section Powering the DS18B20 in DS18B20 datasheet (page 7) and use DallasTemperature(OneWire*, uint8_t) constructor.

We have included a «REQUIRESNEW» and «REQUIRESALARMS» definition. If you want to slim down the code feel free to use either of these by including

at the top of DallasTemperature.h

Finally, please include OneWire from Paul Stoffregen in the library manager before you begin.

The OneWire code has been derived from http://www.arduino.cc/playground/Learning/OneWire. Miles Burton miles@mnetcs.com originally developed this library. Tim Newsome nuisance@casualhacker.net added support for multiple sensors on the same bus. Guil Barros [gfbarros@bappos.com] added getTempByAddress (v3.5) Note: these are implemented as getTempC(address) and getTempF(address) Rob Tillaart [rob.tillaart@gmail.com] added async modus (v3.7.0)

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

About

Arduino plug and go library for the Maxim (previously Dallas) DS18B20 (and similar) temperature ICs

Источник

Arduino temperature control library

Copy raw contents

Copy raw contents

Arduino Library for Maxim Temperature Integrated Circuits

This library supports the following devices :

  • DS18B20
  • DS18S20 — Please note there appears to be an issue with this series.
  • DS1822
  • DS1820
  • MAX31820
  • MAX31850

You will need a pull-up resistor of about 5 KOhm between the 1-Wire data line and your 5V power. If you are using the DS18B20, ground pins 1 and 3. The centre pin is the data line ‘1-wire’.

In case of temperature conversion problems (result is -85 ), strong pull-up setup may be necessary. See section Powering the DS18B20 in DS18B20 datasheet (page 7) and use DallasTemperature(OneWire*, uint8_t) constructor.

We have included a «REQUIRESNEW» and «REQUIRESALARMS» definition. If you want to slim down the code feel free to use either of these by including

at the top of DallasTemperature.h

Finally, please include OneWire from Paul Stoffregen in the library manager before you begin.

The OneWire code has been derived from http://www.arduino.cc/playground/Learning/OneWire. Miles Burton miles@mnetcs.com originally developed this library. Tim Newsome nuisance@casualhacker.net added support for multiple sensors on the same bus. Guil Barros [gfbarros@bappos.com] added getTempByAddress (v3.5) Note: these are implemented as getTempC(address) and getTempF(address) Rob Tillaart [rob.tillaart@gmail.com] added async modus (v3.7.0)

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Источник

Adblock
detector