<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/"
>

<channel>
	<title>KwartzLab Makerspace &#187; Arduino</title>
	<atom:link href="http://www.kwartzlab.ca/tag/arduino/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kwartzlab.ca</link>
	<description>Home of Kwartzlab Makerspace in Kitchener/Waterloo, Ontario</description>
	<lastBuildDate>Tue, 18 Jun 2013 19:32:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
<!-- podcast_generator="Blubrry PowerPress/4.0.7" -->
	<itunes:summary>Regular discussions with hackers, makers and artists at the Kwartzlab Makerspace. We talk about what projects people are working on, what events are coming up and how you can get involved.</itunes:summary>
	<itunes:author>kwartzlab</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.kwartzlab.ca/wp-content/uploads/powerpress/light_box_logo.jpg" />
	<itunes:owner>
		<itunes:name>kwartzlab</itunes:name>
		<itunes:email>podcast@kwartzlab.ca</itunes:email>
	</itunes:owner>
	<managingEditor>podcast@kwartzlab.ca (kwartzlab)</managingEditor>
	<itunes:subtitle>A hackerspace radio show</itunes:subtitle>
	<itunes:keywords>kwartzlab, hackerspace, makerspace, diy, hardware, software, maker, hacker, artist, roundtable</itunes:keywords>
	<image>
		<title>KwartzLab Makerspace &#187; Arduino</title>
		<url>http://www.kwartzlab.ca/wp-content/uploads/powerpress/light_box_logo.jpg</url>
		<link>http://www.kwartzlab.ca</link>
	</image>
	<itunes:category text="Technology" />
	<itunes:category text="Arts" />
	<itunes:category text="Games &amp; Hobbies">
		<itunes:category text="Hobbies" />
	</itunes:category>
		<rawvoice:location>Kitchener, ON</rawvoice:location>
		<item>
		<title>Kwartzlab TON Timelapse December 4th 2012.</title>
		<link>http://www.kwartzlab.ca/2012/12/kwartzlab-ton-timelapse-december-4th-2012/</link>
		<comments>http://www.kwartzlab.ca/2012/12/kwartzlab-ton-timelapse-december-4th-2012/#comments</comments>
		<pubDate>Wed, 05 Dec 2012 03:47:33 +0000</pubDate>
		<dc:creator>markp</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[TON in Pictures]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[arduino tutorial]]></category>
		<category><![CDATA[timelapse]]></category>
		<category><![CDATA[TON]]></category>
		<category><![CDATA[Tuesday Open Night]]></category>

		<guid isPermaLink="false">http://www.kwartzlab.ca/?p=3116</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='http://www.youtube.com/embed/6q-tjnxIzdk?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2012/12/kwartzlab-ton-timelapse-december-4th-2012/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Beamer Show</title>
		<link>http://www.kwartzlab.ca/2012/10/beamer-show/</link>
		<comments>http://www.kwartzlab.ca/2012/10/beamer-show/#comments</comments>
		<pubDate>Wed, 24 Oct 2012 15:47:20 +0000</pubDate>
		<dc:creator>markp</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[beamer]]></category>
		<category><![CDATA[chipKit]]></category>
		<category><![CDATA[laser]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[projector]]></category>

		<guid isPermaLink="false">http://www.kwartzlab.ca/?p=3007</guid>
		<description><![CDATA[For the Kwartzlab third anniversary party I put on a &#8220;laser show&#8221; featuring some of the things I&#8217;ve been working on over the past few months. The &#8220;laser&#8221; is an LCD Projector (thanks Don!) pointed at the audience. I wrote a program in Processing using the Minim library for beat detection. By applying filters to [...]]]></description>
				<content:encoded><![CDATA[<p>For the Kwartzlab third anniversary party I put on a &#8220;laser show&#8221; featuring some of the things I&#8217;ve been working on over the past few months.</p>
<p><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='http://www.youtube.com/embed/sfP8gCLmqnk?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span></p>
<p><img class="alignleft  wp-image-3012" title="560818_10152185544515582_297890721_n" src="http://www.kwartzlab.ca/wp-content/uploads/2012/10/560818_10152185544515582_297890721_n-300x400.jpg" alt="" width="234" height="312" /></p>
<p>The &#8220;laser&#8221; is an LCD Projector (thanks Don!) pointed at the audience. I wrote a program in Processing using the Minim library for beat detection. By applying filters to the input audio, you can extract the beat in real time and use that to control a number of variables, such as timers, colours, sizes, rotations, etc. This however proved unsatisfactory. The &#8220;show&#8221; it produced looked random and uninspired. I then recorded the output to video, made loops out of the animations, and then used a video editor to try to figure out what looks good and why. I ended up treating the video loops like breakbeat drum loops, chopping and slicing them up, laying them over each other, and keeping everything tight by quantizing to the audio channel. I also used some video effects to create transitions. This was eventually presented as the &#8220;laser show&#8221;, and now I&#8217;ll go back to Processing and see if this type of manipulation can be automated.<br />
In order for this to work, the room has to be filled with smoke. A projector is much to bright to look at, even if projecting nothing but black. The smoke takes the glare off the projector, and gives the beams some volume. Smoke is generated by a small &#8220;Halloween&#8221; smoke machine (thanks Agnes!)</p>
<p><img class="alignleft size-medium wp-image-3028" title="IMG_2199 (Large)" src="http://www.kwartzlab.ca/wp-content/uploads/2012/10/IMG_2199-Large-400x300.jpg" alt="" width="400" height="300" /><br />
I also built a chipKit powered &#8220;dowser&#8221; to flip a flag over the lens with a servo whenever nothing was being shown, but this was unnecessary in practice. Eventually this as to tie into the VGA cable, and whenever the RGB lines went low the flag would flip down covering the lens. There&#8217;s provisions for two dowser flags, and one VGA control line, so that two projectors can be used for the show, but only one will project at at a time.</p>
<p>There was going to be another projector used for this show, in sync with the main projector using VLC&#8217;s network-sync feature. However Kwartzlab&#8217;s wifi was saturated and I wasn&#8217;t able to get a stable connection. Next time I will use a wired network. In hindsight I think this would have detracted from the show, so no loss by not having it.</p>
<p><a href="http://www.kwartzlab.ca/2012/10/beamer-show/247372_10152185538820582_1687098203_n/" rel="attachment wp-att-3009"><img class="alignleft size-medium wp-image-3009" title="247372_10152185538820582_1687098203_n" src="http://www.kwartzlab.ca/wp-content/uploads/2012/10/247372_10152185538820582_1687098203_n-300x400.jpg" alt="" width="300" height="400" /></a><a href="http://www.kwartzlab.ca/2012/10/beamer-show/photo-3/" rel="attachment wp-att-3036"><img class="alignleft size-medium wp-image-3036" title="photo (3)" src="http://www.kwartzlab.ca/wp-content/uploads/2012/10/photo-3-e1351091293872-300x400.jpg" alt="" width="300" height="400" /></a><a href="http://www.kwartzlab.ca/2012/10/beamer-show/431731_10152185537880582_1748659929_n/" rel="attachment wp-att-3011"><img class="alignleft size-medium wp-image-3011" title="431731_10152185537880582_1748659929_n" src="http://www.kwartzlab.ca/wp-content/uploads/2012/10/431731_10152185537880582_1748659929_n-300x400.jpg" alt="" width="300" height="400" /></a><a href="http://www.kwartzlab.ca/2012/10/beamer-show/297241_10152185538260582_1642767488_n/" rel="attachment wp-att-3010"><img class="alignleft size-medium wp-image-3010" title="297241_10152185538260582_1642767488_n" src="http://www.kwartzlab.ca/wp-content/uploads/2012/10/297241_10152185538260582_1642767488_n-300x400.jpg" alt="" width="300" height="400" /></a><a href="http://www.kwartzlab.ca/2012/10/beamer-show/644682_10152185540860582_631534363_n/" rel="attachment wp-att-3013"><img class="alignleft size-medium wp-image-3013" title="644682_10152185540860582_631534363_n" src="http://www.kwartzlab.ca/wp-content/uploads/2012/10/644682_10152185540860582_631534363_n-300x400.jpg" alt="" width="300" height="400" /></a> <a href="http://www.kwartzlab.ca/2012/10/beamer-show/photo-4/" rel="attachment wp-att-3037"><img class="alignleft size-medium wp-image-3037" title="photo (4)" src="http://www.kwartzlab.ca/wp-content/uploads/2012/10/photo-4-e1351091317769-300x400.jpg" alt="" width="300" height="400" /></a> Thanks Karl for the pictures!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2012/10/beamer-show/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arduino-Compatible Multi-Threading Library v0.5 Released</title>
		<link>http://www.kwartzlab.ca/2011/06/arduino-compatible-multi-threading-library-v0-5-released/</link>
		<comments>http://www.kwartzlab.ca/2011/06/arduino-compatible-multi-threading-library-v0-5-released/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 20:20:28 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[microcontroller]]></category>
		<category><![CDATA[multi-threading]]></category>

		<guid isPermaLink="false">http://www.kwartzlab.ca/?p=1441</guid>
		<description><![CDATA[It&#8217;s been a while since I&#8217;ve touched this project, but I&#8217;ve decided to re-visit the multi-threading library I wrote for the Arduino (largely because of the amount of consistent traffic those particular blog posts have generated&#8230; it&#8217;s satisfying to know that someone other than me seems to appreciate my work). Although, I&#8217;ve made some minor [...]]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s been a while since I&#8217;ve touched this project, but I&#8217;ve decided to re-visit the multi-threading library I wrote for the <a href="http://arduino.cc">Arduino</a> (largely because of the amount of consistent traffic those particular blog posts have generated&#8230; it&#8217;s satisfying to know that someone other than me seems to appreciate my work).  Although, I&#8217;ve made some minor edits to the internals of the <a href="http://www.jlamothe.net/projects/mthread/v0.5/classThread.html"><code>Thread</code></a> class, the most important update has been the addition of the <a href="http://www.jlamothe.net/projects/mthread/v0.5/classEventHandler.html"><code>EventHandler</code></a> class.  As it&#8217;s name would suggest, it provides the framework for basic event-handling.</p>
<p><span id="more-1441"></span></p>
<p>Those who&#8217;ve been following the evolution of this library, will probably be familiar with the <a href="http://www.jlamothe.net/projects/mthread/v0.5/classSwitchInput.html"><code>SwitchInput</code></a> class.  It was intended (among other things) to provide functions that would only be called when a physical switch was closed or opened.  The <code>EventHandler</code> class is similar, except that the conditions upon which the event is triggered are configurable and the function isn&#8217;t limited to running a single loop when the event occurs.  I actually considered re-writing the <code>SwitchInput</code> class to be more like this, but given that it might break programs that people had written with it, I opted not to.  Perhaps I&#8217;ll create a replacement in the future.  Like <code>SwitchInput</code>, <code>EventHandler</code> is drived from the <code>Thread</code> class, with the <code>loop()</code> function overwritten.  In its place are two protected virtual functions: <a href="http://www.jlamothe.net/projects/mthread/v0.5/classEventHandler.html#a413d8613b761d5709a28cf488850d41f"><code>condition()</code></a> and <a href="http://www.jlamothe.net/projects/mthread/v0.5/classEventHandler.html#a1f1b4ac0929b4dc6db3bdc76300dc19f"><code>on_event()</code></a>.</p>
<h1>The <code>condition()</code> Function:</h1>
<p>This is the function that is used to determine when the event is to be triggered.  Basically, while the <code>EventHandler</code> object is idle, this function will be called every time the object is invoked by a <a href="http://www.jlamothe.net/projects/mthread/v0.5/classThreadList.html"><code>ThreadList</code></a> object.  If it returns <code>true</code>, the event will be triggered, but if it returns <code>false</code>, the handler will remain in an idle state (this is one of those cases where I wish C++ supported lambdas (but that may be the LISP programming I&#8217;ve been doing talking (it&#8217;s hard to tell, really))).</p>
<h1>The <code>on_event()</code> Function:</h1>
<p>Once the event has been triggered, instead of calling the <code>condition()</code> function, the <code>on_event()</code> function will be called in its place.  This can be thought of as a conditional <code>loop()</code> function.  The difference being that when it returns <code>false</code> the handler will return to an idle state and wait for the <code>condition()</code> function to return <code>true</code> again rather than destroying itself.</p>
<h1>A Note about <code>kill_flag</code>:</h1>
<p>With a regular <code>Thread</code> object, the <code>loop()</code> function is expected to watch the <a href="http://www.jlamothe.net/projects/mthread/v0.5/classThread.html#a82e88eebd44957e65bb075103fb6ca1b"><code>kill_flag</code></a> value.  When it is set to <code>true</code>, the <code>loop()</code> function is is expected to terminate gracefully.  As a help, this functionality is already built into the <code>EventHandler::loop()</code> function.  If the handler is in an idle state, it will automatically terminate itself on its next call, however it may be advisable to have the <code>on_event()</code> function watch for this value so that it can facilitate a graceful termination (although, this is not strictly required as the handler will be terminated when the function returns false).</p>
<p>While I don&#8217;t feel I&#8217;ve done anything particularly ground-breaking with this new release, I hope I&#8217;ve created an adequate framework for other Arduino developers who don&#8217;t want to re-invent the wheel.  As usual, I&#8217;ve made all the <a href="https://github.com/jlamothe/mthread/tree/v0.5">code</a> and <a href="http://www.jlamothe.net/projects/mthread/v0.5/">documentation</a> available for this version.</p>
<p>Happy Hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2011/06/arduino-compatible-multi-threading-library-v0-5-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New and Improved Arduino Multi-Threading Library</title>
		<link>http://www.kwartzlab.ca/2010/10/new-and-improved-arduino-multi/</link>
		<comments>http://www.kwartzlab.ca/2010/10/new-and-improved-arduino-multi/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 15:40:48 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[interrupt]]></category>
		<category><![CDATA[multi-threading]]></category>
		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>So... I've been doing a little more work on the multi-threading library <a href="http://kwartzlab.ca/blog/jlamothe/2010-09-06/arduino-multi-threading-librar">I blogged about earlier</a>, and I decided that it would be a good idea to add some interrupt-like functionality to handle switches.  Thus, the <code>SwitchInput</code> class was born.  This class has several nice features that make working with switches easier.</p>

<!--more-->

<h2>Wiring Switches to the Arduino</h2>

<p>The simplest and easiest way to connect a switch is to just wire a dry contact switch directly from the input pin to the ground pin taking advantage of the Arduino's internal 20k pull up resistor.  That way, when the switch is open, the input will read <code>HIGH</code>, and when it's closed, the input will read <code>LOW</code> (although, this is a little counter-intuitive for most people).</p>

<p><strong>NOTE:</strong> Pull-up resistors usually don't work well for pin 13 because of the built-in LED (see below).</p>

<p>The next way is to supply your own pull-up resistor by wiring the switch the same way, but also running a resistor between the 5V power output pin and the input pin.  I'm not sure why anyone would choose this option over the former, but you <strong>could</strong> if you really wanted to.  The logic for reading this switch would be the same as in the previous case.</p>

<p>The last way is to supply a pull-down resistor.  In this case, you hook your dry contact from input to the 5V supply, and your resistor from the input to the ground pin.  In this case, the logic makes more sense, where a <code>LOW</code> input level is an open switch and a <code>HIGH</code> input level is a closed switch.  This option works well with pin 13.</p>

<h2>What <code>SwitchInput</code> Provides</h2>

<p>Primarily, <code>SwitchInput</code> is intended to provide a layer of abstraction for a switch.  Instead of thinking of a switch input in terms of <code>HIGH</code> and <code>LOW</code> logic levels, it allows you to think of the switch in terms of open and closed states, which is a little easier on the brain.  The <code>SwitchInput</code> class has <code>is_open()</code> and <code>is_closed()</code> member functions that will return <code>true</code> when the switch is open or closed respectively (and <code>false</code> otherwise... obviously).</p>

<p>That's hardly the best feature of the <code>SwitchInput</code> class however.  Another handy feature of this class are the <code>on_open()</code> and <code>on_close()</code> functions.  These are virtual member functions that are automatically called when the state of the switch changes, and can be overridden to perform tasks in an interrupt-like manner when these events occur.</p>

<p>As their names would imply, the <code>on_open()</code> function is called when the state of the switch transitions from closed to open, and the <code>on_close()</code> function is called when the switch changes from from open to closed.</p>

<p>That brings us to our third feature: automatic debounce filtering.  This helps to clean up "dirty" input signals.  With most switches, when you close or open them, they don't transition cleanly from one state to another; the voltage tends to "jitter" back and forth.  Without some kind of filtering, this would cause <code>on_open()</code> and <code>on_close()</code> to be called repeatedly for no reason, which needless to say, would be undesirable.</p>

<p>This feature operates transparently.  When the voltage level of the input changes, the object will wait for a pre-determined number of milliseconds (50 by default) before doing anything.  If at the end of this time period, the level is different from what it was at the beginning, the appropriate function (<code>on_open()</code> or <code>on_close()</code>) will be called.  Otherwise, the input change will be treated as a spike and be ignored.</p>

<h2>A Note about <code>SwitchInput</code></h2>

<p>This class is derived from the <code>Thread</code> class since it needs to do logic in the background for the debouncing and edge-detection.  As such, it must be added to a <code>ThreadList</code> object (such as <code>main_thread_list</code>) just as any other <code>Thread</code> object would.  Don't expect your switch to work if you forget to do this.  ;)</p>

<h2>Source and Documentation</h2>

<p>As always, the most recent version of the <a href="http://github.com/jlamothe/mthread">source</a> is available under the <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public Licence</a> on GitHub, and the <a href="http://www.jlamothe.net/projects/mthread/current">documentation</a> is available on my web site.</p>

<p>Happy Hacking.</p>

<p><strong>EDIT 2010-11-11:</strong><br />
As of version 0.4, the <code>SwitchInput</code> class now has <code>time_open()</code> and <code>time_closed()</code> member functions which will return the time for which the switch has been open or closed (in milliseconds).</p>
]]></description>
				<content:encoded><![CDATA[<p>So&#8230; I&#8217;ve been doing a little more work on the multi-threading library <a href="http://kwartzlab.ca/blog/jlamothe/2010-09-06/arduino-multi-threading-librar">I blogged about earlier</a>, and I decided that it would be a good idea to add some interrupt-like functionality to handle switches.  Thus, the <code>SwitchInput</code> class was born.  This class has several nice features that make working with switches easier.</p>
<p><span id="more-434"></span></p>
<h2>Wiring Switches to the Arduino</h2>
<p>The simplest and easiest way to connect a switch is to just wire a dry contact switch directly from the input pin to the ground pin taking advantage of the Arduino&#8217;s internal 20k pull up resistor.  That way, when the switch is open, the input will read <code>HIGH</code>, and when it&#8217;s closed, the input will read <code>LOW</code> (although, this is a little counter-intuitive for most people).</p>
<p><strong>NOTE:</strong> Pull-up resistors usually don&#8217;t work well for pin 13 because of the built-in LED (see below).</p>
<p>The next way is to supply your own pull-up resistor by wiring the switch the same way, but also running a resistor between the 5V power output pin and the input pin.  I&#8217;m not sure why anyone would choose this option over the former, but you <strong>could</strong> if you really wanted to.  The logic for reading this switch would be the same as in the previous case.</p>
<p>The last way is to supply a pull-down resistor.  In this case, you hook your dry contact from input to the 5V supply, and your resistor from the input to the ground pin.  In this case, the logic makes more sense, where a <code>LOW</code> input level is an open switch and a <code>HIGH</code> input level is a closed switch.  This option works well with pin 13.</p>
<h2>What <code>SwitchInput</code> Provides</h2>
<p>Primarily, <code>SwitchInput</code> is intended to provide a layer of abstraction for a switch.  Instead of thinking of a switch input in terms of <code>HIGH</code> and <code>LOW</code> logic levels, it allows you to think of the switch in terms of open and closed states, which is a little easier on the brain.  The <code>SwitchInput</code> class has <code>is_open()</code> and <code>is_closed()</code> member functions that will return <code>true</code> when the switch is open or closed respectively (and <code>false</code> otherwise&#8230; obviously).</p>
<p>That&#8217;s hardly the best feature of the <code>SwitchInput</code> class however.  Another handy feature of this class are the <code>on_open()</code> and <code>on_close()</code> functions.  These are virtual member functions that are automatically called when the state of the switch changes, and can be overridden to perform tasks in an interrupt-like manner when these events occur.</p>
<p>As their names would imply, the <code>on_open()</code> function is called when the state of the switch transitions from closed to open, and the <code>on_close()</code> function is called when the switch changes from from open to closed.</p>
<p>That brings us to our third feature: automatic debounce filtering.  This helps to clean up &#8220;dirty&#8221; input signals.  With most switches, when you close or open them, they don&#8217;t transition cleanly from one state to another; the voltage tends to &#8220;jitter&#8221; back and forth.  Without some kind of filtering, this would cause <code>on_open()</code> and <code>on_close()</code> to be called repeatedly for no reason, which needless to say, would be undesirable.</p>
<p>This feature operates transparently.  When the voltage level of the input changes, the object will wait for a pre-determined number of milliseconds (50 by default) before doing anything.  If at the end of this time period, the level is different from what it was at the beginning, the appropriate function (<code>on_open()</code> or <code>on_close()</code>) will be called.  Otherwise, the input change will be treated as a spike and be ignored.</p>
<h2>A Note about <code>SwitchInput</code></h2>
<p>This class is derived from the <code>Thread</code> class since it needs to do logic in the background for the debouncing and edge-detection.  As such, it must be added to a <code>ThreadList</code> object (such as <code>main_thread_list</code>) just as any other <code>Thread</code> object would.  Don&#8217;t expect your switch to work if you forget to do this.  <img src='http://www.kwartzlab.ca/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h2>Source and Documentation</h2>
<p>As always, the most recent version of the <a href="http://github.com/jlamothe/mthread">source</a> is available under the <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public Licence</a> on GitHub, and the <a href="http://www.jlamothe.net/projects/mthread/current">documentation</a> is available on my web site.</p>
<p>Happy Hacking.</p>
<p><strong>EDIT 2010-11-11:</strong><br />
As of version 0.4, the <code>SwitchInput</code> class now has <code>time_open()</code> and <code>time_closed()</code> member functions which will return the time for which the switch has been open or closed (in milliseconds).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2010/10/new-and-improved-arduino-multi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino Multi-Threading Library</title>
		<link>http://www.kwartzlab.ca/2010/09/arduino-multi-threading-librar/</link>
		<comments>http://www.kwartzlab.ca/2010/09/arduino-multi-threading-librar/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 17:49:29 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[multi-threading]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>One of the things that I've always wished I could do with my Arduino is writing programs that can do multiple tasks independently of each other.  Unfortunately, the Arduino doesn't support multi-threading.  Instead, I've written a library to provide crude multi-threading support.
<!--more-->
This is actually based on an idea I had back in around '97, but I've made some modifications to adapt it for the Arduino.  For instance, I've trimmed the code down so that it can run in the smallest memory footprint possible since Arduinos don't have a whole lot of memory to spare.</p>

<h2>Anatomy of a Typical Arduino Program</h2>

<p>In order to understand what this library does, it is important to first understand what a typical Arduino program looks like.</p>

<p>A typical Arduino program has two main functions.  First there is a setup() function that is called once when the system is powered on.  This is typically used for initializing variables, setting pins as input or output, starting up serial communication, etc.  Once the setup() function completes, there is then a loop() function that just gets called again and again and again and again... until the system loses power or breaks down.</p>

<h2>So What Does this Library Do Differently?</h2>

<p>First of all, a program that uses this library has no main loop() function (well, it does, but it's part of the library; it doesn't have to be separately written).</p>

<p>Instead, the library provides a Thread class.  This class can be derived from to provide the basic functionality for a single thread.  Each Thread has its own loop() function which works in basically the same way as the loop() function we all know and love.  The only major difference is that the loop() function in a Thread returns a boolean value (true if the loop needs to be called again or false if it doesn't).  When the Thread completes, it will automatically destroy itself freeing the memory it occupied to be used for other things.</p>

<h2>ThreadList Objects</h2>

<p>Once a Thread object is created, it then has to be added to a ThreadList object (through the add_thread() function).  One of these is already created by the library.  It's called main_thread_list and it's run in place of the main loop() function.</p>

<p>What a ThreadList does is call the loop() function from the first Thread in the list, then it calls the loop() function from the next one, and so on and so forth.  Once they've all been called, it returns to the first Thread and starts over again.  Whenever a Thread has completed its run, it is automatically removed from the ThreadList.</p>

<h2>Tiered ThreadLists</h2>

<p>An interesting thing about ThreadLists is that they are Threads in and of themselves.  That way a tiered system can be crated where a lower-priority ThreadList object can be placed inside of a higher one.  That way, the higher-priority ThreadList will call one loop() from each of the high-priority Threads, and then a loop() from the first Thread in the lower-priority list.  It will then call the loop() function in all of the high-priority Threads again, and then the next one from the low-priority list... and so on.</p>

<h2>The kill() Function</h2>

<p>Rather than waiting for it to run its course, a Thread can be killed by calling its kill() function.  There are two levels of "kill" that this function offers.  The first (recommended) way is much more polite.  It simply sets an internal variable called kill_flag to true telling the Thread that it should start finishing up.  Its loop() function is expected to check for this and behave accordingly.</p>

<p>The second way of killing a Thread is to call kill(true).  This will essentially kill the Thread outright without any warning.  <strong>Do not use the delete keyword on a Thread!</strong>  This <strong>will</strong> cause memory corruption.</p>

<h2>Limitations</h2>

<p>One of the major potential problems with this library is the fact that a single Thread that gets hung will lock the entire system up, since the next Thread can't be called until the current one finishes its loop() function.</p>

<p>For this reason, it is unwise to use blocking functions such as delay(), because they will cause a delay in all the other threads as well.  To help get around this, the Thread class has three functions that will not allow the loop() function for that Thread to be called again until a specified amount of time has passed.  These functions are sleep(), sleep_milli() and sleep_micro(); which suspend the Thread for a set number of seconds, milliseconds and microseconds respectively.</p>

<p>The Thread class also provides pause() and resume() functions.  As the names imply, the pause() function will suspend the Thread until the its resume() function is called.  Obviously, the resume() function would have to be called by another (non-suspended) Thread, so care should be taken with these functions.</p>

<h2>Where Can I Get It?</h2>

<p>The library is available for download under the terms of version 3 the <a href="http://www.gnu.org/licenses/gpl.html" title="GPL">GNU General Public License</a> on github <a href="http://github.com/jlamothe/mthread" title="mthread">here</a>.  The full documentation for the library can be read <a href="http://www.jlamothe.net/projects/mthread/current" title="mthread Documentation">here</a>.</p>

<p>Hopefully, this will be useful to someone other than me.</p>

<p>Happy Hacking.</p>

<p><strong>EDIT:</strong>
I almost forgot to mention that this library also requires another simple library called newdel to enable the new and delete keywords.  It's available (public domain) <a href="http://github.com/jlamothe/newdel" title="newdel">here</a>.</p>

<p><strong>EDIT 2010-10-09:</strong>
Moved the project to github and updated the links.</p>
]]></description>
				<content:encoded><![CDATA[<p>One of the things that I&#8217;ve always wished I could do with my Arduino is writing programs that can do multiple tasks independently of each other.  Unfortunately, the Arduino doesn&#8217;t support multi-threading.  Instead, I&#8217;ve written a library to provide crude multi-threading support.<br />
<span id="more-414"></span><br />
This is actually based on an idea I had back in around &#8217;97, but I&#8217;ve made some modifications to adapt it for the Arduino.  For instance, I&#8217;ve trimmed the code down so that it can run in the smallest memory footprint possible since Arduinos don&#8217;t have a whole lot of memory to spare.</p>
<h2>Anatomy of a Typical Arduino Program</h2>
<p>In order to understand what this library does, it is important to first understand what a typical Arduino program looks like.</p>
<p>A typical Arduino program has two main functions.  First there is a setup() function that is called once when the system is powered on.  This is typically used for initializing variables, setting pins as input or output, starting up serial communication, etc.  Once the setup() function completes, there is then a loop() function that just gets called again and again and again and again&#8230; until the system loses power or breaks down.</p>
<h2>So What Does this Library Do Differently?</h2>
<p>First of all, a program that uses this library has no main loop() function (well, it does, but it&#8217;s part of the library; it doesn&#8217;t have to be separately written).</p>
<p>Instead, the library provides a Thread class.  This class can be derived from to provide the basic functionality for a single thread.  Each Thread has its own loop() function which works in basically the same way as the loop() function we all know and love.  The only major difference is that the loop() function in a Thread returns a boolean value (true if the loop needs to be called again or false if it doesn&#8217;t).  When the Thread completes, it will automatically destroy itself freeing the memory it occupied to be used for other things.</p>
<h2>ThreadList Objects</h2>
<p>Once a Thread object is created, it then has to be added to a ThreadList object (through the add_thread() function).  One of these is already created by the library.  It&#8217;s called main_thread_list and it&#8217;s run in place of the main loop() function.</p>
<p>What a ThreadList does is call the loop() function from the first Thread in the list, then it calls the loop() function from the next one, and so on and so forth.  Once they&#8217;ve all been called, it returns to the first Thread and starts over again.  Whenever a Thread has completed its run, it is automatically removed from the ThreadList.</p>
<h2>Tiered ThreadLists</h2>
<p>An interesting thing about ThreadLists is that they are Threads in and of themselves.  That way a tiered system can be crated where a lower-priority ThreadList object can be placed inside of a higher one.  That way, the higher-priority ThreadList will call one loop() from each of the high-priority Threads, and then a loop() from the first Thread in the lower-priority list.  It will then call the loop() function in all of the high-priority Threads again, and then the next one from the low-priority list&#8230; and so on.</p>
<h2>The kill() Function</h2>
<p>Rather than waiting for it to run its course, a Thread can be killed by calling its kill() function.  There are two levels of &#8220;kill&#8221; that this function offers.  The first (recommended) way is much more polite.  It simply sets an internal variable called kill_flag to true telling the Thread that it should start finishing up.  Its loop() function is expected to check for this and behave accordingly.</p>
<p>The second way of killing a Thread is to call kill(true).  This will essentially kill the Thread outright without any warning.  <strong>Do not use the delete keyword on a Thread!</strong>  This <strong>will</strong> cause memory corruption.</p>
<h2>Limitations</h2>
<p>One of the major potential problems with this library is the fact that a single Thread that gets hung will lock the entire system up, since the next Thread can&#8217;t be called until the current one finishes its loop() function.</p>
<p>For this reason, it is unwise to use blocking functions such as delay(), because they will cause a delay in all the other threads as well.  To help get around this, the Thread class has three functions that will not allow the loop() function for that Thread to be called again until a specified amount of time has passed.  These functions are sleep(), sleep_milli() and sleep_micro(); which suspend the Thread for a set number of seconds, milliseconds and microseconds respectively.</p>
<p>The Thread class also provides pause() and resume() functions.  As the names imply, the pause() function will suspend the Thread until the its resume() function is called.  Obviously, the resume() function would have to be called by another (non-suspended) Thread, so care should be taken with these functions.</p>
<h2>Where Can I Get It?</h2>
<p>The library is available for download under the terms of version 3 the <a href="http://www.gnu.org/licenses/gpl.html" title="GPL">GNU General Public License</a> on github <a href="http://github.com/jlamothe/mthread" title="mthread">here</a>.  The full documentation for the library can be read <a href="http://www.jlamothe.net/projects/mthread/current" title="mthread Documentation">here</a>.</p>
<p>Hopefully, this will be useful to someone other than me.</p>
<p>Happy Hacking.</p>
<p><strong>EDIT:</strong><br />
I almost forgot to mention that this library also requires another simple library called newdel to enable the new and delete keywords.  It&#8217;s available (public domain) <a href="http://github.com/jlamothe/newdel" title="newdel">here</a>.</p>
<p><strong>EDIT 2010-10-09:</strong><br />
Moved the project to github and updated the links.</p>
<p><strong>EDIT 2012-07-01:</strong><br />
This library is now available under the <a href="http://www.gnu.org/licenses/lgpl.html">Lesser General Public License</a> (verion 3 or later).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2010/09/arduino-multi-threading-librar/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Getting Started with Arduino Workshop</title>
		<link>http://www.kwartzlab.ca/2010/02/getting-started-arduino-worksh/</link>
		<comments>http://www.kwartzlab.ca/2010/02/getting-started-arduino-worksh/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 17:49:23 +0000</pubDate>
		<dc:creator>bevlan</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Arduino]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>Kwartzlab is hosting a getting started with Arduino workshop.</p>

<p><img src="https://kwartzlab.ca/sites/default/files/IMG00006-20100214-1813.jpg" alt="Fits in your hand" /></p>

<p>The Arduino is a micro controller that can read inputs such as push buttons, switches, sensors and control output devices such as motors, lights, buzzers and much more.</p>

<p>Some things you can do with the Arduino are:
infrared limit switches
hijack a remote control
analog needle gauge
reflective infrared detector
buzz a buzzer
twirly knobs, we call pots
drive an LCD
If you are wondering “can I do this with an Arduino?”, why don’t you ask us?</p>

<p>We will have computers with Arduinos already set up to demonstrate some of their many uses. If attendees wish to bring there laptops in we will help them get the software running.
There will be a $20 fee to cover cost of materials. We are getting some new boards in for the event for people to try out.</p>

<p>When: Saturday February 27, 1-4 PM</p>

<p>Where: Kwartzlab 283 Duke St. W, Unit 106, Kitchener, ON</p>

<p>Cost: $20</p>

<p>RSVP to events@kwartzlab.ca</p>

<p>Hosts: Andrew Mackie and Bevan Lantz</p>

<p><!-- Images -->
<!--more--></p>
]]></description>
				<content:encoded><![CDATA[<p>Kwartzlab is hosting a getting started with Arduino workshop.</p>
<p><img src="https://kwartzlab.ca/wp-content/uploads/IMG00006-20100214-1813.jpg" alt="Fits in your hand" /></p>
<p>The Arduino is a micro controller that can read inputs such as push buttons, switches, sensors and control output devices such as motors, lights, buzzers and much more.</p>
<p>Some things you can do with the Arduino are:<br />
infrared limit switches<br />
hijack a remote control<br />
analog needle gauge<br />
reflective infrared detector<br />
buzz a buzzer<br />
twirly knobs, we call pots<br />
drive an LCD<br />
If you are wondering “can I do this with an Arduino?”, why don’t you ask us?</p>
<p>We will have computers with Arduinos already set up to demonstrate some of their many uses. If attendees wish to bring there laptops in we will help them get the software running.<br />
There will be a $20 fee to cover cost of materials. We are getting some new boards in for the event for people to try out.</p>
<p>When: Saturday February 27, 1-4 PM</p>
<p>Where: Kwartzlab 283 Duke St. W, Unit 106, Kitchener, ON</p>
<p>Cost: $20</p>
<p>RSVP to events@kwartzlab.ca</p>
<p>Hosts: Andrew Mackie and Bevan Lantz</p>
<p><!-- Images --><br />
<span id="more-281"></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2010/02/getting-started-arduino-worksh/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Remote debugging an Arduino</title>
		<link>http://www.kwartzlab.ca/2009/12/remote-debugging-arduino/</link>
		<comments>http://www.kwartzlab.ca/2009/12/remote-debugging-arduino/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 21:44:05 +0000</pubDate>
		<dc:creator>rharding</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[AVR]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>I don't have a fancy JTAG or ICE system for Arduino debugging.  AVR simulators can only take you so far.  So I've been working on creating a remote debugging stub, so you can use GDB (the GNU Debugger) and Insight (a graphical interface to GDB) on your PC to remotely debug code running on the Arduino board (or any AVR-based board.)
<!--more-->
I've had some success.  I got compiled-in breakpoints working a while ago, and reading memory and registers.  Just a moment ago, I actually got single-stepping to work.  From there, settable breakpoints are only a small step.</p>

<p>I still have to support writing memory and registers, and complete the support for breakpoints.  I also need to optimize the rather sloppy, inefficient code.  Right now it takes up a fairly sizable chunk of the program memory.  I also have ideas how I might shrink the Arduino stub down really, really small, by putting another PC-based layer between GDB and the Arduino stub.</p>

<p>Running with breakpoints enabled will, unfortunately, slow the system down considerably.  This is because there is no (easy) way to stuff a breakpoint instruction into the AVR's flash program memory.  So, breakpoints are actually implemented by continuously single-stepping until you hit one.</p>

<p>And single-stepping itself is not free.  The AVR has no internal mechanism for single-stepping.  It's implemented by forcing a hardware interrupt on one of the IO ports.  Fortunately, it will let you choose which IO port to use, to hopefully avoid a conflict with your system's requirements.  Currently Analog Comparator (Port D:6,7), External Interrupt 0 (Port D:2) and External Interrupt 1 (Port D:3) can be used for single-stepping.</p>
]]></description>
				<content:encoded><![CDATA[<p>I don&#8217;t have a fancy JTAG or ICE system for Arduino debugging.  AVR simulators can only take you so far.  So I&#8217;ve been working on creating a remote debugging stub, so you can use GDB (the GNU Debugger) and Insight (a graphical interface to GDB) on your PC to remotely debug code running on the Arduino board (or any AVR-based board.)<br />
<span id="more-226"></span><br />
I&#8217;ve had some success.  I got compiled-in breakpoints working a while ago, and reading memory and registers.  Just a moment ago, I actually got single-stepping to work.  From there, settable breakpoints are only a small step.</p>
<p>I still have to support writing memory and registers, and complete the support for breakpoints.  I also need to optimize the rather sloppy, inefficient code.  Right now it takes up a fairly sizable chunk of the program memory.  I also have ideas how I might shrink the Arduino stub down really, really small, by putting another PC-based layer between GDB and the Arduino stub.</p>
<p>Running with breakpoints enabled will, unfortunately, slow the system down considerably.  This is because there is no (easy) way to stuff a breakpoint instruction into the AVR&#8217;s flash program memory.  So, breakpoints are actually implemented by continuously single-stepping until you hit one.</p>
<p>And single-stepping itself is not free.  The AVR has no internal mechanism for single-stepping.  It&#8217;s implemented by forcing a hardware interrupt on one of the IO ports.  Fortunately, it will let you choose which IO port to use, to hopefully avoid a conflict with your system&#8217;s requirements.  Currently Analog Comparator (Port D:6,7), External Interrupt 0 (Port D:2) and External Interrupt 1 (Port D:3) can be used for single-stepping.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2009/12/remote-debugging-arduino/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arduino XBee communication</title>
		<link>http://www.kwartzlab.ca/2009/11/arduino-xbee-communication/</link>
		<comments>http://www.kwartzlab.ca/2009/11/arduino-xbee-communication/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 06:07:21 +0000</pubDate>
		<dc:creator>Mattbee</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[wireless]]></category>
		<category><![CDATA[XBee]]></category>
		<category><![CDATA[ZigBee]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>This past week, i finally got 2 Arduinos (Arduini?) to communicate with the XBee shield. I wasn’t happy with the <a href="http://www.arduino.cc/en/Main/ArduinoXbeeShield">tutorials online</a>, because these didn’t seem to tell you what you needed while at the same time included a lot of unnecessary info. Using ZNet 2.5 (Series 2) involves only one extra step.</p>

<p>The following parts were used:</p>

<table>
<thead>
<tr>
  <th>Quantity</th>
  <th>Part</th>
  <th align="right">Cost ea (CAD)</th>
</tr>
</thead>
<tbody>
<tr>
  <td>2</td>
  <td>Arduino Duemilanove</td>
  <td align="right">33</td>
</tr>
<tr>
  <td>2</td>
  <td>Arduino XBee Shield v1.1 (includes XBee Series 2 module)</td>
  <td align="right">87</td>
</tr>
<tr>
  <td>1</td>
  <td>USB A B cable (salvaged)</td>
  <td align="right">0</td>
</tr>
<tr>
  <td>1</td>
  <td>Power adapter (salvaged)</td>
  <td align="right">0</td>
</tr>
<tr>
  <td></td>
  <td>Total</td>
  <td align="right">240</td>
</tr>
</tbody>
</table>

<p><a href="http://www.flickr.com/photos/44415145@N00/4114324249/" title="PFZ20-09781 Arduino with XBee shield by mbells, on Flickr"><img src="http://farm3.static.flickr.com/2651/4114324249_b00d2c72ba.jpg" width="500" height="381" alt="PFZ20-09781 Arduino with XBee shield" /></a></p>

<hr />

<h2>Basic Setup</h2>

<p>The menu Tools --> Board --> Arduino Deumilanove w/ ATmega328 was selected.
The menu Tools --> Serial Post --> (appropriate port) was selected. Note the port needs to be selected each time a different Arduino is connected to USB. One automatically binds to COM3 and the other to COM4; there is most likely a setting somewhere to have these on the same COM port, but that would later preclude connecting both at the same time.</p>

<hr />

<h2>Testing the XBee</h2>

<p>The shield and wireless module were assembled onto the Arduino. The jumpers on the XBee shield were put into the outward position. The Arduino was plugged into USB. The following sketch was uploaded:</p>

<p>Sketch: XBee_diagnostics</p>

<pre><code>void setup()
{
    Serial.begin(9600);
}

void loop()
{
    Serial.println("+++");
    delay(2000);
    echo();
    Serial.println("ATID");
    echo();
}

void echo() {
    byte incomingByte;

    // see if there's incoming serial data:
    delay(50);
    while (Serial.available() &#62; 0) {
        // read the oldest byte in the serial buffer:
        incomingByte = Serial.read();
        Serial.write(incomingByte);
        if(incomingByte != '\r') {
            Serial.write(' ');
        }
        delay(100);
    }
}
</code></pre>

<p>The Arduino was unplugged from USB, the jumpers switched to the inward position, then the serial monitor activated. The XBee should be responding with 234 as the ID (for Series 2).</p>

<hr />

<h2>Configuring</h2>

<p>Use <a href="http://www.digi.com/support/kbase/kbaseresultdetl.jsp?kb=125">X-CTU</a> to configure. Alternatively, any serial terminal will do. Note that the ATmega328 must be removed and the XBee shield pins placed in the outward position for this to work.</p>

<p>It may be preferred to configure the XBee module as part of a sketch and avoid removing the processor or finding a terminal program. The diagnostic sketch may be modified to with the following:</p>

<pre><code>void loop()
{
    delay(2000);
    Serial.println("+++");
    delay(2000);
    echo();
    Serial.println("ATDL FFFF");
    echo();
    Serial.println("ATWR");
    echo();
    delay(10000);
}
</code></pre>

<p>After configuring, the Arduino was unplugged fro USB.</p>

<hr />

<h2>Transmitter</h2>

<p>The jumpers on the XBee shield were put into the outward position. The Arduino was plugged into USB. The following sketch was uploaded:</p>

<p>Sketch: Send_physical_pixel</p>

<pre><code>const int ledPin = 13;

void setup()
{
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
}

void loop()
{
    digitalWrite(ledPin, HIGH);
    Serial.print('H');
    delay(1000);

    digitalWrite(ledPin, LOW);
    Serial.print('L');
    delay(1000);
}
</code></pre>

<p>The Arduino was unplugged from USB, the jumpers switched to the inward position. Then the Arduino was plugged into USB and the serial monitor activated. The serial monitor showed a string of HLHL… The LED was flashing at 0.5 Hz.</p>

<p>The Arduino was unplugged from USB, and the plugged this into the power adapter. The LED continued to flash at 0.5 Hz.</p>

<hr />

<h2>Receiver</h2>

<p>Now for the second Arduino with XBee shield. The jumpers on the XBee shield were put into the outward position. The Arduino was plugged into USB and the following sketch Sketchbook --> Examples --> Communication --> PhysicalPixel was uploaded (unchanged).</p>

<p>The LED on the receiver is observed going on and off. However, not at regular 1 second intervals – the XBee sometimes groups the H and L sends together so these will be read at irregular intervals.</p>

<hr />

<h1>More Details</h1>

<p>Note if you are in an area with ore XBee modules, then more configuration will be required to prevent all pairs from interfering with others.</p>

<h2>Jumper meanings</h2>

<p>When loading the Arduino while the XBee shield is attached, ensure the pins are in the USB position. Here’s a table of the <a href="http://www.arduino.cc/en/Main/ArduinoXbeeShield">explanation of jumper settings</a>:</p>

<table>
<thead>
<tr>
  <th>Position</th>
  <th>Meaning</th>
  <th>Connections</th>
  <th>Connections</th>
</tr>
</thead>
<tbody>
<tr>
  <td>Inward</td>
  <td>XBee</td>
  <td>Xbee.DOUT = Micro.RX = FTDI.TX</td>
  <td>Xbee.DIN = Micro.TX = FTDI.RX</td>
</tr>
<tr>
  <td>Outward</td>
  <td>USB</td>
  <td>Xbee.DOUT = FTDI.RX</td>
  <td>Xbee.DIN = FTDI.TX</td>
</tr>
</tbody>
</table>

<p><a href="http://www.flickr.com/photos/44415145@N00/4115096202/" title="XBee shield jumpers in XBee position "><img src="http://farm3.static.flickr.com/2753/4115096202_2fc8cfb962_m.jpg" width="240" height="135" alt="PFZ20-09787 XBee shield jumpers XBee" /></a></p>

<p><a href="http://www.flickr.com/photos/44415145@N00/4115095992/" title="XBee shield jumpers in USB position"><img src="http://farm3.static.flickr.com/2618/4115095992_d266af954f_m.jpg" width="240" height="135" alt="PFZ20-09786 XBee shield jumpers USB" /></a></p>
]]></description>
				<content:encoded><![CDATA[<p>This past week, i finally got 2 Arduinos (Arduini?) to communicate with the XBee shield. I wasn’t happy with the <a href="http://www.arduino.cc/en/Main/ArduinoXbeeShield">tutorials online</a>, because these didn’t seem to tell you what you needed while at the same time included a lot of unnecessary info. Using ZNet 2.5 (Series 2) involves only one extra step.</p>
<p>The following parts were used:</p>
<table>
<thead>
<tr>
<th>Quantity</th>
<th>Part</th>
<th align="right">Cost ea (CAD)</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>Arduino Duemilanove</td>
<td align="right">33</td>
</tr>
<tr>
<td>2</td>
<td>Arduino XBee Shield v1.1 (includes XBee Series 2 module)</td>
<td align="right">87</td>
</tr>
<tr>
<td>1</td>
<td>USB A B cable (salvaged)</td>
<td align="right">0</td>
</tr>
<tr>
<td>1</td>
<td>Power adapter (salvaged)</td>
<td align="right">0</td>
</tr>
<tr>
<td></td>
<td>Total</td>
<td align="right">240</td>
</tr>
</tbody>
</table>
<p><a href="http://www.flickr.com/photos/44415145@N00/4114324249/" title="PFZ20-09781 Arduino with XBee shield by mbells, on Flickr"><img src="http://farm3.static.flickr.com/2651/4114324249_b00d2c72ba.jpg" width="500" height="381" alt="PFZ20-09781 Arduino with XBee shield" /></a></p>
<hr />
<h2>Basic Setup</h2>
<p>The menu Tools &#8211;> Board &#8211;> Arduino Deumilanove w/ ATmega328 was selected.<br />
The menu Tools &#8211;> Serial Post &#8211;> (appropriate port) was selected. Note the port needs to be selected each time a different Arduino is connected to USB. One automatically binds to COM3 and the other to COM4; there is most likely a setting somewhere to have these on the same COM port, but that would later preclude connecting both at the same time.</p>
<hr />
<h2>Testing the XBee</h2>
<p>The shield and wireless module were assembled onto the Arduino. The jumpers on the XBee shield were put into the outward position. The Arduino was plugged into USB. The following sketch was uploaded:</p>
<p>Sketch: XBee_diagnostics</p>
<pre><code>void setup()
{
    Serial.begin(9600);
}

void loop()
{
    Serial.println("+++");
    delay(2000);
    echo();
    Serial.println("ATID");
    echo();
}

void echo() {
    byte incomingByte;

    // see if there's incoming serial data:
    delay(50);
    while (Serial.available() &gt; 0) {
        // read the oldest byte in the serial buffer:
        incomingByte = Serial.read();
        Serial.write(incomingByte);
        if(incomingByte != '\r') {
            Serial.write(' ');
        }
        delay(100);
    }
}
</code></pre>
<p>The Arduino was unplugged from USB, the jumpers switched to the inward position, then the serial monitor activated. The XBee should be responding with 234 as the ID (for Series 2).</p>
<hr />
<h2>Configuring</h2>
<p>Use <a href="http://www.digi.com/support/kbase/kbaseresultdetl.jsp?kb=125">X-CTU</a> to configure. Alternatively, any serial terminal will do. Note that the ATmega328 must be removed and the XBee shield pins placed in the outward position for this to work.</p>
<p>It may be preferred to configure the XBee module as part of a sketch and avoid removing the processor or finding a terminal program. The diagnostic sketch may be modified to with the following:</p>
<pre><code>void loop()
{
    delay(2000);
    Serial.println("+++");
    delay(2000);
    echo();
    Serial.println("ATDL FFFF");
    echo();
    Serial.println("ATWR");
    echo();
    delay(10000);
}
</code></pre>
<p>After configuring, the Arduino was unplugged fro USB.</p>
<hr />
<h2>Transmitter</h2>
<p>The jumpers on the XBee shield were put into the outward position. The Arduino was plugged into USB. The following sketch was uploaded:</p>
<p>Sketch: Send_physical_pixel</p>
<pre><code>const int ledPin = 13;

void setup()
{
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
}

void loop()
{
    digitalWrite(ledPin, HIGH);
    Serial.print('H');
    delay(1000);

    digitalWrite(ledPin, LOW);
    Serial.print('L');
    delay(1000);
}
</code></pre>
<p>The Arduino was unplugged from USB, the jumpers switched to the inward position. Then the Arduino was plugged into USB and the serial monitor activated. The serial monitor showed a string of HLHL… The LED was flashing at 0.5 Hz.</p>
<p>The Arduino was unplugged from USB, and the plugged this into the power adapter. The LED continued to flash at 0.5 Hz.</p>
<hr />
<h2>Receiver</h2>
<p>Now for the second Arduino with XBee shield. The jumpers on the XBee shield were put into the outward position. The Arduino was plugged into USB and the following sketch Sketchbook &#8211;> Examples &#8211;> Communication &#8211;> PhysicalPixel was uploaded (unchanged).</p>
<p>The LED on the receiver is observed going on and off. However, not at regular 1 second intervals – the XBee sometimes groups the H and L sends together so these will be read at irregular intervals.</p>
<hr />
<h1>More Details</h1>
<p>Note if you are in an area with ore XBee modules, then more configuration will be required to prevent all pairs from interfering with others.</p>
<h2>Jumper meanings</h2>
<p>When loading the Arduino while the XBee shield is attached, ensure the pins are in the USB position. Here’s a table of the <a href="http://www.arduino.cc/en/Main/ArduinoXbeeShield">explanation of jumper settings</a>:</p>
<table>
<thead>
<tr>
<th>Position</th>
<th>Meaning</th>
<th>Connections</th>
<th>Connections</th>
</tr>
</thead>
<tbody>
<tr>
<td>Inward</td>
<td>XBee</td>
<td>Xbee.DOUT = Micro.RX = FTDI.TX</td>
<td>Xbee.DIN = Micro.TX = FTDI.RX</td>
</tr>
<tr>
<td>Outward</td>
<td>USB</td>
<td>Xbee.DOUT = FTDI.RX</td>
<td>Xbee.DIN = FTDI.TX</td>
</tr>
</tbody>
</table>
<p><a href="http://www.flickr.com/photos/44415145@N00/4115096202/" title="XBee shield jumpers in XBee position "><img src="http://farm3.static.flickr.com/2753/4115096202_2fc8cfb962_m.jpg" width="240" height="135" alt="PFZ20-09787 XBee shield jumpers XBee" /></a></p>
<p><a href="http://www.flickr.com/photos/44415145@N00/4115095992/" title="XBee shield jumpers in USB position"><img src="http://farm3.static.flickr.com/2618/4115095992_d266af954f_m.jpg" width="240" height="135" alt="PFZ20-09786 XBee shield jumpers USB" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2009/11/arduino-xbee-communication/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
