<?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; Jonathan Lamothe</title>
	<atom:link href="http://www.kwartzlab.ca/author/jlamothe/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kwartzlab.ca</link>
	<description>Home of Kwartzlab Makerspace in Kitchener/Waterloo, Ontario</description>
	<lastBuildDate>Fri, 24 May 2013 16:54:58 +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; Jonathan Lamothe</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>Adventures in Haskell</title>
		<link>http://www.kwartzlab.ca/2012/08/adventures-haskell/</link>
		<comments>http://www.kwartzlab.ca/2012/08/adventures-haskell/#comments</comments>
		<pubDate>Thu, 30 Aug 2012 01:31:40 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[voodoo]]></category>

		<guid isPermaLink="false">http://www.kwartzlab.ca/?p=2836</guid>
		<description><![CDATA[So I&#8217;ve decided that it&#8217;s time to expand my horizons and put a new programming language under my belt. I&#8217;ve been told by a number of people now that Haskell is awesome, so I decided to give learning it a go. I&#8217;ve been reading over Learn You a Haskell for Great Good! I&#8217;m not done [...]]]></description>
				<content:encoded><![CDATA[<p>So I&#8217;ve decided that it&#8217;s time to expand my horizons and put a new programming language under my belt.  I&#8217;ve been told by a number of people now that Haskell is awesome, so I decided to give learning it a go.  I&#8217;ve been reading over <a href="http://learnyouahaskell.com">Learn You a Haskell for Great Good!</a>  I&#8217;m not done reading through it, but I definitely recommend it to anyone who wants to learn Haskell.  Anyhow, over the course of my tinkering around with Haskell, I&#8217;ve learnt that Haskell is full of freaky voodoo mathemagics (yes, that&#8217;s a word now).</p>
<p><span id="more-2836"></span></p>
<p>Since I still haven&#8217;t managed to figure out I/O, I decided to start by rolling my own square root function.  There&#8217;s a fairly simple algorithm to do this:</p>
<p>Suppose we want to find the square root of X.  We can start by making a guess, we&#8217;ll call it G (1 tends to be a good start).  We can then square our guess to see if it works out to X, if not, we can get a closer approximation by taking the average of G and G/X.  We simply need to repeat this process over and over again until we converge on the square root of X.</p>
<p>To implement this, I wrote two simple functions.  First, there was the square root function itself.  It looked like this:</p>
<pre>sqrt' :: (Floating a, Ord a) =&gt; a -&gt; a
sqrt' x
  | x</span></span> &lt; 0 = error "square root of negative number"
  | otherwise = limit (\g -&gt; (g + x / g) / 2) 1</pre>
<p>Basically, the <code>sqrt'</code> function checks the value of its input (<code>x</code>), if it&#8217;s negative, it throws an error, otherwise, it calls a <code>limit</code> function that takes a function and a value, and repeats that function over and over until we converge on a constant value.  I&#8217;ve defined the limit function as follows:</p>
<pre>limit :: Eq a =&gt; (a -&gt; a) -&gt; a -&gt; a
limit f x
  | thisTry == x = x
  | otherwise = limit f thisTry
  where thisTry = f x</pre>
<p>Naturally, I wanted to see how quickly and accurately my function would calculate square roots, so I started out with a number with a known square root&#8230; say 4.  When I ran the function, this was the instantaneous result:</p>
<pre>*Main&gt; sqrt' 4
2.0</pre>
<p>Good.  That&#8217;s what I would expect to see.  Let&#8217;s see what happens when we try to use the function to calculate the square root of 2, comparing it to the built-in square root function.</p>
<pre>*Main&gt; sqrt' 2
1.414213562373095
*Main&gt; sqrt 2
1.4142135623730951</pre>
<p>Excellent.  So we&#8217;ve now established that the function will quickly calculate square roots.  Next, I wanted to try doing a little stress testing.  I happen to know (from being bored in math class back in my high school days) that if you take a large nubmer and repeatedly take the square root, you&#8217;ll eventually converge on the number 1.  Let&#8217;s try it with a really large number&#8230; say 10<sup>10</sup>.  Putting my newly created limit function to the test, I got the following result immediately:</p>
<pre>*Main&gt; limit (\x -&gt; sqrt' x) (10^10)
1.0</pre>
<p>That&#8217;s impressive, I was expecting it to take at least a second or so to calculate, after all, 10<sup>10</sup> is a pretty large number.  It should have to loop around quite a few times before it converges on 1.  Let&#8217;s try a googol (10<sup>100</sup>):</p>
<pre>*Main&gt; limit (\x -&gt; sqrt' x) (10^100)
1.0</pre>
<p>Still, instantaneous?  Challenge accepted.  How big do we need to go before we crash the system, or at least slow it down?</p>
<p>As it turns out, pretty big.  I got as high as 10<sup>400</sup> before I managed to hang the machine (while still not consuming more than 2% of my total system memory).  That&#8217;s pretty impressive.  My previous attempt 10<sup>300</sup> was still instantaneous.</p>
<p>The one thing I know for sure is that the next time I need to write a program that runs some serious computations, I&#8217;ll definitely be considering Haskell.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2012/08/adventures-haskell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cryptography Workshop</title>
		<link>http://www.kwartzlab.ca/2012/07/cryptography-workshop/</link>
		<comments>http://www.kwartzlab.ca/2012/07/cryptography-workshop/#comments</comments>
		<pubDate>Sun, 08 Jul 2012 20:45:24 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Workshops]]></category>

		<guid isPermaLink="false">http://www.kwartzlab.ca/?p=2675</guid>
		<description><![CDATA[Yesterday, I ran my first cryptography workshop and keysigning party at kwartzlab (actually, it was my first workshop, period). The turnout was actually a lot better than I was expecting. Unfortunately, I didn&#8217;t think to take pictures. This post is mainly about my observations on how I&#8217;d do things differently if I were to run [...]]]></description>
				<content:encoded><![CDATA[<p>Yesterday, I ran my first cryptography workshop and keysigning party at kwartzlab (actually, it was my first workshop, period).  The turnout was actually a lot better than I was expecting.  Unfortunately, I didn&#8217;t think to take pictures.</p>
<p>This post is mainly about my observations on how I&#8217;d do things differently if I were to run one again (and I probably will) as well as some reference notes for the people who attended.</p>
<p><span id="more-2675"></span></p>
<h2>What is Cryptography?</h2>
<p>For those unfamiliar with cryptography, Khan Academy has <a href="http://www.khanacademy.org/science/brit-cruise/cryptography">an excellent series of video tutorials</a> on the subject, although, they deal mainly with the basic mathematics behind the subject, which I find fascinating, but may not be your cup of tea.</p>
<h2>How the Workshop Worked</h2>
<p>The workshop was focused on the basics of the <a>GNU Privacy Guard</a> (often referred to as GnuPG or just GPG), which is a free implementation of the OpenPGP protocol, a <a href="http://en.wikipedia.org/wiki/Public-key_cryptography">public key cryptosystem</a>.</p>
<p>The tutorial was broken up into two parts.  The first part was a basic rundown on what public key cryptography is, and how to use GnuPG.  This part ran pretty smoothly.  The second part was the actual key generation and signing.  Because of the large number of people present, this ran significantly longer than I had expected; I think I finally went home around 11PM.</p>
<h2>How I&#8217;d Do It Better</h2>
<p>Ideally, when you run a keysigning party, you want people to have their keys generated beforehand.  Since this was a tutorial as well, this can&#8217;t really be done for some people, but it doesn&#8217;t take that long to generate keys.</p>
<p>I think next time, I&#8217;ll create some sort of script that will allow people to generate and print a sheet of paper, which can be cut into slips, containing their name, e-mail address, key ID, and fingerprint.  Rather than signing the keys at the event, they can simply hand these slips out to the other participants (showing ID where necessary).  Afterwards, people can just go home and sign the keys there using the slips to validate them.  That way, only the people who are not familiar with the software will need to stay behind for help, and even then, they&#8217;ll probably get it after signing a key or two.</p>
<h2>Using GnuPG through the Command Line</h2>
<p>I was going to write an explanation of how to do the most common tasks in GnuPG, but I found <a href="http://irtfweb.ifa.hawaii.edu/~lockhart/gpg/gpg-cs.html">this handy guide to using GnuPG on the command line</a> so I won&#8217;t bother duplicating that effort.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2012/07/cryptography-workshop/feed/</wfw:commentRss>
		<slash:comments>0</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>Etching PCBs without Ferric Chloride</title>
		<link>http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/</link>
		<comments>http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 04:31:13 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[etching]]></category>
		<category><![CDATA[ferric chloride]]></category>
		<category><![CDATA[hydrogen peroxide]]></category>
		<category><![CDATA[muriatic acid]]></category>
		<category><![CDATA[pcb]]></category>

		<guid isPermaLink="false">http://www.kwartzlab.ca/?p=1293</guid>
		<description><![CDATA[I came across this tutorial a while ago detailing how to etch PCBs using common household chemicals instead of ferric chloride. Being a lazy person who doesn&#8217;t want to drive out to Sayal (in Cambridge) to get ferric chloride, I decided to give it a shot and take pictures documenting the attempt. Here&#8217;s the result: [...]]]></description>
				<content:encoded><![CDATA[<p>I came across <a href="http://www.instructables.com/id/Stop-using-Ferric-Chloride-etchant!--A-better-etc/">this tutorial</a> a while ago detailing how to etch PCBs using common household chemicals instead of ferric chloride.  Being a lazy person who doesn&#8217;t want to drive out to Sayal (in Cambridge) to get ferric chloride, I decided to give it a shot and take pictures documenting the attempt.  Here&#8217;s the result:<br />
<span id="more-1293"></span><br />
<div id="attachment_1281" class="wp-caption alignnone" style="width: 310px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329111823-01/" rel="attachment wp-att-1281"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329111823-01-e1303531510913-300x400.jpg" alt="" width="300" height="400" class="size-medium wp-image-1281" /></a><p class="wp-caption-text">Pouring muriatic acid into the etchant (add the peroxide first)</p></div></p>
<div id="attachment_1284" class="wp-caption alignnone" style="width: 410px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329111932-00/" rel="attachment wp-att-1284"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329111932-00-400x300.jpg" alt="" width="400" height="300" class="size-medium wp-image-1284" /></a><p class="wp-caption-text">The design printed onto magazine paper (for toner transfer)</p></div>
<div id="attachment_1282" class="wp-caption alignnone" style="width: 310px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329111859-00/" rel="attachment wp-att-1282"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329111859-00-e1303531494730-300x400.jpg" alt="" width="300" height="400" class="size-medium wp-image-1282" /></a><p class="wp-caption-text">Loaded into the heat press</p></div>
<div id="attachment_1283" class="wp-caption alignnone" style="width: 410px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329111903-00/" rel="attachment wp-att-1283"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329111903-00-400x300.jpg" alt="" width="400" height="300" class="size-medium wp-image-1283" /></a><p class="wp-caption-text">Using the press to transfer the toner onto the board</p></div>
<div id="attachment_1285" class="wp-caption alignnone" style="width: 410px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329111948-00/" rel="attachment wp-att-1285"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329111948-00-400x300.jpg" alt="" width="400" height="300" class="size-medium wp-image-1285" /></a><p class="wp-caption-text">Cooling the board down before removing the paper</p></div>
<div id="attachment_1286" class="wp-caption alignnone" style="width: 410px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329112005-00/" rel="attachment wp-att-1286"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329112005-00-400x300.jpg" alt="" width="400" height="300" class="size-medium wp-image-1286" /></a><p class="wp-caption-text">Paper carefully removed from the board to keep the toner intact</p></div>
<div id="attachment_1287" class="wp-caption alignnone" style="width: 410px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329112005-01/" rel="attachment wp-att-1287"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329112005-01-400x300.jpg" alt="" width="400" height="300" class="size-medium wp-image-1287" /></a><p class="wp-caption-text">The other side</p></div>
<div id="attachment_1288" class="wp-caption alignnone" style="width: 410px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329112012-01/" rel="attachment wp-att-1288"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329112012-01-400x300.jpg" alt="" width="400" height="300" class="size-medium wp-image-1288" /></a><p class="wp-caption-text">Freshly made etchant starts to turn green as it absorbs copper from the board</p></div>
<div id="attachment_1289" class="wp-caption alignnone" style="width: 410px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329112021-01/" rel="attachment wp-att-1289"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329112021-01-400x300.jpg" alt="" width="400" height="300" class="size-medium wp-image-1289" /></a><p class="wp-caption-text">Starting to etch the copper off the board</p></div>
<div id="attachment_1292" class="wp-caption alignnone" style="width: 410px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329112058-01/" rel="attachment wp-att-1292"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329112058-01-400x300.jpg" alt="" width="400" height="300" class="size-medium wp-image-1292" /></a><p class="wp-caption-text">The front of the (almost) finished board</p></div>
<div id="attachment_1291" class="wp-caption alignnone" style="width: 410px"><a href="http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/0329112058-00/" rel="attachment wp-att-1291"><img src="http://www.kwartzlab.ca/wp-content/uploads/2011/04/0329112058-00-400x300.jpg" alt="" width="400" height="300" class="size-medium wp-image-1291" /></a><p class="wp-caption-text">The reverse side of the (almost) finished board</p></div>
<p>As can be seen from the last picture, I left the board in the etchant a little too long (it was more active than I expected).  Apparently, after a few uses it becomes a little slower acting, although I&#8217;ve considered using this effect to somehow watermark my boards.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2011/04/etching-pcbs-without-ferric-chloride/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Homebrew Arduino 0-10v Shield</title>
		<link>http://www.kwartzlab.ca/2011/03/homebrew-arduino-0-10v-shield/</link>
		<comments>http://www.kwartzlab.ca/2011/03/homebrew-arduino-0-10v-shield/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 00:06:58 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.kwartzlab.ca/?p=1032</guid>
		<description><![CDATA[One of the things I&#8217;ve wanted to learn to do since joining the lab has been designing my own printed circuit boards. Also, having worked with the Arduino for a little while, one of the things I&#8217;ve found it lacks is support for 0-10v analog outputs. In fact, it really lacks any analog outputs at [...]]]></description>
				<content:encoded><![CDATA[<p>One of the things I&#8217;ve wanted to learn to do since joining the lab has been designing my own printed circuit boards.  Also, having worked with the <a href="http://arduino.cc" title="Arduino Homepage">Arduino</a> for a little while, one of the things I&#8217;ve found it lacks is support for 0-10v analog outputs.  In fact, it really lacks any analog outputs at all; the closest it has are six 5v pulse width modulation outputs, which I find less useful than a proper analog output.  The logical solution to both of these dilemas was to design my own shield which would allow the PWM outputs to be converted to 0-10v.</p>
<p><span id="more-1032"></span></p>
<p>The first decision that had to be made was what PCB layout software to use.  Eagle seems to be a rather popular package for PCB layout (for both hobbyists and professionals) and I&#8217;ve used it at work, but it&#8217;s proprietary.  As a <a href="http://www.gnu.org/philosophy/free-sw.html" title="Free Software Definition">free software</a> developer, I&#8217;d much rather use a free (as in speech) tool if at all possible, so I set out to find one.  Enter <a href="http://gpleda.org" title="gEDA Homepage">gEDA</a>.  gEDA is a <a href="http://www.gnu.org/licenses/licenses.html#GPL" title="GPL License">GPL-licensed</a> suite of PCB design tools.</p>
<p>One of the things that I&#8217;ve heard people complaining about when designing Arduino shields is the non-standard pin spacing.  I didn&#8217;t really get what they were complaining about until I set out to make one of my own.  There are four headers (two with six pins and two with eight) on the board, and for the most part they&#8217;re pretty standard: 100mil spacing between pins on each header and a 200mil spacing between pins on the gap between the bottom two connectors, but a 160mil gap between the two headers on the top.  In the PCB editor, you could just use a 100mil grid if it weren&#8217;t for that one header.  It really was a bit of a headache to get the pads in the right places.</p>
<p>Not wanting to have to do the work of getting the pins set up properly twice, I decided to make a custom symbol and footprint for an <a href="http://arduino.cc/en/Main/ArduinoBoardUno" title="Arduino Uno Specs">Arduino Uno</a> board.  That way, on future Arduino shields, I could simply drop a block representing the Arduino into the schematic and it would automatically place all the pins on the PCB where they&#8217;ll fit the board.  If I drag one header around, the othes will follow to maintain proper spacing.  Quite handy.</p>
<p>Being a suite of programs rather than a single monolithic program, creating PCBs with gEDA is a little more involved than it is with Eagle, but it&#8217;s still pretty straight-forward.  You start by creating one or more schematics (one per page) with gschem.  The schematic files are in a well-documented plain-text format, so you could make them with a simple text editor, but that&#8217;s way too hardcore for even me.  With gschem, it&#8217;s all drag and drop.</p>
<p>The next step is to use the gsch2pcb program to convert your schematics into a pcb file and a netlist (it also creates a .cmd file, but I don&#8217;t know what that&#8217;s for).  From there, you open the pcb file with their pcb layout editor (creatively named pcb) place the components, import the netlist, and then you can use the auto-routing feature to draw all the traces on the board.  I had to play with trace and via sizing so that I could get all the traces to fit into two layers.  <a href="http://www.kwartzlab.ca/author/Don-Leibold/" title="Don Leibold">Don</a> showed me a way to manufacture PCBs, but it only works for two-layer boards.</p>
<p>Unfortunately, there are now a number of vias on the board that have a hole size of 20mil&#8230; that&#8217;s going to require a steady hand to drill.  Perhaps in a later version, I&#8217;ll use SMT components to free up some space on the board so I can use larger vias.</p>
<p>That&#8217;s about it for my progress so far.  I&#8217;ll be sure to blog some more as I actually attempt to manufacture these boards.  They&#8217;re going to be a little more complex than I&#8217;d like for a first attempt at using this manufacturing process, but I&#8217;m always up for a challenge.</p>
<p>Happy Hacking.</p>
<p><b>EDIT 5 Mar 2011:</b><br />
I almost forgot to post links to the actual project.</p>
<ul>
<li>Here&#8217;s my list of <a href="http://github.com/jlamothe/symbols">custom symbols</a>.</li>
<li>Here&#8217;s my list of <a href="http://github.com/jlamothe/footprints">custom footprints</a>.</li>
<li>And last but not least, here&#8217;s the <a href="http://github.com/jlamothe/arduino-0-10v-shield">actual shield</a>.</li>
</ul>
<p>Also, there&#8217;s a more descriptive <a href="http://geda.seul.org/wiki/geda:gsch2pcb_tutorial" title="gEDA Tutorial">tutorial</a> on how to use gEDA on their website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2011/03/homebrew-arduino-0-10v-shield/feed/</wfw:commentRss>
		<slash:comments>5</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>SoOnCon Badge Help</title>
		<link>http://www.kwartzlab.ca/2010/10/sooncon-badge-help/</link>
		<comments>http://www.kwartzlab.ca/2010/10/sooncon-badge-help/#comments</comments>
		<pubDate>Sat, 16 Oct 2010 14:32:09 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[help]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>So, I've been playing around with the SoOnCon badge over the past couple weeks, but I've hit what I think is a problem with my board.</p>

<!--more-->

<p>It started when I was looking at the code that defines the switches (SoonCon2010Badge.h) and saw this:</p>

<pre><code>#define SWITCH_0  0
#define SWITCH_1  1
#define SWITCH_2 35
#define SWITCH_4  7

</code></pre>

<p>Yes, that's right, the switches are numbered 0, 1, 2 and 4.  A little odd, but I decided that I should investigate farther.</p>

<p>I wrote a test program that would check the statuses of these switches and blink the red segment of the LED on the top differently depending on which switch was depressed.  I remembered hearing that the switches had internal pull-up resistors, so their normal (open) state would be high.</p>

<p>I set up the blinking patterns like so:</p>

<table>
<thead>
<tr>
<th align="center">Switch Depressed</th>
<th align="center">Number of Blinks</th>
</tr>
</thead>
<tbody>
<tr>

<td align="center"><code>SWITCH_0</code></td>
<td align="center">3</td>
</tr>
<tr>
<td align="center"><code>SWITCH_1</code></td>
<td align="center">1</td>
</tr>
<tr>
<td align="center"><code>SWITCH_2</code></td>
<td align="center">2</td>
</tr>

<tr>
<td align="center"><code>SWITCH_4</code></td>
<td align="center">4</td>
</tr>
</tbody>
</table>

<p>What I've discovered from playing with this is that the switch on the bottom left is <code>SWITCH_1</code> and the switch on the bottom right is <code>SWITCH_4</code>.  I'm assuming that the switch on the top right is <code>SWITCH_2</code>, but according to my program, it is continuously depressed, and <code>SWITCH_0</code> (I'm assuming this to be the reset pin) is never depressed.</p>

<p>I suspect that this is a problem with my board rather than a problem with my code.</p>

<p>If there's anyone else out there who's been able to compile and install new firmware onto their badge, can they do me the favour of trying my code out and describing the blinking patterns they see?</p>

<p>The code is on github (the switch-test branch).  It can be found <a href="http://github.com/jlamothe/arduinizer/tree/switch-test" title="arduinizer switch-test branch">here</a>.</p>

<h2>Update 2010-10-17:</h2>

<p>This issue has been resolved.  I found a patch on the original sourceforge page that I have imported into the git repository.</p>
]]></description>
				<content:encoded><![CDATA[<p>So, I&#8217;ve been playing around with the SoOnCon badge over the past couple weeks, but I&#8217;ve hit what I think is a problem with my board.</p>
<p><span id="more-432"></span></p>
<p>It started when I was looking at the code that defines the switches (SoonCon2010Badge.h) and saw this:</p>
<pre><code>#define SWITCH_0  0
#define SWITCH_1  1
#define SWITCH_2 35
#define SWITCH_4  7

</code></pre>
<p>Yes, that&#8217;s right, the switches are numbered 0, 1, 2 and 4.  A little odd, but I decided that I should investigate farther.</p>
<p>I wrote a test program that would check the statuses of these switches and blink the red segment of the LED on the top differently depending on which switch was depressed.  I remembered hearing that the switches had internal pull-up resistors, so their normal (open) state would be high.</p>
<p>I set up the blinking patterns like so:</p>
<table>
<thead>
<tr>
<th align="center">Switch Depressed</th>
<th align="center">Number of Blinks</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><code>SWITCH_0</code></td>
<td align="center">3</td>
</tr>
<tr>
<td align="center"><code>SWITCH_1</code></td>
<td align="center">1</td>
</tr>
<tr>
<td align="center"><code>SWITCH_2</code></td>
<td align="center">2</td>
</tr>
<tr>
<td align="center"><code>SWITCH_4</code></td>
<td align="center">4</td>
</tr>
</tbody>
</table>
<p>What I&#8217;ve discovered from playing with this is that the switch on the bottom left is <code>SWITCH_1</code> and the switch on the bottom right is <code>SWITCH_4</code>.  I&#8217;m assuming that the switch on the top right is <code>SWITCH_2</code>, but according to my program, it is continuously depressed, and <code>SWITCH_0</code> (I&#8217;m assuming this to be the reset pin) is never depressed.</p>
<p>I suspect that this is a problem with my board rather than a problem with my code.</p>
<p>If there&#8217;s anyone else out there who&#8217;s been able to compile and install new firmware onto their badge, can they do me the favour of trying my code out and describing the blinking patterns they see?</p>
<p>The code is on github (the switch-test branch).  It can be found <a href="http://github.com/jlamothe/arduinizer/tree/switch-test" title="arduinizer switch-test branch">here</a>.</p>
<h2>Update 2010-10-17:</h2>
<p>This issue has been resolved.  I found a patch on the original sourceforge page that I have imported into the git repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2010/10/sooncon-badge-help/feed/</wfw:commentRss>
		<slash:comments>2</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>Chess Pathfinder (Knight&#8217;s Tour) 1.2</title>
		<link>http://www.kwartzlab.ca/2010/02/chess-pathfinder-knights-tour/</link>
		<comments>http://www.kwartzlab.ca/2010/02/chess-pathfinder-knights-tour/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 00:24:24 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[chess]]></category>
		<category><![CDATA[knight's tour]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[progress]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>It seems I've made some significant progress with the algorithm, just not enough yet.</p>

<p>After some discussion in the comments of my last entry, I decided that my next attempt should be to add a check after every move to make sure that I hadn't boxed any positions in, making them unreachable.
<!--more-->
I almost dismissed this idea because I originally thought that it would involve checking every position on the board after every move, but it's only necessary to check the eight positions that can be moved to from the current one.</p>

<p>The end result was this: on a 7x7 board, I can now compute the same path in 614 iterations as opposed to the 4430 required before.  This represents an efficiency increase of slightly better than 720% (although that admittedly doesn't account for the overhead added to each iteration by the check itself).  An 8x8 board still takes an unknown amount of time however.</p>

<p>The thing that this check doesn't take into account is the fact that there could be a cluster of positions that can reach each other, but can't be reached from outside; as opposed to a single, isolated position.  I had thought of this before I implemented the check, but hoped that it wouldn't be a significant problem.  It now seems that it may be.</p>

<p>It would seem that the next step is to find a way to look for clusters of isolated positions, although I haven't yet quite decided how to go about that from a programming standpoint.  Whatever I do, I'll have to make sure that the checking process itself is as efficient as possible.</p>

<p>More details as I make more progress.  As usual, here's the <a href="http://github.com/jlamothe/pathfinder/tree/v1.2">source</a> and <a href="http://www.jlamothe.net/projects/pathfinder/v1.2/">documentation</a>.</p>

<p><strong>EDIT - 13 Feb 2011:</strong>
The source and documentation for this version were lost.  I was able to recover the source (without doxygen comments) from Google's cache, but I had to re-write much of the documentation.  The code is now hosted at <a href="http://github.com">GitHub</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>It seems I&#8217;ve made some significant progress with the algorithm, just not enough yet.</p>
<p>After some discussion in the comments of my last entry, I decided that my next attempt should be to add a check after every move to make sure that I hadn&#8217;t boxed any positions in, making them unreachable.<br />
<span id="more-296"></span><br />
I almost dismissed this idea because I originally thought that it would involve checking every position on the board after every move, but it&#8217;s only necessary to check the eight positions that can be moved to from the current one.</p>
<p>The end result was this: on a 7&#215;7 board, I can now compute the same path in 614 iterations as opposed to the 4430 required before.  This represents an efficiency increase of slightly better than 720% (although that admittedly doesn&#8217;t account for the overhead added to each iteration by the check itself).  An 8&#215;8 board still takes an unknown amount of time however.</p>
<p>The thing that this check doesn&#8217;t take into account is the fact that there could be a cluster of positions that can reach each other, but can&#8217;t be reached from outside; as opposed to a single, isolated position.  I had thought of this before I implemented the check, but hoped that it wouldn&#8217;t be a significant problem.  It now seems that it may be.</p>
<p>It would seem that the next step is to find a way to look for clusters of isolated positions, although I haven&#8217;t yet quite decided how to go about that from a programming standpoint.  Whatever I do, I&#8217;ll have to make sure that the checking process itself is as efficient as possible.</p>
<p>More details as I make more progress.  As usual, here&#8217;s the <a href="http://github.com/jlamothe/pathfinder/tree/v1.2">source</a> and <a href="http://www.jlamothe.net/projects/pathfinder/v1.2/">documentation</a>.</p>
<p><strong>EDIT &#8211; 13 Feb 2011:</strong><br />
The source and documentation for this version were lost.  I was able to recover the source (without doxygen comments) from Google&#8217;s cache, but I had to re-write much of the documentation.  The code is now hosted at <a href="http://github.com">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2010/02/chess-pathfinder-knights-tour/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Chess Pathfinder 1.1</title>
		<link>http://www.kwartzlab.ca/2010/02/chess-pathfinder-11/</link>
		<comments>http://www.kwartzlab.ca/2010/02/chess-pathfinder-11/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 18:33:50 +0000</pubDate>
		<dc:creator>Jonathan Lamothe</dc:creator>
				<category><![CDATA[Member Blogs]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[chess]]></category>
		<category><![CDATA[curse you exponential growth!]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>So, after a talk on IRC with @flying_squirrel (<a href="http://kwartzlab.ca/users/darcy-casselman">Darcy</a>), I decided to add a progress indicator to the program.  This indicator would tell me what estimated percentage of the total number of permutations the program had exhausted and display this information in increments of 1%.  As it turns out, this wasn't very helpful.  Let me explain:
<!--more-->
Starting from the upper left hand corner (0, 0) the smallest board on which a path can be found has dimensions of 5x5.  A path is found after exhausting somewhere between 1-2% of the possible permutations.  As I mentioned in my previous blog entry, my computer essentially calculates this instantly.</p>

<p>If we increase the size of the board to 6x6, we don't even use up 1% of the possible permutations and the result is still calculated in an imperceptibly small amount of time.</p>

<p>By the time we increase to 7x7, we're still using less than 1% (I'm assuming much less) of the possible permutations, but the result takes a few fractions of a second to calculate.</p>

<p>At 8x8 it gets really interesting.  The gauge still doesn't register (as expected) but I let the program run for about a minute or so with no result.</p>

<p>This would seem to indicate that as the size of the board increases, the percentage of permutations that we need to exhaust decreases (I'm assuming exponentially) but the amount of time needed increases (also exponentially... which I kind of expected).</p>

<p>From this we can extrapolate that at a size of 10x10, I will probably die before the program reaches a conclusion.  If there's a better way of calculating this it'll either involve a radical optimization of the existing program or (more likely) writing a new one from scratch.</p>

<p>Once again, here's my <a href="http://github.com/jlamothe/pathfinder/tree/v1.1">code</a> and <a href="http://www.jlamothe.net/projects/pathfinder/v1.1/">documentation</a>.</p>

<p>As a matter of interest, I left the original program running in the background.  We're currently sitting at 18+ hours with (surprise) still no result.</p>

<p><strong>EDIT - 13 Feb 2011:</strong>
The source code and documentation were lost.  I found the source cached on Google (it's now hosted at <a href="http://github.com">GitHub</a>) and regenerated the documentation.</p>
]]></description>
				<content:encoded><![CDATA[<p>So, after a talk on IRC with @flying_squirrel (<a href="http://kwartzlab.ca/users/darcy-casselman">Darcy</a>), I decided to add a progress indicator to the program.  This indicator would tell me what estimated percentage of the total number of permutations the program had exhausted and display this information in increments of 1%.  As it turns out, this wasn&#8217;t very helpful.  Let me explain:<br />
<span id="more-293"></span><br />
Starting from the upper left hand corner (0, 0) the smallest board on which a path can be found has dimensions of 5&#215;5.  A path is found after exhausting somewhere between 1-2% of the possible permutations.  As I mentioned in my previous blog entry, my computer essentially calculates this instantly.</p>
<p>If we increase the size of the board to 6&#215;6, we don&#8217;t even use up 1% of the possible permutations and the result is still calculated in an imperceptibly small amount of time.</p>
<p>By the time we increase to 7&#215;7, we&#8217;re still using less than 1% (I&#8217;m assuming much less) of the possible permutations, but the result takes a few fractions of a second to calculate.</p>
<p>At 8&#215;8 it gets really interesting.  The gauge still doesn&#8217;t register (as expected) but I let the program run for about a minute or so with no result.</p>
<p>This would seem to indicate that as the size of the board increases, the percentage of permutations that we need to exhaust decreases (I&#8217;m assuming exponentially) but the amount of time needed increases (also exponentially&#8230; which I kind of expected).</p>
<p>From this we can extrapolate that at a size of 10&#215;10, I will probably die before the program reaches a conclusion.  If there&#8217;s a better way of calculating this it&#8217;ll either involve a radical optimization of the existing program or (more likely) writing a new one from scratch.</p>
<p>Once again, here&#8217;s my <a href="http://github.com/jlamothe/pathfinder/tree/v1.1">code</a> and <a href="http://www.jlamothe.net/projects/pathfinder/v1.1/">documentation</a>.</p>
<p>As a matter of interest, I left the original program running in the background.  We&#8217;re currently sitting at 18+ hours with (surprise) still no result.</p>
<p><strong>EDIT &#8211; 13 Feb 2011:</strong><br />
The source code and documentation were lost.  I found the source cached on Google (it&#8217;s now hosted at <a href="http://github.com">GitHub</a>) and regenerated the documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kwartzlab.ca/2010/02/chess-pathfinder-11/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
