dallas temperature control library - miles burton - innovative engineering for pretty much anything

11
2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering« 1/11 www.milesburton.com/Dallas_Temperature_Control_Library Dallas Temperature Control Librar\ From Miles Burton - Innovative engineering for prett\ much an\thing Contents 1 IQWURdXcWiRQ 2 The LibUaU\ 2.1 SX SSRUWed DeYiceV 3 LiPiWaWiRQV 4 BeQefiWV 5 IQVWaOOaWiRQ 6 E[aPSOe 7 DRZQORad 7.1 CRde/LibUaU\ 7.1.1 LaWeVW 7.2 OSeQ SRXUce CROOabRUaWiRQ 7.2.1 AUchiYe 7.3 OQe WiUe LibUaU\ 7.4 DaWaVheeW 8 HiVWRU\ 9 BXgV 10 TURXbOeVhRRWiQg 11 Media 12 LiceQVe Introduction The DS18B20 iV a YeU\ VPaOO WheUPRPeWeU Zhich caQ be eaViO\ hRRNed iQWR Whe AUdXiQR MCU Wh URXgh aQ\ digiWaO iQSXW! IW UeTXiUeV YeU\ OiWWOe iQ Whe Za\ Rf addiWiRQaO VXSSRUW, a cRXSOe Rf UeViVWRUV aQd VRPe hRRNXS cabOeV aQd \RX'Ue VeW WR gR. FRU PRUe iQfRUPaWiRQ RQ Whe DS18B20 checN RXW [Ma[iP-IC (hWWS://ZZZ.Pa[iP-ic.cRP/TXicN_YieZ2.cfP? TY_SN=2812) ]. The Librar\ ThiV OibUaU\ iV deUiYed fURP VRPe gRRd ZRUN b\ Whe AUdXiQR cRPPXQiW\. ThiV OibUaU\ iV, fRU Whe PRVW SaUW, SXUeO\ a UefacWRU YeUViRQ Rf Whe e[iVWiQg OibUaU\. I fRXQd Whe RUigiQaO WR be VRPeZhaW Rf a SaiQ WR iPSOePeQW aQd, OiNe PRVW AUdXiQR OibUaUieV, cRde-VeSeUaWiRQ VXcNV. The iQWeQWiRQ Rf WhiV LibUaU\ iV WR bXiOd RQ JiP SWXdW ZRUN aQd PaNe iW TXicN aQd eaV\ fRU begiQQeUV WR geW VWaUWed.

Upload: ricardo-jose-bastos

Post on 19-May-2017

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

1/11www.milesburton.com/Dallas_Temperature_Control_Library

Dallas Temperature Control Library

From Miles Burton - Innovative engineering for pretty much anything

Contents

1 Introduction

2 The Library

2.1 Supported Devices3 Limitations4 Benefits

5 Installation

6 Example7 Download

7.1 Code/Library

7.1.1 Latest

7.2 Open Source Collaboration

7.2.1 Archive

7.3 One Wire Library

7.4 Datasheet

8 History

9 Bugs

10 Troubleshooting

11 Media

12 License

Introduction

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

For more information on the DS18B20 check out [Maxim-IC (http://www.maxim-ic.com/quick_view2.cfm?qv_pk=2812) ].

The Library

This library is derived from some good work by the Arduino community. This library is, for the most part, purelya refactor version of the existing library. I found the original to be somewhat of a pain to implement and, likemost 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 getstarted.

Page 2: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

2/11www.milesburton.com/Dallas_Temperature_Control_Library

If you are interested [Beginning Arduino (http://rcm-uk.amazon.co.uk/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=n074f-21&o=2&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=1430232404) ] covers this library in-depth for newusers.

Supported Devices

DS18B20

DS1822

DS18S20*

DS1820

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

*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 useNo software limitation to the number of devices you may use

Installation

Very little in the way of "installation" is required. [Unrar (http://www.rarlabs.com) ] the contents of the library tosketchbook-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 thelibrary 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 youcontinue (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 appropriatedocumentation. 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 5KOhm 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

Example

Page 3: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

3/11www.milesburton.com/Dallas_Temperature_Control_Library

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

Download

Code/Library

Latest

TCL 3.7.1 (http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_371Beta.zip)

Open Source Collaboration

0 1 .0 2 .0 3 .0 4 .0 5 .0 6 .0 7 .

0 8 .0 9 .1 0 .1 1 .1 2 .1 3 .1 4 .1 5 .1 6 .1 7 .1 8 .1 9 .2 0 .

2 1 .2 2 .2 3 .2 4 .2 5 .2 6 .

2 7 .2 8 .2 9 .

3 0 .3 1 .3 2 .3 3 .

3 4 .3 5 .

# i n c l u d e < O n e W i r e . h ># i n c l u d e < D a l l a s T e m p e r a t u r e . h > / / D a t a w i r e i s p l u g g e d i n t o p i n 2 o n t h e A r d u i n o# d e f i n e O N E _ W I R E _ B U S 2 / / S e t u p a o n e W i r e i n s t a n c e t o c o m m u n i c a t e w i t h a n y O n e W i r e d e v i c e s

( n o t j u s t M a x i m / D a l l a s t e m p e r a t u r e I C s )O n e W i r e o n e W i r e ( O N E _ W I R E _ B U S ) ; / / P a s s o u r o n e W i r e r e f e r e n c e t o D a l l a s T e m p e r a t u r e .D a l l a s T e m p e r a t u r e s e n s o r s ( & o n e W i r e ) ; v o i d s e t u p ( v o i d ){

/ / s t a r t s e r i a l p o r tS e r i a l . b e g i n ( 9 6 0 0 ) ;S e r i a l . p r i n t l n ( " D a l l a s T e m p e r a t u r e I C C o n t r o l L i b r a r y D e m o " ) ;

/ / S t a r t u p t h e l i b r a r ys e n s o r s . b e g i n ( ) ; / / I C D e f a u l t 9 b i t . I f y o u h a v e t r o u b l e s

c o n s i d e r u p p i n g i t 1 2 . U p s t h e d e l a y g i v i n g t h e I C m o r e t i m e t op r o c e s s t h e t e m p e r a t u r e m e a s u r e m e n t

} v o i d l o o p ( v o i d ){

/ / c a l l s e n s o r s . r e q u e s t T e m p e r a t u r e s ( ) t o i s s u e a g l o b a lt e m p e r a t u r e

/ / r e q u e s t t o a l l d e v i c e s o n t h e b u sS e r i a l . p r i n t ( " R e q u e s t i n g t e m p e r a t u r e s . . . " ) ;s e n s o r s . r e q u e s t T e m p e r a t u r e s ( ) ; / / S e n d t h e c o m m a n d t o g e t

t e m p e r a t u r e sS e r i a l . p r i n t l n ( " D O N E " ) ; S e r i a l . p r i n t ( " T e m p e r a t u r e f o r D e v i c e 1 i s : " ) ;S e r i a l . p r i n t ( s e n s o r s . g e t T e m p C B y I n d e x ( 0 ) ) ; / / W h y " b y I n d e x " ? Y o u

c a n h a v e m o r e t h a n o n e I C o n t h e s a m e b u s . 0 r e f e r s t o t h e f i r s tI C o n t h e w i r e

}

Page 4: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

4/11www.milesburton.com/Dallas_Temperature_Control_Library

https://code.google.com/p/dallas-temperature-control-library/updates/list - A snapshot release. Please requestcommit access to contribute.

Archive

TCL 3.7.0 Beta(http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_370Beta.zip) - Beta release

Dallas IC Library (http://milesburton.com/downloads/Arduino/DallasTemperature/DallasTemperature.rar) -Version 1.0 IC Temperature Control Library (2009)

Maxim/Dallas IC Library(http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_150Test.zip) - Version1.5.0 Test Temperature Control Library (August 2009)

TCL 2.0 (http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_200.zip) - Version2.0.0 Temperature Control Library (September 2009)

TCL 2.0.1 (http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_201.zip) -Version 2.0.1 Temperature Control Library (September 2009)

TCL 2.5.0 (http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_250.zip) -Version 2.5.0 Temperature Control Library (September 2009)

TCL 2.6.0 PRE(http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_260PRE.zip) - Version2.6.0 Temperature Control Library Pre-release Beta (September 19th 2009)

TCL 3.0.0 PRE(http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_300PRE.zip) - Version3.0.0 Temperature Control Library Pre-release Beta (October 16th 2009).

TCL 3.0.0B PRE(http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_300bPRE.zip) - Version3.0.0B - Same as above but includes S series support. (October 20th 2009)

TCL 3.1.0 PRE(http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_310PRE.zip) - Version3.1.0PRE - Full support for the S series of ICs.(November 1st 2009)

TCL 3.1.0 PRE(http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_310PRE.zip) - Version3.1.0 PRE Full support for the S series of ICs.

TCL 3.2.0 (http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_320.zip) -Version 3.2.0 Final

TCL 3.3.0 (http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_330.zip) -Version 3.3.0 Final

TCL 3.4.0 (http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_340.zip) -Version 3.4.0

Page 5: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

5/11www.milesburton.com/Dallas_Temperature_Control_Library

Pre indicated a pre-release "non-final" version. This usually means some of the functionality is either notthoroughly tested or is still under development. Future versions may supersede a pre-release

TCL 3.5.0 (http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_350.zip) -Version 3.5.0 (16/2/2010)

TCL 3.6.0 (http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_360.zip) -Version 3.6.0 (1/10/2010)

One Wire Library

OneWire 2 (http://www.pjrc.com/teensy/td_libs_OneWire.html) - I recommend you use OneWire 2, a spiritualsuccessor to the original OneWire library. PJRC has developed this library to fix many of the original bugs foundin OneWire. If you find OneWire to be unreliable I would highly recommend this drop-in replacement.

Datasheet

DS18B20 Datasheet (http://datasheets.maxim-ic.com/en/ds/DS18B20.pdf) - One of the better datasheets I'veseen. 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 newexample 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 makesketches 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 gotOneWire installed (avoids those annoying conflicts). This includes full support for alarms and a supportingexample. We have also included a couple of definitions should you want to remove the alarm functionality tosave some memory

[3.3.0] [Below]

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

Page 6: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

6/11www.milesburton.com/Dallas_Temperature_Control_Library

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

void processAlarms(void); Used in loop(). Performs an alarmSearch() and calls the appropriateAlarmHandler for any devices with alarms.AlarmHandler.pde example included.

Core Updates:

private float calculateTemperature(uint8_t*, uint8_t*); This was done so the hasAlarm(uint8_t*) functiondidn't have to read the scratchpad twice or include duplicate code for measuring the temperature. Changeis invisible to the end user.

Updated keywords.txt

- Thanks James for another update

[3.4.0] Fixes:

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

Changes:

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

[3.5.0]

Guil Barros submitted two additional functions, GetTemperatureByIndex & GetTemperatureByAddress

to make life a little easier

[3.6.0]

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

Page 7: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

7/11www.milesburton.com/Dallas_Temperature_Control_Library

& Paolo Bosetti.

[3.7.0]

Rob Tillaart was kind enough to introduce a new revision to the library, asynchronous calls. When yourequest 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.

Bugs

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 ofinsufficient power. I have found after about 3 ICs a parasite power set-up can fail to provide enough current toproduce an accurate result. The best way to fix this problem is to use the dedicated power pin (VCC). If youmust 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 hasinsufficient charge the results may be invalid.

Media

Page 8: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

8/11www.milesburton.com/Dallas_Temperature_Control_Library

If you'd like to learn more about the DS18B20 and Arduino setup visit:http://www.synbio.org.uk/instrumentation-news/1484.html

Page 9: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

9/11www.milesburton.com/Dallas_Temperature_Control_Library

Page 10: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

10/11www.milesburton.com/Dallas_Temperature_Control_Library

Page 11: Dallas Temperature Control Library - Miles Burton - Innovative Engineering for Pretty Much Anything

2011-12-21 Dallas Temperature Control Library - Miles Burton - Innovative engineering…

11/11www.milesburton.com/Dallas_Temperature_Control_Library

License

Arduino Library for Dallas Temperature ICs, version 2.5.0 Credits

The OneWire code has been derived from

http://www.arduino.cc/playground/Learning/OneWire.

Miles Burton <******> originally developed this library.

Tim Newsome <******> added support for multiple sensors on

the same bus.

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

License

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

Retrieved from "http://www.milesburton.com/Dallas_Temperature_Control_Library"

This page was last modified on 4 December 2011, at 13:43.Content is available under GNU Free Documentation License 1.2.