<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>..the cat came back.. &#187; 1-Wire</title>
	<atom:link href="http://blog.automated.it/category/1-wire/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.automated.it</link>
	<description>i does tech i does.</description>
	<lastBuildDate>Wed, 25 Nov 2009 08:30:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Gratifying Graphic Gizmos</title>
		<link>http://blog.automated.it/2009/03/01/gratifying-graphic-gizmos/</link>
		<comments>http://blog.automated.it/2009/03/01/gratifying-graphic-gizmos/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 08:47:37 +0000</pubDate>
		<dc:creator>ScaredyCat / Andy Powell</dc:creator>
				<category><![CDATA[1-Wire]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[environment]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[Pachube]]></category>

		<guid isPermaLink="false">http://blog.automated.it/?p=207</guid>
		<description><![CDATA[Yesterday the Current Cost unit actually got installed for real, something I was dreading. Dreading not because it was a difficult thing to do but simply because I expected the figure it would show would be terrible. Guess what, it wasn&#8217;t. In fact it seemed to be fairly close to that of other people who [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday the <a href=http://www.currentcost.com/ target=_new>Current Cost</a> unit actually got installed for real, something I was dreading. Dreading not because it was a difficult thing to do but simply because I expected the figure it would show would be terrible. Guess what, it wasn&#8217;t. In fact it seemed to be fairly close to that of other people who are monitoring theirs. The initial figure of 371 Watts didn&#8217;t last too long once the dishwasher and oven came on and an interesting spike appeared when the hob went on for the kettle. </p>
<p><img class="left" title="Current Cost Graph" src="/images/gallery/environment/small_69.png" alt="" width="387" height="166" /><br />
<br/><br />
Continuing with my sudden graphing fetish, as well as using a Current Cost unit I have dotted a number of little devices I&#8217;ve built with <a href='http://www.digi.com/products/wireless/zigbee-mesh/' target=_new>Xbee</a> and <a href='http://arduino.cc' target=_new>Arduinos</a> to measure temperatures (and other things)  around the house. More information on those will come out later, but it&#8217;s an interesting project too. </p>
<p>Since I have the data for those it&#8217;d be rude not to graph them too, there&#8217;s a sample in the thumbnails below.</p>
<p>Not content with graphing them locally I picked up a <a href=http://www.pachube.com target=_new>Pachube</a> invite and started graphing data there too. The process is simple really and as you can see on the right hand side of this page under &#8216;Graphy Stuff&#8217;, graph images can be embedded in your own or other sites. The really interesting thing about Pachube is that you can <a href=http://www.pachube.com/feeds/1498 target=_new>share</a> your data with people who may be interested. The data they get to see is delayed by approximately 15 minutes. If you output your data in the <a href=http://community.pachube.com/?q=node/127>eeml</a> format then you can specify your own tags too.</p>
<p><a title="Electricity Usage Graph" rel="thumbnail" href="http://blog.automated.it/images/gallery/environment/graph_69_1.png"><img src="http://blog.automated.it/images/gallery/environment/thumb_graph_69_1.png" alt="Electricity Usage Graph" width="176" height="64" /></a><a title="Temperature in the garage" rel="thumbnail" href="http://blog.automated.it/images/gallery/environment/graph_70_1.png"><img src="http://blog.automated.it/images/gallery/environment/thumb_graph_70_1.png" alt="Temperature in the garage" width="176" height="64" /></a><br />
<br/></p>

<br><a href=http://blog.automated.it/2009/03/01/gratifying-graphic-gizmos/><p><img style='float:right;margin-left:15px;margin-bottom:10px;' src='http://blog.automated.it/images/tccb.png' border='0'></a></p><br>

<br><span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F&amp;title=Gratifying+Graphic+Gizmos" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F&amp;title=Gratifying+Graphic+Gizmos" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F&amp;title=Gratifying+Graphic+Gizmos" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F&amp;title=Gratifying+Graphic+Gizmos" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F&amp;title=Gratifying+Graphic+Gizmos', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://del.icio.us/favicon.ico" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F&amp;title=Gratifying+Graphic+Gizmos" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F&amp;title=Gratifying+Graphic+Gizmos" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
<a href="http://twitter.com/home?status=Currently reading http%3A%2F%2Fblog.automated.it%2F2009%2F03%2F01%2Fgratifying-graphic-gizmos%2F" title="Click to send this page to Twitter!" target="_blank"><img src="http://www.twitter.com/favicon.ico" width="16" height="16" alt="[Twitter]" /></a>
</span><br><br>]]></content:encoded>
			<wfw:commentRss>http://blog.automated.it/2009/03/01/gratifying-graphic-gizmos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One Wireduino made easy</title>
		<link>http://blog.automated.it/2009/02/04/one-wireduino-made-easy/</link>
		<comments>http://blog.automated.it/2009/02/04/one-wireduino-made-easy/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 21:46:25 +0000</pubDate>
		<dc:creator>ScaredyCat / Andy Powell</dc:creator>
				<category><![CDATA[1-Wire]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.automated.it/?p=204</guid>
		<description><![CDATA[For a very long time now I&#8217;ve been playing with the Arduino boards but it wasn&#8217;t until I recently discovered some DS1820 1-wire chips in my parts box that I started even thinking about 1-wire stuff. Connecting 1-wire devices to the Arduino is, well, amazingly simple. Using the sample circuit from the datasheet we can [...]]]></description>
			<content:encoded><![CDATA[<p>For a very long time now I&#8217;ve been <a href="http://blog.automated.it/2008/02/18/usb-controlled-rgb-blob/" target="_new">playing</a> with the <a title="Arduino" href="http://www.arduino.cc/" target="_blank">Arduino</a> boards but it wasn&#8217;t until I recently discovered some <a title="DS1820 (replacements)" href="http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3021" target="_blank">DS1820</a> 1-wire chips in my parts box that I started even thinking about 1-wire stuff. Connecting 1-wire devices to the Arduino is, well, amazingly simple. Using the sample circuit from the datasheet we can see the connections are few and far between.</p>
<p style="text-align: center;"><img class="aligncenter" title="DS1820 Circuit" src="/images/gallery/1wire/ds1820-circuit.png" alt="" width="415" height="135" /></p>
<p>Please note that this is the corrected circuit, previously the VDD was not tied to ground. While the circuit would work it would only give reliable results on very short runs. This circuit allows longer runs to the sensor.</p>
<p>Coding this up is also made extremely easy with the OneWire library. I&#8217;ve put together a little application below that will read all of the 1-wire devices on a bus. If you press L in the Arduino IDE serial monitor it will list all the 1-Wire device id&#8217;s and if you press T you&#8217;ll get the id and temperature reading.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
Simple 1-wire device reading
&nbsp;
Pass T over serial to get temperatures
Pass L to list 1-wire devices
&nbsp;
*/</span>
<span style="color: #339933;">#include &lt;OneWire.h&gt;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #339933;">#define CONVERT     0x44</span>
<span style="color: #339933;">#define READSCRATCH 0xBE</span>
<span style="color: #339933;">#define SKIP_ROM    0xCC</span>
<span style="color: #339933;">#define MATCH_ROM   0x55</span>
&nbsp;
OneWire  ds<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// The DS18S20 is connected on pin 10</span>
<span style="color: #993333;">int</span> ledPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">13</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// flash an led on 13 - we all like flashing lights</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// initialize inputs/outputs</span>
  <span style="color: #666666; font-style: italic;">// start serial port</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>ledPin<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//we'll use the led to output a heartbeat</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> incomingByte <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// read the incoming byte:</span>
		incomingByte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// say what you got:</span>
		<span style="color: #666666; font-style: italic;">//Serial.print(&quot;I received: &quot;);</span>
		<span style="color: #666666; font-style: italic;">//Serial.println(incomingByte, DEC);</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000dd;">84</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                  getStuff<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>^&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>incomingByte <span style="color: #339933;">==</span> <span style="color: #0000dd;">76</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                   listDevices<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> listDevices<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  byte addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  ds.<span style="color: #202020;">reset_search</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>ds.<span style="color: #202020;">search</span><span style="color: #009900;">&#40;</span>addr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
     digitalWrite<span style="color: #009900;">&#40;</span>ledPin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// sets the LED on</span>
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> OneWire<span style="color: #339933;">::</span><span style="color: #202020;">crc8</span><span style="color: #009900;">&#40;</span> addr<span style="color: #339933;">,</span> <span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>   <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #208080;">0x10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Make sure it is a DS18S20 device</span>
            <span style="color: #993333;">char</span> buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">512</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            sprintf<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;Id:%02x%02x%02x%02x%02x%02x%02x%02x<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
                       addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                       addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
              Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'^'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> getStuff<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  byte i<span style="color: #339933;">;</span>
  byte present <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  byte data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">12</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  byte addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #993333;">char</span> buff<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">15</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #993333;">float</span> real_temp<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #993333;">float</span> temp_count<span style="color: #339933;">;</span>
  <span style="color: #993333;">float</span> read_temp<span style="color: #339933;">;</span> 
&nbsp;
  ds.<span style="color: #202020;">reset_search</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>ds.<span style="color: #202020;">search</span><span style="color: #009900;">&#40;</span>addr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
&nbsp;
     digitalWrite<span style="color: #009900;">&#40;</span>ledPin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// sets the LED on</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> OneWire<span style="color: #339933;">::</span><span style="color: #202020;">crc8</span><span style="color: #009900;">&#40;</span> addr<span style="color: #339933;">,</span> <span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Check CRC is valid</span>
        Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;CRC is not valid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #208080;">0x10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>   <span style="color: #666666; font-style: italic;">// Make sure it is a DS18x20 device</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Device is not a DS18x20 family device.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    ds.<span style="color: #202020;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// Reset device</span>
    ds.<span style="color: #202020;">select</span><span style="color: #009900;">&#40;</span>addr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// Select device</span>
    ds.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span>CONVERT<span style="color: #339933;">,</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// Issue Convert command </span>
&nbsp;
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// maybe 750ms is enough, maybe not</span>
    digitalWrite<span style="color: #009900;">&#40;</span>ledPin<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// sets the LED off</span>
&nbsp;
    present <span style="color: #339933;">=</span> ds.<span style="color: #202020;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Reset device</span>
    ds.<span style="color: #202020;">select</span><span style="color: #009900;">&#40;</span>addr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Select device</span>
    ds.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span>READSCRATCH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Read Scratchpad</span>
&nbsp;
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #666666; font-style: italic;">// we need 9 bytes</span>
          data<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ds.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>OneWire<span style="color: #339933;">::</span><span style="color: #202020;">crc8</span><span style="color: #009900;">&#40;</span> data<span style="color: #339933;">,</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #666666; font-style: italic;">// Check CRC is valid</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// CRC is ok</span>
      <span style="color: #666666; font-style: italic;">// Divide the temperature by 2 - note the » and</span>
      <span style="color: #666666; font-style: italic;">// « need to be replaced with double &lt; and &gt;</span>
      <span style="color: #666666; font-style: italic;">// wordpress kills the server when you try to </span>
      <span style="color: #666666; font-style: italic;">// save otherwise.</span>
      read_temp<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>«<span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> » <span style="color: #0000dd;">1</span> <span style="color: #339933;">;</span>
     <span style="color: #666666; font-style: italic;">// Convert to real temperature</span>
      temp_count<span style="color: #339933;">=</span><span style="color: #993333;">float</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span>data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      real_temp <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span>read_temp<span style="color: #339933;">-</span><span style="color:#800080;">0.25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>temp_count<span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #666666; font-style: italic;">// Convert float to ascii</span>
      tempToAscii<span style="color: #009900;">&#40;</span>real_temp<span style="color: #339933;">,</span>buff<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #993333;">char</span> buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">512</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      sprintf<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;%02x%02x%02x%02x%02x%02x%02x%02x %s<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
                  addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                  addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> addr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> buff<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>    <span style="color: #009900;">&#123;</span>
       Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;CRC Failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>    
&nbsp;
<span style="color: #993333;">void</span> tempToAscii<span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span> temp<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buff<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> frac<span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//get three numbers to the right of the decimal point</span>
  frac<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>temp<span style="color: #339933;">*</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span><span style="color:#800080;">1000</span><span style="color: #339933;">;</span>
  itoa<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>temp<span style="color: #339933;">,</span>buff<span style="color: #339933;">,</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  strcat<span style="color: #009900;">&#40;</span>buff<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//put the frac after the decimal</span>
  itoa<span style="color: #009900;">&#40;</span>frac<span style="color: #339933;">,&amp;</span>amp<span style="color: #339933;">;</span>buff<span style="color: #009900;">&#91;</span>strlen<span style="color: #009900;">&#40;</span>buff<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>There&#8217;s also a copy of the .pde file that you can <a title="download file" href="http://blog.automated.it/files/ds18s20.pde" target="_blank">download</a> if you feel more inclined. It&#8217;s not an exact copy, I removed the commented out xml for the above version. It&#8217;s worth pointing out that this circuit is using what is called parasitic power, which means your cable run should be shortish. If you want to use an external power supply then pin 3 (VDD) on the DS18S20 should go to your external supply. This would allow for much longer runs of cable. Below is an example graph generated by <a title="Cacti" href="http://www.cacti.net/" target="_blank">cacti</a> with 2 DS1820&#8217;s connected the the arduino. As you can see the temperatures aren&#8217;t exactly the same but this is to be expected since the accuracy of the DS1820 is +/- 0.5 ° C</p>
<p style="text-align: center;"><img class="aligncenter" style="margin-left: 30px; margin-right: 30px;" title="Example Graph" src="/images/gallery/1wire/example_graph.png" alt="" width="367" height="304" /></p>
<p>The breaks in the graph were caused my me removing the USB plug from the PC it was connected to so that I could make some minor alterations to the circuit.</p>
<p><a href=http://blog.automated.it/2009/02/04/one-wireduino-made-easy/#comments>Josh</a> asked how I was getting the input for Cacti, here&#8217;s the perl script I use</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`echo -en &quot;T&quot; &gt;&gt;/dev/ttyUSB0 &amp;&amp; cat /dev/ttyUSB0`</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">@lines</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\r\n/</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$t</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$line</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@lines</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
       <span style="color: #0000ff;">@spl</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s+/</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$line</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #0000ff;">$lc</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@spl</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$lc</span> gt <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
                <span style="color: #0000ff;">$node</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$spl</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #0000ff;">$val</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$spl</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Temperature_$node:$val &quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #0000ff;">$t</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This outputs <em>Temperature_x:n</em> where x is the 1-Wire id and n is the temperature. It could probably do with tidying up and if you wanted to you could pass the 1-Wire id to the script to and only output the temperature for that particular 1-Wire device. A copy of the exported Cacti template can be <a href="/files/cacti_arduino.xml" target=_new>downloaded</a>, I&#8217;m hoping that you just need to import that into your Cacti after placing the script in the scripts directory. Just remember, under linux, if you unplug and replug in your Arduino you may need to set the tty port speed to 9600 (or whatever you put in your Serial.begin(); ). You can use the following command for that;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">stty</span> <span style="color: #660033;">-F</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0 cs8 <span style="color: #000000;">9600</span> ignbrk <span style="color: #660033;">-brkint</span> <span style="color: #660033;">-icrnl</span> <span style="color: #660033;">-imaxbel</span> <span style="color: #660033;">-opost</span> <span style="color: #660033;">-onlcr</span> <span style="color: #660033;">-isig</span> <span style="color: #660033;">-icanon</span> <span style="color: #660033;">-iexten</span> <span style="color: #660033;">-echo</span> <span style="color: #660033;">-echoe</span> <span style="color: #660033;">-echok</span> <span style="color: #660033;">-echoctl</span> <span style="color: #660033;">-echoke</span> noflsh <span style="color: #660033;">-ixon</span> <span style="color: #660033;">-crtscts</span></pre></td></tr></table></div>

<p>Make sure that ttyUSB0 is what your Arduino is connected to first. If not you will need to change it in the perl script and on the line above. </p>

<br><a href=http://blog.automated.it/2009/02/04/one-wireduino-made-easy/><p><img style='float:right;margin-left:15px;margin-bottom:10px;' src='http://blog.automated.it/images/tccb.png' border='0'></a></p><br>

<br><span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F&amp;title=One+Wireduino+made+easy" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F&amp;title=One+Wireduino+made+easy" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F&amp;title=One+Wireduino+made+easy" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F&amp;title=One+Wireduino+made+easy" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F&amp;title=One+Wireduino+made+easy', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://del.icio.us/favicon.ico" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F&amp;title=One+Wireduino+made+easy" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F&amp;title=One+Wireduino+made+easy" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
<a href="http://twitter.com/home?status=Currently reading http%3A%2F%2Fblog.automated.it%2F2009%2F02%2F04%2Fone-wireduino-made-easy%2F" title="Click to send this page to Twitter!" target="_blank"><img src="http://www.twitter.com/favicon.ico" width="16" height="16" alt="[Twitter]" /></a>
</span><br><br>]]></content:encoded>
			<wfw:commentRss>http://blog.automated.it/2009/02/04/one-wireduino-made-easy/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
