<?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>lithium flowers bloom &#187; xbee</title>
	<atom:link href="http://leejayxia.com/blog/tag/xbee/feed/" rel="self" type="application/rss+xml" />
	<link>http://leejayxia.com/blog</link>
	<description>the weblog</description>
	<lastBuildDate>Sat, 15 May 2010 20:52:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Communication Setup for Blinded</title>
		<link>http://leejayxia.com/blog/communication-setup-for-blinded/</link>
		<comments>http://leejayxia.com/blog/communication-setup-for-blinded/#comments</comments>
		<pubDate>Sat, 15 May 2010 20:52:00 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Sociable Objects Workshop]]></category>
		<category><![CDATA[Kinetic]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[xbee]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=857</guid>
		<description><![CDATA[Li and I worked on a group of robotic/kinetic creatures to create an ironic and self-balanced networked system called Blinded. A very detailed documentation of the construction iterations are up on Li&#8217;s website, so I&#8217;ll just write a bit about the communication between the creatures. For the first iteration we had only one creature fully [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://leejayxia.com/blog/wp-content/uploads/2010/05/4573919919_ab5486a201_o.jpg" rel="lightbox[857]"><img src="http://leejayxia.com/blog/wp-content/uploads/2010/05/4573919919_ab5486a201_o.jpg" alt="" title="4573919919_ab5486a201_o" width="720" height="465" class="alignnone size-full wp-image-858" /></a></p>
<p><a href="http://im-li.com">Li</a> and I worked on a group of robotic/kinetic creatures to create an ironic and self-balanced networked system called <em><a href="http://im-li.com/blinded/">Blinded</a></em>. </p>
<p>A very <a href="http://im-li.com/project-blinded/">detailed documentation</a> of the construction iterations are up on Li&#8217;s website, so I&#8217;ll just write a bit about the communication between the creatures.</p>
<p>For the first iteration we had only one creature fully assembled so I built a quick &#8220;single character communication protocol&#8221; that allows the creature to be remotely controlled from a computer. I have two pre-paired series one xbees which are perfect for this basic cable replacement purpose. </p>
<p>The arduino on the creature side is expecting specific &#8220;single character&#8221; functions from the serial channel via xbee, available instructions are:</p>
<p>1. L &#8211; turn left<br />
2. R &#8211; turn right<br />
3. F &#8211; step forward<br />
4. anything else &#8211; stop</p>
<p>At the same time, for monitoring purpose the arduino is reporting if the creature is on its target by comparing its left and right sensors and their historic readings, the reported status is written into the serial channel simply with notation of 1 (on-target) and 0 (target lost).</p>
<p>Because we had only one creature ready back then, the pursuing status is not entirely making sense, so the computer mainly served as a remote controller. The controller setup is pretty simple though, it can be just an xbee explorer board and any serial terminal program can be used to send commands to the remote creature. Following video shows one of our field tests in the park.</p>
<p><object type="application/x-shockwave-flash" width="500" height="375" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="intl_lang=en-us&#038;photo_secret=736789bd13&#038;photo_id=4573469454&#038;flickr_show_info_box=true"></param><param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&#038;photo_secret=736789bd13&#038;photo_id=4573469454&#038;flickr_show_info_box=true" height="375" width="500"></embed></object> </p>
<p>After more creatures were added to the group, the situation became much more complicated and I have to put up a processing sketch to coordinate input from multiple creatures. I did not use the xbee library for processing although it did look pretty promising in the examples and taking care a lot of the heavy liftings. But I dig into the source code a little bit and got a feeling that it might be a pain to use with series 2 xbees. So I just wrote some very simple parsing functions to take apart I/O packets and make sure I have access to any digital or analog pins without too much hack. </p>
<p>For physical setup, I switched all remote xbees to series 2 and put their firmware to router-at mode. The base station that stays with the computer is in coordinator-api mode. I used 4 pins of the remote xbees, 2 for digital output (remote commands), 2 for analog input (transferring sensor values to the remote computer/coordinator). Each remote xbee will still need to handle status reporting and command receiving, and the arduino on the creature remains as local intelligence that parses the sensor information and actually controls the motion.</p>
<p>Commands for Xbee configuration:</p>
<p>ATD04<br />
ATD14<br />
ATD22<br />
ATD32</p>
<p>During runtime, the computer is able to set the remote xbee digital pin state through processing sketch. Code snippet for setting</p>
<div class="codecolorer-container java dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">void</span> setRemotePin<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>address, <span style="color: #003399;">String</span> command, <span style="color: #000066; font-weight: bold;">int</span> value<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>address.<span style="color: #006633;">length</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;invalid address&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>command.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; println<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;invalid command&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>0x7E<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// start byte</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>0x0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// high part of length (always zero)</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>0x10<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// low part of length (the number of bytes that follow, not including checksum)</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>0x17<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 0x17 is a remote AT command</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>0x0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// frame id set to zero for no reply</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// ID of recipient, or use 0xFFFF for broadcast</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>address<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp;<span style="color: #666666; font-style: italic;">/* broadcast */</span><br />
&nbsp;<span style="color: #666666; font-style: italic;">/*<br />
&nbsp; serialSelector.port.write(00);<br />
&nbsp; serialSelector.port.write(00);<br />
&nbsp; serialSelector.port.write(00);<br />
&nbsp; serialSelector.port.write(00);<br />
&nbsp; serialSelector.port.write(00);<br />
&nbsp; serialSelector.port.write(00);<br />
&nbsp; serialSelector.port.write(0xFF); // 0xFF for broadcast<br />
&nbsp; serialSelector.port.write(0xFF); // 0xFF for broadcast<br />
&nbsp; */</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// 16 bit of recipient or 0xFFFE if unknown</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>0xFF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>0xFE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>0x02<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 0x02 to apply changes immediately on remote</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// command name in ASCII characters</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>command.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>command.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// command data in as many bytes as needed</span><br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// checksum is all bytes after length bytes</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">int</span> sum <span style="color: #339933;">=</span> 0x17 <span style="color: #339933;">+</span> 0xFF <span style="color: #339933;">+</span> 0xFE <span style="color: #339933;">+</span> 0x02 <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>command.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#40;</span>command.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> value<span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;sum <span style="color: #339933;">+=</span> address<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; serialSelector.<span style="color: #006633;">port</span>.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span> 0xFF <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span> sum <span style="color: #339933;">&amp;</span> 0xFF<span style="color: #009900;">&#41;</span> &nbsp;<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// calculate the proper checksum</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/communication-setup-for-blinded/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sensor Network: Data Logging and Visualization</title>
		<link>http://leejayxia.com/blog/sensor-network-data-logging-and-visualization/</link>
		<comments>http://leejayxia.com/blog/sensor-network-data-logging-and-visualization/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 07:50:18 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[ITP]]></category>
		<category><![CDATA[Sociable Objects Workshop]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[sensor network]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[xbee]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=823</guid>
		<description><![CDATA[I&#8217;m working with Sebastian and Michael as &#8220;visualization&#8221; team for the sensor network assignment for this week&#8217;s Sociable Objects Workshop. It&#8217;s very challenging for the whole class to work on one single project, but so far it went on pretty well. Tasks are split and assigned and we also find ways to work with dependencies [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working with Sebastian and Michael as &#8220;visualization&#8221; team for the sensor network assignment for this week&#8217;s Sociable Objects Workshop. It&#8217;s very challenging for the whole class to work on one single project, but so far it went on pretty well. Tasks are split and assigned and we also find ways to work with dependencies and such constraints.</p>
<p>Since we are just focusing on the visualization part, meaning that we take on only after all the data are aggregated at the coordinator xbee, our main effort will be data logging, mining and visualization. So the first thing we built is a <strong>pseudo data generator</strong> that feeds data in the same format as the data will be from the coordinator. We talked to the base station team and agreed that we will be getting raw API I/O RX packet and we will take care of the parsing and data storage. </p>
<p>I put together some simple arduino code to feed pseudo data, they could be easily replaced by a real coordinator and ideally we will not have to change the processing code on the other side which is listening to the serial channel.</p>
<div class="codecolorer-container c dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:1300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define ADDRESS_COUNT 9</span><br />
<span style="color: #993333;">int</span> addresses<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">9</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #208080;">0x0001</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0002</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0003</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0004</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0005</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0006</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0007</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0008</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #208080;">0x0009</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; 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><br />
&nbsp; randomSeed<span style="color: #009900;">&#40;</span>analogRead<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i <span style="color: #339933;">&lt;</span> ADDRESS_COUNT<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>random<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">990</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>random<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">500</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sendPseudoPackage<span style="color: #009900;">&#40;</span>addresses<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sendPseudoPackage<span style="color: #009900;">&#40;</span>addresses<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<br />
<span style="color: #993333;">void</span> sendPseudoPackage<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> address<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp;<span style="color: #666666; font-style: italic;">// pass either a 0x4 or and 0x5 to turn the pin on or off</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x7E</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// start byte</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x0</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// high part of length (always zero)</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x17</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// low part of length (the number of bytes that follow, not including checksum)</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x92</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 0x92 is I/O RX Packet</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//05-12: &nbsp;64-bit address</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x13</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xA2</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x40</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x33</span><span style="color: #339933;">,</span>BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #993333;">int</span> low <span style="color: #339933;">=</span> address <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #993333;">int</span> high <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>address <span style="color: #339933;">-</span> low<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>high<span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>low<span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//13-14: &nbsp;16 bit of recipient or 0xFFFE if unknown</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xFF</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xFE</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//15: &nbsp;Receive Option</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x01</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//16: &nbsp;Num Samples</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x01</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//17-18 Digital Channel Mask</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x01</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//only Digital I/O 0</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//19: &nbsp;Analog Channel Mask</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//20-21: &nbsp;Digital Samples</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0x00</span><span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>value<span style="color: #339933;">,</span> BYTE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">//no analog samples</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// checksum is all bytes after length bytes</span><br />
&nbsp; <span style="color: #993333;">long</span> sum <span style="color: #339933;">=</span> <span style="color: #208080;">0xFF</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//fake</span><br />
&nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #208080;">0xFF</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span> sum <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> BYTE <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// calculate the proper checksum</span><br />
&nbsp; delay<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;">// safety pause to avoid overwhelming the serial port (if this function is not implemented properly)</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Then I wrote a basic processing sketch which filters the data and stores only changes to the databases. The sketch itself servers as some sort of realtime visualization on the input, and we get a feeling of how often data are changing and potentially detects sensor failures if one sensor is not active for a very long time.</p>
<p><object width="500" height="281"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9819815&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9819815&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="281"></embed></object></p>
<p>The processing sketch is sending data to a website that handles data logging. The website also provides query api that returns sensor history in json format, and functions like filtering by certain address. The site itself is lightweight and fairly easy to add new functionality.</p>
<p>The plan is to meet tomorrow and start building a web interface upon the api for the final visualization. Hopefully we could also get to verify if the pseudo data is identical to the real format, and maybe we can get a test run with the real setup.</p>
<p><del datetime="2010-03-24T04:37:19+00:00">Stay tuned!</del></p>
<p><strong>UPDATE</strong>: A list of available API functions:</p>
<p>url: http://itp.nyu.edu/~lx243/sensornet/index.php/api/</p>
<blockquote><p>all (meaning that the url will look like http://itp.nyu.edu/~lx243/sensornet/index.php/api/all)
</p></blockquote>
<p>returning all records in json format</p>
<blockquote><p>find/:address</p></blockquote>
<p>returning all records from address specified<br />
address should be a string of 64bit address, e.g. 0013A20040330001</p>
<blockquote><p>find_today/:address</p></blockquote>
<blockquote><p>find_by_day/:address/:day
</p></blockquote>
<p>day should be in the format of yyyymmdd, e.g. 20100301</p>
<blockquote><p>status/:address
</p></blockquote>
<p>returning latest records from specified address</p>
<blockquote><p>status_at/:address/:time
</p></blockquote>
<p>returning latest records by the time specified<br />
time should be in the format of yyyymmddHHMMSS, e.g. 20100301140000</p>
<blockquote><p>changes/:address
</p></blockquote>
<p>returning all changes at specified address</p>
<blockquote><p>changes_today/:address
</p></blockquote>
<p>returning changes happened today at specified address</p>
<blockquote><p>changes_by_day/:address/:day
</p></blockquote>
<p>returning changes happened today on specified date at specified address<br />
day should be in the format of yyyymmdd, e.g. 20100301</p>
<blockquote><p>stats/:address
</p></blockquote>
<p>returning open time, close time, changes, and total active time of the sensor</p>
<blockquote><p>stats_today/:address
</p></blockquote>
<p>returning above stats from specified address</p>
<blockquote><p>stats_by_day/:address/:day
</p></blockquote>
<p>returning above stats from specified address on specified day</p>
<p><strong>UPDATE 2</strong>: Visualization</p>
<p>It took a while for Sebastian and I to make processing.js to talk to the API and get real time update. We used jQuery as a bridge to retrieve the data and feed it on the page to processing.js.  But eventually all is fine:</p>
<p><a href="http://leejayxia.com/blog/wp-content/uploads/2010/03/Mozilla-Firefox.png" rel="lightbox[823]"><img src="http://leejayxia.com/blog/wp-content/uploads/2010/03/Mozilla-Firefox.png" alt="" title="Where is my professor?" width="797" height="284" class="alignnone size-full wp-image-840" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/sensor-network-data-logging-and-visualization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using XBee Without Arduino</title>
		<link>http://leejayxia.com/blog/using-xbee-without-arduino/</link>
		<comments>http://leejayxia.com/blog/using-xbee-without-arduino/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 04:34:04 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Sociable Objects Workshop]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[xbee]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=821</guid>
		<description><![CDATA[I worked with Adi on the &#8220;Romantic Lighting Sensor&#8221; Lab for Sociable Objects Workshop. Since we do not have a photo cell at hand, we just used a normal potentiometer as the remote sensor. The code is from Rob Faludi&#8217;s course code sample page. We had some problem at first with the receiver side and [...]]]></description>
			<content:encoded><![CDATA[<p>I worked with Adi on the &#8220;Romantic Lighting Sensor&#8221; Lab for Sociable Objects Workshop.  Since we do not have a photo cell at hand, we just used a normal potentiometer as the remote sensor. The code is from Rob Faludi&#8217;s course <a href="http://www.faludi.com/classes/sociableobjectsworkshop/code/">code sample</a> page.</p>
<p>We had some problem at first with the receiver side and we didn&#8217;t find an effective to debug it. It was pretty clear that the transmitter is working fine since while I was using just xbee explorer board as receiver I can directly see the data coming from the serial channel. However I cannot get the code to work when I plugged the xbee back to arduino circuit.</p>
<p>I ended up using a processing sketch to print out serial data from arduino since I cannot see it directly by printing out data to the serial terminal in arduino code. So lesson learned:</p>
<p>1. the resister used to augment sensor output value to fit xbee&#8217;s 3.3v requirement has to be carefully handled, otherwise you do not get to use full range of the sensor output and it makes it harder to figure out the range to look for in the receiver code,</p>
<p>2. a processing sketch is necessary for debugging. it gives a lot of confidence while you can see what is in the data stream, at least for me.</p>
<p><object width="500" height="375"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9747935&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9747935&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="375"></embed></object><br />
simple remote xbee sensor</p>
<p><object width="500" height="375"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9748291&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9748291&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="375"></embed></object><br />
with feedback</p>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/using-xbee-without-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sociable Objects: a nap doorbell</title>
		<link>http://leejayxia.com/blog/sociable-object-a-nap-doorbell/</link>
		<comments>http://leejayxia.com/blog/sociable-object-a-nap-doorbell/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 22:07:33 +0000</pubDate>
		<dc:creator>L.J</dc:creator>
				<category><![CDATA[Sociable Objects Workshop]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[doorbell]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[nap]]></category>
		<category><![CDATA[Spring 2010]]></category>
		<category><![CDATA[xbee]]></category>

		<guid isPermaLink="false">http://leejayxia.com/blog/?p=792</guid>
		<description><![CDATA[Nap doorbells are designed for nappers. They will not actually ring and wake you up unless it is a real emergency. This project is developed in collaboration with Adi and Asli. Doorbell for insistent visitors from My Journey on Vimeo. Switch Code 1234567891011121314151617181920212223242526272829303132333435363738int BUTTON = 2; int GREEN = 12; int RED = 13; void [...]]]></description>
			<content:encoded><![CDATA[<p>Nap doorbells are designed for nappers. They will not actually ring and wake you up unless it is a real emergency. This project is developed in collaboration with Adi and Asli.</p>
<p><object width="500" height="375"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9514947&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9514947&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="375"></embed></object>
<p><a href="http://vimeo.com/9514947">Doorbell for insistent visitors</a> from <a href="http://vimeo.com/user3193576">My Journey</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Switch Code</p>
<div class="codecolorer-container c dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> BUTTON <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> GREEN <span style="color: #339933;">=</span> <span style="color: #0000dd;">12</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> RED <span style="color: #339933;">=</span> <span style="color: #0000dd;">13</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp;pinMode<span style="color: #009900;">&#40;</span>BUTTON<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;pinMode<span style="color: #009900;">&#40;</span>GREEN<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;pinMode<span style="color: #009900;">&#40;</span>RED<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;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><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>digitalRead<span style="color: #009900;">&#40;</span>BUTTON<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> HIGH<span style="color: #009900;">&#41;</span><br />
&nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'D'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp;<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;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><br />
&nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #993333;">char</span> r <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><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>r <span style="color: #339933;">==</span> <span style="color: #ff0000;">'G'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;digitalWrite<span style="color: #009900;">&#40;</span>GREEN<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>r <span style="color: #339933;">==</span> <span style="color: #ff0000;">'R'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;digitalWrite<span style="color: #009900;">&#40;</span>RED<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<span style="color: #b1b100;">else</span><br />
&nbsp;<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;digitalWrite<span style="color: #009900;">&#40;</span>GREEN<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;digitalWrite<span style="color: #009900;">&#40;</span>RED<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Buzzer Code</p>
<div class="codecolorer-container c dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> BELL <span style="color: #339933;">=</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">long</span> lastReleased <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">long</span> lastPressed <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> counter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> offcounter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<br />
boolean pressed <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; pinMode <span style="color: #009900;">&#40;</span>BELL<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; 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> &nbsp;<br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</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;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> &nbsp; <br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</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> <span style="color: #ff0000;">'D'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// look for a capital D over the serial port and ring the bell if found </span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Serial.println(&quot;ON&quot;);</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>pressed<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; lastPressed <span style="color: #339933;">=</span> millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pressed <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">long</span> interval <span style="color: #339933;">=</span> lastPressed <span style="color: #339933;">-</span> lastReleased<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Serial.print(&quot;+&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Serial.println(counter, DEC);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Serial.println(interval);</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>interval <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// if this one is pressed soon enough, increase the counter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//send feedback that message was recieved </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>counter <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'G'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//ring the bell briefly</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; digitalWrite<span style="color: #009900;">&#40;</span>BELL<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; digitalWrite<span style="color: #009900;">&#40;</span>BELL<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; offcounter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Serial.println(&quot;OFF&quot;);</span><br />
&nbsp; &nbsp; offcounter<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pressed <span style="color: #339933;">&amp;&amp;</span> offcounter <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">5000</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; pressed <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; lastReleased <span style="color: #339933;">=</span> millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; offcounter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://leejayxia.com/blog/sociable-object-a-nap-doorbell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

