DS18B20P Library

It took me quite a while to get my DS18B20P (aka. DS18B20P-PAR) to work properly and give me nice readable Celsius values. I finally got it all to work while keeping the code somewhat clean by using a slightly modified OneWire library and wrapping my own library around it.

I couldn’t find any other way to do this, but I wanted to give you guys access to my code, and my changes to the OneWire library (I already sent them over email to the guy who released the latest version). I released my code under Creative Commons Attribution-ShareAlike 3.0 Unported License, the OneWire library is using some different license (explained in the OneWire.cpp source).

You can find the code, with an example implementation at http://lietu.net/index.php/releases under the “DS18B20P Library” section. You need to wire your sensor as in the diagram at the top of http://forums.fungizmos.com/viewtopic.php?f=6&t=2 or in the datasheet page 3 at http://datasheets.maxim-ic.com/en/ds/DS18B20-PAR.pdf

I also attached the code here, so you can access it in case my homepages are down…

ds18b20p.zip (11.3 KB)

I had no trouble talking to multiple DS18B20 chips with the existing OneWire.h. The example code was able to scan the wire for thermometers and report their addresses:


Please don’t take this the wrong way, but what functionality does your new code provide that wasn’t already provided by the existing onewire libraries? The DS18B20 is probably the most widely used 1-wire device. Am I missing something here? (note: I’m probably missing something here )

Hmm. I've had no problem with multiple DS18B20's using: http://www.milesburton.com/?title=Dallas_Temperature_Control_Library

Here's my How-To information on these thermometers: http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20

Regards, Terry King ...In The Woods In Vermont terry@yourduino.com

Well, when I was trying to get mine to work, I also noticed most other people seemed to have no issues with theirs.. However, most of them did not work for me at all, and the one piece of code that finally was able to read data from the sensor gave junk output a that made no sense, e.g. it said the temperature was 1800, when I touched the sensor for a second it was 2600, etc.

There are really not many differences to the already existing OneWire library and other pieces of code on the net, but a few still: 1) This one works for me 2) This one gives useful data, in celsius with decimal precision, e.g. if the sensor thinks it's 24.56C, it will return "24.56" 3) This one requires you to just run .read() to get data, not ".reset(); .skip(); .write(); delay(); .reset(); .skip(); .write(); .read(); ..." 4) This code is not that painful to look at 5) It actually might give you a clue of what error you have, if you have one, instead of just saying "if you get result -10000 you have an error"

... at some point I will probably add the support to give it an address for the sensor, at the moment it uses .skip() as I really don't need the hassle of supporting a gazillion sensors on the one pin. Also I was planning on giving you the option to decide what to do with the 800msec it takes for the sensor to do it's temperature calculations, instead of pointlessly sleeping it away in my code. Neither of these is really a high priority for me, I need data out of the sensor like once every 5 minutes, and I will just have a couple of sensors so I might just as well use different pins for them..