<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Gumbo Labs</title>
	
	<link>http://www.gumbolabs.org</link>
	<description>A New Orleans Artist / Inventor / Technologist Collective (a.k.a. a hacker space)</description>
	<lastBuildDate>Thu, 04 Mar 2010 06:21:51 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/GumboLabs" /><feedburner:info uri="gumbolabs" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>DSO nano and synth circuit</title>
		<link>http://feedproxy.google.com/~r/GumboLabs/~3/ZqP5zMR5uAc/</link>
		<comments>http://www.gumbolabs.org/2010/03/03/dso-nano-and-synth-circuit/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 03:09:57 +0000</pubDate>
		<dc:creator>Benjamin Eckel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.gumbolabs.org/?p=349</guid>
		<description><![CDATA[A few days ago, a co-worker let me borrow his DSO nano to run a few tests. First thing I decided to do was throw a really chaotic waveform at it. I built this little synth with 2 square wave oscillators.


It is kind of comical to call this a synth or even a set of [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, a co-worker let me borrow his <a href="http://www.seeedstudio.com/depot/micro-digital-storage-oscilloscopedso-nano-p-512.html">DSO nano</a> to run a few tests. First thing I decided to do was throw a really chaotic waveform at it. I built this little synth with 2 square wave oscillators.</p>
<p><a href="http://www.gumbolabs.org/cms/wp-content/downloads/2010/03/2010-03-03-20.37.24.jpg"><br />
<img src="http://www.gumbolabs.org/cms/wp-content/downloads/2010/03/2010-03-03-20.37.24-300x225.jpg" alt="Square wave oscillator schematic" title="Square wave oscillator schematic" width="300" height="225" class="aligncenter size-medium wp-image-350" /></a></p>
<p>It is kind of comical to call this a synth or even a set of oscillators. It is basically a simple NOT gate arranged in a feedback loop. The capacitor fills up until it reaches the breakdown voltage of the internal diode in the NOT gate, at that point, the signal is inverted to GND and the capacitor discharges. When it reaches ground, the output signal inverts again and the process starts over. The result is a square wave. The potentiometer controls the amount of current flowing into the capacitor and thus alters the amount of time it takes to fill up. In effect, altering the frequency of the square wave. I built two of these and muxed the signals together with some resistors, kind of like a fixed mixer. The overall signal is pretty hectic, with weird beat frequencies and strange tiny oscillations in the individual frequencies themselves.</p>
<p><object width="480" height="393"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9900653&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=A90000&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=9900653&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=A90000&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="480" height="393"></embed></object></p>
<p>I found it pretty hard to get the DSO nano to get a good read on it but it was pretty hard with my regular scope as well. Probably not the best waveform to start with. So, I decided to try out some simpler waveforms. I programmed an Arduino to just spit out &#8216;a&#8217; on the UART every second and used a rising slope trigger to freeze the waveform. It worked really well for that. It also worked really well for just a square wave generated on the Arduino. It was able to guess the frequency with accuracy. Unfortunately my phone had died at that point and I couldn&#8217;t get any pictures or video.</p>
<p>Overall I found it pretty simple to use and a surprising amount of functionality for it&#8217;s small size and price. I have to admit though, I wouldn&#8217;t find much use for it as I am almost always in front of a desk where I can use my USB scope and software. I think this would be more helpful for someone who works in &#8216;the field&#8217; so to speak. It is pretty much as good as you are going to get in a pocket-sized package.</p>
<img src="http://feeds.feedburner.com/~r/GumboLabs/~4/ZqP5zMR5uAc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.gumbolabs.org/2010/03/03/dso-nano-and-synth-circuit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.gumbolabs.org/2010/03/03/dso-nano-and-synth-circuit/</feedburner:origLink></item>
		<item>
		<title>RFID  Ethernet Shield Client   Rails</title>
		<link>http://feedproxy.google.com/~r/GumboLabs/~3/EFs_6BKjcqI/</link>
		<comments>http://www.gumbolabs.org/2010/02/05/rfid-ethernet-shield-client-rails/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 04:10:27 +0000</pubDate>
		<dc:creator>Benjamin Eckel</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Tutorial/Documentation]]></category>
		<category><![CDATA[ethernet shield]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.gumbolabs.org/?p=173</guid>
		<description><![CDATA[Last week A few months ago, I wrote an article on connecting the Parallax RFID reader to the the Arduino. The reason I was revisiting that device was because I am working on a system for our hackerspace which will allow people to find out who is in the hackerspace at any given time. The [...]]]></description>
			<content:encoded><![CDATA[<p><del>Last week</del> A few months ago, I wrote an article on connecting the <a href="http://www.gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/" target="_blank">Parallax RFID reader to the the Arduino</a>. The reason I was revisiting that device was because I am working on a system for our hackerspace which will allow people to find out who is in the hackerspace at any given time. The overall system requires the Arduino to connect to the internet as a client and tell the <a href="http://rubyonrails.org/" target="_blank">Ruby on Rails</a> application that person with RFID tag XXXXXXXXXX has walked into or left the space. The Rails application will be able to &#8216;publish&#8217; this information to different mediums [web, twitter, facebook, IRC, etc] by providing a simple API for other programmers in the space to utilize.</p>
<p>The whole system is too complicated to explain right now and I am not finished. I plan on writing my next article about that. For now, I just wanted to document some of the issues I had with the <a href="http://www.arduino.cc/en/Main/ArduinoEthernetShield" target="_blank">Arduino Ethernet Shield</a> and how I resolved them as it may be of help to others trying to figure it out.</p>
<div id="attachment_175" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.gumbolabs.org/cms/wp-content/downloads/2009/10/ArduinoWithEthernetShield.jpg" target="_blank"><img class="size-medium wp-image-175" title="ArduinoWithEthernetShield" src="http://www.gumbolabs.org/cms/wp-content/downloads/2009/10/ArduinoWithEthernetShield-300x195.jpg" alt="Arduino Ethernet Shield" width="300" height="195" /></a><p class="wp-caption-text">Arduino Ethernet Shield</p></div>
<p>The ethernet shield, like the RFID reader, was not as simple to use as I hoped it would be. The information out there was decent, but nothing beyond explaining the examples. First I must explain my use cases to put context to the example code.</p>
<p>My goals for the code are to first send two pieces of information to the Rails application:</p>
<ol>
<li>A secret API key [to prevent fraud]</li>
<li>The Tag code read by the RFID reader</li>
</ol>
<p>Then I want to read the response and differentiate between four situations:</p>
<ol>
<li>The user has been marked as &#8220;Logged In&#8221;</li>
<li>The user has been marked as &#8220;Logged Out&#8221;</li>
<li>There is no user with the tag code that was sent</li>
<li>The wrong API key was supplied</li>
</ol>
<p>The ethernet shield allows your Arduino to operate as a Client or a Server. In this situation, I just want to use the client interface as I am connecting to a server to get information. Now let&#8217;s just look at the code required to make a simple HTTP GET request client with no parameters. I just modified this from the examples.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;Ethernet.h&gt; // load ethernet SPI functions</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// a MAC address that you make up to identify the Arduino</span>
byte mac<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #208080;">0xDE</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xAD</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xBE</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xEF</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xFE</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xED</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// this is the IP that will identify the Arduino</span>
byte ip<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">192</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">168</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">160</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// this is the IP of the server that we are trying to connect to</span>
byte server<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">192</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">168</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">101</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//create the client</span>
<span style="color: #666666; font-style: italic;">//wide area HTTP networks are on port 80 but my local rails app is on 3000</span>
Client client<span style="color: #009900;">&#40;</span>server<span style="color: #339933;">,</span> <span style="color: #0000dd;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">//start ethernet</span>
  Ethernet.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span>mac<span style="color: #339933;">,</span> ip<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;connecting...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #202020;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;connected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//this constructs the GET request, it is the equivalent</span>
    <span style="color: #666666; font-style: italic;">//going to the browser and entering http://192.168.0.101:3000/main/index</span>
    client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GET /main/rfid HTTP/1.1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// print a newline char to tell the server we are done?</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// this is called if conenction fails</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;connection failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// need to see if response has been read into the buffer yet</span>
    <span style="color: #993333;">char</span> c <span style="color: #339933;">=</span> client.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//get next character and print it</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>client.<span style="color: #202020;">connected</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//if we lose connection</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;disconnecting.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    client.<span style="color: #202020;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// disconnects from the server</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">;;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Some of this warrants a little more explanation for some&#8230; </p>
<h2>Configuring the ethernet shield</h2>
<p>First is the MAC address.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">byte mac<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #208080;">0xDE</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xAD</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xBE</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xEF</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xFE</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xED</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>For those unfamiliar with basic networks, a <a href="http://en.wikipedia.org/wiki/MAC_address" target="_blank">MAC address</a> is a unique number assigned to your network card that never changes. You don&#8217;t need to know much about it other than you need to make it up. You should be good if you use the one I have just used in this example but keep in mind that if you have multiple Arduinos connected to the same network, you may need to make up unique MAC addresses for each one.</p>
<p>Next is your IP.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">byte ip<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">192</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">168</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">160</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This array refers to the IP that you want your Arduino to take. The Arduino Ethernet Shield currently ?doesn&#8217;t support <a href="http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol" target="_blank">DHCP</a>?, so you have to choose an unused IP yourself. There are a variety of ways and steps to do this. First what you need to do is figure out what the first three bytes in this array need to be. This is determined by the local router you are connecting to. For instance, Linksys is usually 192.168.1.XXX and D-Link, in my case, is usually 192.168.0.XXX. You can find out what your situation is by checking the IP of a computer on that network. Then you need to choose an unused number for the last byte, usually between 100 and 255. If you are on a network with few computers, around 150 is usually a safe bet. If you are not sure or have a lot of computers on the network, you should find a way to log into your router&#8217;s admin interface and check the DHCP information. It will tell you all the IP addresses that are currently assigned and you can make one up an unused one based off that.</p>
<p>Last is the server&#8217;s IP.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">byte server<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">192</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">168</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">101</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is the IP of the server that you are trying to connect to. In my case, it is a laptop running my Rails application connected to the same network. If you want to connect to a server outside your network, on the internet, you need to find it&#8217;s IP. Your computer usually does this under the surface using <a href="http://en.wikipedia.org/wiki/Domain_Name_System" target="_blank">DNS</a> but you will have to do it manually here. One way you can do this is by <a href="http://en.wikipedia.org/wiki/Ping" target="_blank">pinging</a> the domain name and seeing what IP it resolves to.</p>
<h2>Sending information to a server</h2>
<p>So, this example works out for many situations, but how can I send information to the server where my Rails app is being run? In my case, I need to send the API key and and the RFID tag I just read. What we need to do is build a <a href="http://en.wikipedia.org/wiki/Query_string" target="_blank">query string</a>. If you aren&#8217;t sure what that means, you will have to read that wikipedia article carefully. Let&#8217;s reexamine the code:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//I changed this line</span>
client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GET /main/rfid HTTP/1.1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//to this line</span>
client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GET /main/rfid?apikey=123&amp;tag=0123456789 HTTP/1.1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>When I run this code, I see this on the serial port:</p>
<blockquote><p>
connecting&#8230;<br />
connected<br />
HTTP/1.1 200 OK<br />
Connection: close<br />
Date: Mon, 26 Oct 2009 01:12:43 GMT<br />
ETag: &#8220;8da44df37e592a5020e852d50fc31a64&#8243;<br />
X-Runtime: 8<br />
Cache-Control: private, max-age=0, must-revalidate<br />
Content-Type: text/html; charset=utf-8<br />
Content-Length: 8</p>
<p>^=NOUSER
</p></blockquote>
<p>This is the HTTP response. The last bit:</p>
<blockquote><p>
^=NOUSER
</p></blockquote>
<p>Is what I have defined in the Rails application to tell the Arduino what has happened. Just for clarification, this is what the rfid function looks like in the Rails app:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;">#login via rfid service, has no view</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> rfid    
    <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:apikey</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#ff6633; font-weight:bold;">$api_key</span>
      <span style="color:#0066ff; font-weight:bold;">@user</span> = User.<span style="color:#9900CC;">find_by_rfid_tag</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:tag</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@user</span>
        <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">in_space</span> = !@user.<span style="color:#9900CC;">in_space</span>
        <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">save</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">in_space</span>
          render <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;^=IN&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">else</span>
          render <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;^=OUT&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        render <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;^=NOUSER&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span> 
    <span style="color:#9966CC; font-weight:bold;">else</span>
      render <span style="color:#ff3333; font-weight:bold;">:text</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;^=KEYFAILED&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>I tested a few different query strings and made sure it worked for all conditions and it did. Now I need a way to dynamically send the tag that we read from the reader. As you might have read in <a href="http://www.gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/" target="_blank">my RFID post</a>, I am storing the RFID tag in a 10 character array:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define CODE_LEN 10</span>
&nbsp;
<span style="color: #993333;">char</span> tag<span style="color: #009900;">&#91;</span>CODE_LEN<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I initially thought I could do this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">client.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GET /main/rfid?apikey=123&amp;tag=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
client.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; HTTP/1.1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Notice that I am using a series of print()s to build a string and ending it with println() to close it out with a newline. The only problem is that this doesn&#8217;t work. My Mongrel server (the Rails server) was telling me that my HTTP request were invalid. It seems like a lot of other people were running into this problem as well. After temporarily giving up, I realized the problem. I was reading <a href="http://oreilly.com/catalog/9780596510046" target="_blank">an essay by Brian Kernighan</a>, one of the creators of the C programming language, about a simple regular expression parser that he uses to teach students about programming methodologies. Scanning through the code, I was reminded that a character array cannot be interpreted as a string without a terminal null character &#8216;\0&#8242; as the last element. So, I handled this situation like this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define CODE_LEN 10</span>
&nbsp;
<span style="color: #993333;">char</span> tag<span style="color: #009900;">&#91;</span>CODE_LEN <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
tag<span style="color: #009900;">&#91;</span>CODE_LEN<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span></pre></div></div>

<p>This didn&#8217;t affect any of my other code and now the tag array can be interpreted as a legit string <img src='http://www.gumbolabs.org/cms/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I love simple solutions. </p>
<p>Now I need a way to parse the response. The reason my responses had this format &#8216;^=XXXXXXX&#8217; was so I could do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Finds result that we are looking for in the returned HTTP response
 */</span>
<span style="color: #993333;">char</span> getHTTPResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #ff0000;">'^'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'='</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> client.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">'x'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This would return the first character for the response I am looking for. For example, with the NOUSER message, I would get back the &#8216;N&#8217; character. I implemented this but the problem is that it was really slow. Or at least, it was a lot slower than it could be. The problem is the amount of pointless HTTP data you have to read before you get to the actual message, or it could be that I am printing all that data? Doesn&#8217;t matter because I can make it faster.  I could have configured my server to not spit out so much junk, or I could just place the message earlier in the response. </p>
<h2>Reverse REST</h2>
<p>The first thing you return is the status code so why not put it there? As I said before, there are only four states I am trying to identify and there are <a href="http://www.w3.org/Protocols/HTTP/HTRESP.html" target="_blank">plenty</a> of HTTP status codes to represent them. So I modified the Rails controller to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
  <span style="color:#008000; font-style:italic;">#login via rfid service, has no view</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> rfid    
    <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:apikey</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#ff6633; font-weight:bold;">$api_key</span>
      <span style="color:#0066ff; font-weight:bold;">@user</span> = User.<span style="color:#9900CC;">find_by_rfid_tag</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:tag</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@user</span>
        <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">in_space</span> = !@user.<span style="color:#9900CC;">in_space</span>
        <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">save</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@user</span>.<span style="color:#9900CC;">in_space</span>
          render <span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">400</span> <span style="color:#008000; font-style:italic;">#IN</span>
        <span style="color:#9966CC; font-weight:bold;">else</span>
          render <span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">401</span> <span style="color:#008000; font-style:italic;">#OUT</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        render <span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">402</span> <span style="color:#008000; font-style:italic;">#NOUSER</span>
      <span style="color:#9966CC; font-weight:bold;">end</span> 
    <span style="color:#9966CC; font-weight:bold;">else</span>
      render <span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">403</span> <span style="color:#008000; font-style:italic;">#FAILED</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>I can&#8217;t help but wanting to call this &#8216;reverse REST&#8217;, LOL. Rerunning my simple &#8220;no user&#8221; test, I now get this:</p>
<blockquote><p>
HTTP/1.1 402 Payment Required<br />
Connection: close<br />
Date: Sat, 06 Feb 2010 02:45:19 GMT<br />
X-Runtime: 12<br />
Content-Type: text/html; charset=utf-8<br />
Cache-Control: no-cache<br />
Content-Length: 0</p>
</blockquote>
<p>This is much quicker to parse. I probably could have used some nice code to make this more flexible, but just hardcoding the digit read process in is probably easier and just as reliable, if not more efficient:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> getHTTPResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #ff0000;">'4'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'0'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//just to make sure</span>
    <span style="color: #b1b100;">return</span> client.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// return either '0' or '1' or '2' or '3'</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">'x'</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// something bad happened</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>At this point a simple switch allows us to define the behavior of the response:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> sendToServer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   client.<span style="color: #202020;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//just to be sure</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #202020;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      client.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GET /main/rfid?apikey=123&amp;tag=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      client.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; HTTP/1.0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      client.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>getHTTPResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'0'</span><span style="color: #339933;">:</span>
           Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;logged in&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'1'</span><span style="color: #339933;">:</span>
           Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;logged out&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>   
        <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'2'</span><span style="color: #339933;">:</span>
           Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;no user&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> 
        <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'3'</span><span style="color: #339933;">:</span>
           Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;API key failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>    
        <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
          Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;broke&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      client.<span style="color: #202020;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//just to be sure, probably not needed here</span>
      client.<span style="color: #202020;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//should stop it</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;connection failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>A few more troubleshooting tips (will keep updated as they come in)</h2>
<ol>
<li>Be sure to use <a href="http://arduino.cc/en/Reference/ClientFlush">flush()</a> when appropriate. This ensures that your input buffer is clean and that you don&#8217;t have any left over remnants.</li>
<li>I noticed that sometimes the ethernet shield would not power up when I plugged in my Arduino. You can tell by the group of lights on the top. I could only get it to start up when I had unplugged anything that was leaching power from my board (in my case the RFID reader which is leaching current off the 5V pin). I am not 100% sure why this is but my guess is that it has something to do with some components on the ethernet shield not getting enough current to start it up. If this happens to you, you will often find that client.connect() will return false every time. I will try to investigate this further.</li>
</ol>
<h2>Conclusion</h2>
<p>Hopefully this isn&#8217;t too far out of context for your applications. Feel free to post questions about this device and I will try to help out.</p>
<img src="http://feeds.feedburner.com/~r/GumboLabs/~4/EFs_6BKjcqI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.gumbolabs.org/2010/02/05/rfid-ethernet-shield-client-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.gumbolabs.org/2010/02/05/rfid-ethernet-shield-client-rails/</feedburner:origLink></item>
		<item>
		<title>Agenda For Our First Official Board Meeting</title>
		<link>http://feedproxy.google.com/~r/GumboLabs/~3/BK8STwdrS4E/</link>
		<comments>http://www.gumbolabs.org/2010/01/19/agenda-for-our-first-official-board-meeting/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 21:54:30 +0000</pubDate>
		<dc:creator>Simon Dorfman</dc:creator>
				<category><![CDATA[Board of Directors]]></category>

		<guid isPermaLink="false">http://www.gumbolabs.org/?p=229</guid>
		<description><![CDATA[Gumbo Labs, Inc.  Board Meeting
4820 Banks Street, Studio  #5, New Orleans, LA 70119
Jan 19, 2010, 7:30-9:00PM
Call Meeting to Order
Membership Business

Review Applications
Confirm Membership

Board Business

Confer Incorporators as    Officers
Elect Board of Directors
Discuss Board Waiver
Adopt Bylaws
Authorize Treasurer’s    Duties
Elect Officers
Authorize Officers’ Duties
Discuss Indemnification
Discuss Officer Reimbursements
Select Agent for the Corporation

Adjourn Meeting
]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><span style="font-family: Verdana; font-size: medium;"><strong>Gumbo Labs, Inc.  Board Meeting</strong></span></p>
<p style="text-align: left;"><span style="font-family: Verdana; font-size: small;">4820 Banks Street, Studio  #5, New Orleans, LA 70119</span></p>
<p><span style="font-family: Verdana; font-size: small;">Jan 19, 2010, 7:30-9:00PM</span></p>
<blockquote><p><span style="font-family: Verdana; font-size: small;">Call Meeting to Order</span></p>
<p><span style="font-family: Verdana; font-size: small;">Membership Business</span></p>
<ol type="1">
<li><span style="font-family: Verdana; font-size: small;">Review Applications</span></li>
<li><span style="font-family: Verdana; font-size: small;">Confirm Membership</span></li>
</ol>
<p><span style="font-family: Verdana; font-size: small;">Board Business</span></p>
<ol type="1">
<li><span style="font-family: Verdana; font-size: small;">Confer Incorporators as    Officers</span></li>
<li><span style="font-family: Verdana; font-size: small;">Elect Board of Directors</span></li>
<li><span style="font-family: Verdana; font-size: small;">Discuss Board Waiver</span></li>
<li><span style="font-family: Verdana; font-size: small;">Adopt Bylaws</span></li>
<li><span style="font-family: Verdana; font-size: small;">Authorize Treasurer’s    Duties</span></li>
<li><span style="font-family: Verdana; font-size: small;">Elect Officers</span></li>
<li><span style="font-family: Verdana; font-size: small;">Authorize Officers’ Duties</span></li>
<li><span style="font-family: Verdana; font-size: small;">Discuss Indemnification</span></li>
<li><span style="font-family: Verdana; font-size: small;">Discuss Officer Reimbursements</span></li>
<li><span style="font-family: Verdana; font-size: small;">Select Agent for the Corporation</span></li>
</ol>
<p><span style="font-family: Verdana; font-size: small;">Adjourn Meeting</span></p></blockquote>
<img src="http://feeds.feedburner.com/~r/GumboLabs/~4/BK8STwdrS4E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.gumbolabs.org/2010/01/19/agenda-for-our-first-official-board-meeting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.gumbolabs.org/2010/01/19/agenda-for-our-first-official-board-meeting/</feedburner:origLink></item>
		<item>
		<title>Simon Dorfman’s Pecha Kucha Presentation about Gumbo Labs Video</title>
		<link>http://feedproxy.google.com/~r/GumboLabs/~3/BQwfCEIV1_8/</link>
		<comments>http://www.gumbolabs.org/2009/11/11/simon-dorfmans-pecha-kucha-presentation-about-gumbo-labs-video/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 15:10:45 +0000</pubDate>
		<dc:creator>Simon Dorfman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.gumbolabs.org/?p=201</guid>
		<description><![CDATA[
Above video also viewable on vimeo. And the slides from this presentation were posted here.
I&#8217;ll try to update this post later with a summary and some links from the slides.
]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=7548581&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="300" src="http://vimeo.com/moogaloop.swf?clip_id=7548581&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Above video also <a href="http://vimeo.com/7548581">viewable on vimeo</a>. And the slides from this presentation were <a href="http://www.gumbolabs.org/2009/10/30/slides-from-my-gumbo-labs-presentation-at-pecha-kucha-last-night/">posted here</a>.</p>
<p>I&#8217;ll try to update this post later with a summary and some links from the slides.</p>
<img src="http://feeds.feedburner.com/~r/GumboLabs/~4/BQwfCEIV1_8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.gumbolabs.org/2009/11/11/simon-dorfmans-pecha-kucha-presentation-about-gumbo-labs-video/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.gumbolabs.org/2009/11/11/simon-dorfmans-pecha-kucha-presentation-about-gumbo-labs-video/</feedburner:origLink></item>
		<item>
		<title>Tuesday Night Meeting 7:30 – 9:00</title>
		<link>http://feedproxy.google.com/~r/GumboLabs/~3/ksxQl1tzGHo/</link>
		<comments>http://www.gumbolabs.org/2009/11/11/tuesday-night-meeting-730-900/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 14:39:16 +0000</pubDate>
		<dc:creator>Tuesday Meeting Reminder Robot</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.gumbolabs.org/2009/11/11/tuesday-night-meeting-730-900/</guid>
		<description><![CDATA[Is there anything in particular you&#8217;d like people to bring or prepare for this Tuesday&#8217;s meeting? Leave a comment. Otherwise it will be the usual hanging out, socializing, working on stuff together, what-have-you&#8230;
]]></description>
			<content:encoded><![CDATA[<p>Is there anything in particular you&#8217;d like people to bring or prepare for this Tuesday&#8217;s meeting? Leave a comment. Otherwise it will be the usual hanging out, socializing, working on stuff together, what-have-you&#8230;</p>
<img src="http://feeds.feedburner.com/~r/GumboLabs/~4/ksxQl1tzGHo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.gumbolabs.org/2009/11/11/tuesday-night-meeting-730-900/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.gumbolabs.org/2009/11/11/tuesday-night-meeting-730-900/</feedburner:origLink></item>
		<item>
		<title>Slides from My Gumbo Labs Presentation at Pecha Kucha Last Night</title>
		<link>http://feedproxy.google.com/~r/GumboLabs/~3/pr1cpUzW7S4/</link>
		<comments>http://www.gumbolabs.org/2009/10/30/slides-from-my-gumbo-labs-presentation-at-pecha-kucha-last-night/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 13:46:50 +0000</pubDate>
		<dc:creator>Simon Dorfman</dc:creator>
				<category><![CDATA[Presentation]]></category>

		<guid isPermaLink="false">http://www.gumbolabs.org/?p=197</guid>
		<description><![CDATA[Gumbo Labs Presentation at Pecha Kucha
View more presentations from Gumbo Labs Inc..

]]></description>
			<content:encoded><![CDATA[<div id="__ss_2383928" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Gumbo Labs Presentation at Pecha Kucha" href="http://www.slideshare.net/GumboLabs/gumbo-labs-presentation-at-pecha-kucha">Gumbo Labs Presentation at Pecha Kucha</a><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dorfman-091030084019-phpapp01&amp;rel=0&amp;stripped_title=gumbo-labs-presentation-at-pecha-kucha" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dorfman-091030084019-phpapp01&amp;rel=0&amp;stripped_title=gumbo-labs-presentation-at-pecha-kucha" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/GumboLabs">Gumbo Labs Inc.</a>.</div>
</div>
<img src="http://feeds.feedburner.com/~r/GumboLabs/~4/pr1cpUzW7S4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.gumbolabs.org/2009/10/30/slides-from-my-gumbo-labs-presentation-at-pecha-kucha-last-night/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.gumbolabs.org/2009/10/30/slides-from-my-gumbo-labs-presentation-at-pecha-kucha-last-night/</feedburner:origLink></item>
		<item>
		<title>Parallax RFID Reader  Arduino</title>
		<link>http://feedproxy.google.com/~r/GumboLabs/~3/03FSUC3E0EI/</link>
		<comments>http://www.gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 08:01:36 +0000</pubDate>
		<dc:creator>Benjamin Eckel</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Tutorial/Documentation]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[rfid]]></category>

		<guid isPermaLink="false">http://www.gumbolabs.org/?p=76</guid>
		<description><![CDATA[A while back, I purchased a Parallax RFID reader and used it for authentication for my house door. It was kind of a hack job and wasn&#8217;t as stable as I would have liked so I never documented it and put it on the backburner. I recently decided to revisit the device for a project [...]]]></description>
			<content:encoded><![CDATA[<p>A while back, I purchased a Parallax <a href="http://en.wikipedia.org/wiki/Radio-frequency_identification">RFID reader</a> and used it for authentication for my house door. It was kind of a hack job and wasn&#8217;t as stable as I would have liked so I never documented it and put it on the backburner. I recently decided to revisit the device for a project for Gumbo Labs.</p>
<div id="attachment_165" class="wp-caption aligncenter" style="width: 240px"><a href="http://www.gumbolabs.org/cms/wp-content/downloads/2009/10/28140-M.jpg"><img class="size-medium wp-image-165" title="28140-M" src="http://www.gumbolabs.org/cms/wp-content/downloads/2009/10/28140-M-230x300.jpg" alt="The Parallax reader" width="230" height="300" /></a><p class="wp-caption-text">The Parallax reader</p></div>
<p>BTW, you can now <a href="http://www.radioshack.com/product/index.jsp?productId=2906723">get this at your local Radioshack?!?</a>. Maybe they are starting to move in the right direction again? Who knows.</p>
<p>Anyway, this device was initially easy to get running but it was not as stable as I hoped it would be. The example code online did not fully account for the quirks of this reader. I had to closely <a href="http://www.parallax.com/Portals/0/Downloads/docs/prod/audiovis/28140-28340-RFID Reader-v2.1.pdf" target="_self">read the manual</a> to make it work as expected. I am going to briefly describe how to get the best out of this reader and properly integrate it with your Arduino.</p>
<p>First you want to get them connected. The quickest way to do this is with a breadboard and some wires like <a href="http://planaheist.com/2009/05/arduino-rfid-hacking/" target="_blank">this guy</a> does:</p>
<div id="attachment_78" class="wp-caption aligncenter" style="width: 310px"><a href="http://planaheist.com/2009/05/arduino-rfid-hacking/"><img class="size-medium wp-image-78" title="dsc00456" src="http://www.gumbolabs.org/cms/wp-content/downloads/2009/10/dsc00456-300x225.jpg" alt="Connecting Arduino to RFID reader" width="300" height="225" /></a><p class="wp-caption-text">Connecting Arduino to RFID reader</p></div>
<p>The mapping should be similar to this:</p>
<ul>
<li>Arduino serial RX to Parallax TX</li>
<li>Arduino GND to Parallax GND</li>
<li>Arduino digital pin (i.e. #2) to Parallax /ENABLE</li>
<li>Arduino +5V to Parallax Vcc</li>
</ul>
<p>Keep in mind that when you upload your binary to the Arduino, you may need to disconnect the Parallax TX connection, just a warning.</p>
<h2>Now to the Arduino code&#8230;</h2>
<p>I will explain each piece in detail and give the whole code at the end. If you are impatient and hate learning, go there.</p>
<p>First let&#8217;s deal with this /ENABLE pin. Here is what the documentation says about it:</p>
<blockquote><p>The RFID Card Reader is activated via the /ENABLE line. When the RFID Card Reader is powered and the /ENABLE line is pulled HIGH, the module will be inactive (standby mode) and the LED will be GREEN. When the /ENABLE line is pulled LOW, the RFID Card Reader enter its active state and enable the antenna to interrogate for tags. The current consumption of the module will increase dramatically when the module is active.</p></blockquote>
<p>So, when the pin is HIGH, the reader is <em>inactive</em> and in a <em>low current</em> consumption mode. When the pin is LOW, the reader is active and can read tags. To utilize this pin, I created two functions:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define RFID_ENABLE 2  //pin connected to ENABLE</span>
&nbsp;
<span style="color: #993333;">void</span> enableRFID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>RFID_ENABLE<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> disableRFID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>RFID_ENABLE<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The usage of this functionality depends on your application. If you (and by you here I mean the Arduino) know when you will need to read a tag, keep the reader inactive until then to conserve current. This situation is not as likely as you usually want the Arduino to just <em>know</em> when a tag is next to it at any time. In this case, we will use it to briefly deactivate the reader after a tag is read. This will keep the Arduino from getting duplicate or junk/half reads and it will reset the reader for the next tag.</p>
<h2>Reading a Tag&#8217;s Unique ID</h2>
<p>As the documentation describes, when the reader is in active mode and a tag is placed near the antenna, a 12 byte message will come across the Parallax TX serial line. The documentation says this about the serial configuration:</p>
<blockquote><p>All communication is 8 data bits, no parity, 1 stop bit, and least significant bit first (8N1). The baud rate is configured for 2400 bps, a standard communications speed supported by most any microprocessor or PC, and cannot be changed.</p></blockquote>
<p>8N1 is the standard for your Arduino, you just have to tell it to start up the UART at 2400 baud in your setup() function:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The designer of the RFID reader, <a href="http://en.wikipedia.org/wiki/Joe_Grand" target="_blank">KingPin</a> if I am not mistaken, designed a custom protocol so we can determine where the tag starts and ends. Once again, we refer to the documentation (click to get a larger view of the picture):</p>
<div id="attachment_84" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-1.png"><img class="size-medium wp-image-84" title="Picture 1" src="http://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-1-300x27.png" alt="RFID tag message protocol" width="300" height="27" /></a><p class="wp-caption-text">RFID tag message protocol</p></div>
<blockquote><p>The start byte and stop byte are used to easily identify that a correct string has been received from the<br />
reader (they correspond to a line feed and carriage return characters, respectively). The middle ten bytes are the actual tag&#8217;s unique ID.</p></blockquote>
<p>In other words, you should read the incoming serial bytes until you find the start byte [hex 0x0A || decimal 10 || line feed]. You should then read the next 10 bytes as the tag&#8217;s unique ID and hope that the stop byte [hex 0x0D || decimal 13 || carriage return] shows up last. BTW, if you ever need to know something like the hex and decimal values of line feed, <a href="http://www.asciitable.com/" target="_blank">check here</a>.</p>
<p>Now let&#8217;s take a look at the piece of code which reads the tag. I am going to litter it with comments, it looks huge but it is actually pretty concise:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//you need to define these</span>
<span style="color: #339933;">#define CODE_LEN 10          //Max length of RFID code</span>
<span style="color: #339933;">#define START_BYTE 0x0A   //decimal 10 or LINE-FEED</span>
<span style="color: #339933;">#define STOP_BYTE 0x0D     //decimal 13 or CARRIAGE-RETURN</span>
&nbsp;
<span style="color: #993333;">char</span> tag<span style="color: #009900;">&#91;</span>CODE_LEN<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//this is the character where we store the tag</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Blocking function, waits for and gets the RFID tag.
 */</span>
<span style="color: #993333;">void</span> getRFIDTag<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
   * next_byte is temporary storage for every byte we read
   */</span>
  byte next_byte<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
   * this next part blocks the code until we get something in
   * the incoming serial buffer. This is what makes this a
   * &quot;blocking function&quot;. You may want to comment this out
   * if you have stuff to do if a tag is not present.
   */</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
   * if we get here, there is at least one byte in the buffer
   * the next if reads it and checks to see if it is the start_byte
   * if it isn't, we are just moving on.
   */</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>next_byte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> START_BYTE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//bytes_read keeps track of how many bytes into the tag we are</span>
    byte bytes_read <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
&nbsp;
   <span style="color: #808080; font-style: italic;">/**
    * This while loop makes sure we don't read
    * more bytes than we can store in tag array.
    */</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>bytes_read <span style="color: #339933;">&lt;</span> CODE_LEN<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//wait for the next byte</span>
&nbsp;
          <span style="color: #808080; font-style: italic;">/**
           * Here we read the next byte and make sure it
           * is not the STOP byte, if it is, we must break
           */</span>
          <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>next_byte<span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> STOP_BYTE<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>        
&nbsp;
          <span style="color: #808080; font-style: italic;">/**
           * Now we store that byte into the
           * tag at the next position by incrementing
           * bytes_read and storing next_byte at that position
           * in the tag array.
           */</span>
          tag<span style="color: #009900;">&#91;</span>bytes_read<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> next_byte<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Dealing with radio interference</h2>
<p>Let&#8217;s say you implement the getRFIDTag() function like this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  enableRFID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  getRFIDTag<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  disableRFID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  sendCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//wait 3 seconds</span>
  Serial.<span style="color: #202020;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  clearCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Clears out the memory space for the tag to 0s.
 */</span>
<span style="color: #993333;">void</span> clearCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>CODE_LEN<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    tag<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Sends the tag to the computer.
 */</span>
<span style="color: #993333;">void</span> sendCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;TAG:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>CODE_LEN<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So, you have this running and you are using the Arduino&#8217;s serial listener in the IDE, and you notice that every once in a while, you get a random tag for no reason. This kind of bug can be a problem and it is one of the things that made my door authentication device so unstable. I wish I would have RTFM a little closer:</p>
<blockquote><p>The Parallax RFID Card Reader, like many RF devices, may experience RF noise in its frequency range.<br />
This may cause the reader to transmit a spurious tag response when no tag is near the unit. This will not<br />
affect most uses of the RFID Card Reader. To completely prevent spurious responses, it is recommended<br />
to simply read two responses in a row within a given amount of time (e.g. 1 second) to ensure that you<br />
are reading a valid tag and not a “tag” generated by noise.</p></blockquote>
<p>I originally thought I was the lone genius who came up with this solution until I read that paragraph <img src='http://www.gumbolabs.org/cms/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Oh well.</p>
<p>Let&#8217;s look at a way we can implement this idea. I noticed when you hold a tag to the reader, considering you don&#8217;t deactivate after a read, it just continues to spit out the number until you pull the tag away. So, what we need is a function that is called immediately after getRFIDTag() that reads the code again and validates that it is the same. Most of this function is the same as getRFIDTag(), and I hate to break <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY principles</a>, but we are going for simplicity here and I don&#8217;t want this to turn into tutorial on <a href="http://arduino.cc/en/Reference/Pointer">pointers!</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Waits for the next incoming tag to see if it matches
 * the current tag.
 */</span>
boolean isCodeValid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  byte next_byte<span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>next_byte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> START_BYTE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    byte bytes_read <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>bytes_read <span style="color: #339933;">&lt;</span> CODE_LEN<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//wait for the next byte</span>
          <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>next_byte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> STOP_BYTE<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
          <span style="color: #808080; font-style: italic;">/**
           * this is the only part that is really different,
           * if we find one byte that is off, we return false,
           */</span>
          <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#91;</span>bytes_read<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> next_byte<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// if we get here, 'it must be good'</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So, this is all good right? No, not really. If you were able to see a problem with this line:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>you are very perceptive. This will work for real tags but will make things complicated when noise occurs. Consider the believable case in which we get a junk tag from noise every 30 minutes. When we get that junk tag, we will be stuck on that line. One way to get around it is to apply a <em>timeout</em>. Here is a pretty ghetto way to implement that, just change the above line to this [<b>UPDATE, there is a bug with this, see end of page</b>]:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">  <span style="color: #993333;">int</span> count <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//passes when we get a byte</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//wait one millisecond</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>count<span style="color: #339933;">++</span> <span style="color: #339933;">&gt;</span> VALIDATE_LENGTH<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//else check again</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>We define VALIDATE_LENGTH to be the number of milliseconds, roughly, that the isCodeValid() function will wait until it realizes the tag you are asking to validate is just noise.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define VALIDATE_LENGTH 200 //wait 200 ms</span></pre></div></div>

<p>So, now you should be good to go. If you are looking to storing and comparing keys in non-volatile memory, I suggest looking <a href="http://arduino.cc/en/Reference/EEPROM">at the EEPROM library</a>. I already wrote some code to do this so if you are curious let me know in the comments. As promised, here is all the code for this article:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * author Benjamin Eckel
 * date 10-17-2009
 *
 */</span>
<span style="color: #339933;">#define RFID_ENABLE 2   //to RFID ENABLE</span>
<span style="color: #339933;">#define CODE_LEN 10      //Max length of RFID tag</span>
<span style="color: #339933;">#define VALIDATE_TAG 1  //should we validate tag?</span>
<span style="color: #339933;">#define VALIDATE_LENGTH  200 //maximum reads b/w tag read and validate</span>
<span style="color: #339933;">#define ITERATION_LENGTH 2000 //time, in ms, given to the user to move hand away</span>
<span style="color: #339933;">#define START_BYTE 0x0A </span>
<span style="color: #339933;">#define STOP_BYTE 0x0D</span>
&nbsp;
<span style="color: #993333;">char</span> tag<span style="color: #009900;">&#91;</span>CODE_LEN<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
  pinMode<span style="color: #009900;">&#40;</span>RFID_ENABLE<span style="color: #339933;">,</span>OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  enableRFID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  getRFIDTag<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>isCodeValid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    disableRFID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    sendCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span>ITERATION_LENGTH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    disableRFID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Got some noise&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
  <span style="color: #009900;">&#125;</span>
  Serial.<span style="color: #202020;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  clearCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Clears out the memory space for the tag to 0s.
 */</span>
<span style="color: #993333;">void</span> clearCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>CODE_LEN<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    tag<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Sends the tag to the computer.
 */</span>
<span style="color: #993333;">void</span> sendCode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;TAG:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #666666; font-style: italic;">//Serial.println(tag);</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>CODE_LEN<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**************************************************************/</span>
<span style="color: #808080; font-style: italic;">/********************   RFID Functions  ***********************/</span>
<span style="color: #808080; font-style: italic;">/**************************************************************/</span>
&nbsp;
<span style="color: #993333;">void</span> enableRFID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   digitalWrite<span style="color: #009900;">&#40;</span>RFID_ENABLE<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> disableRFID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   digitalWrite<span style="color: #009900;">&#40;</span>RFID_ENABLE<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Blocking function, waits for and gets the RFID tag.
 */</span>
<span style="color: #993333;">void</span> getRFIDTag<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  byte next_byte<span style="color: #339933;">;</span> 
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>next_byte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> START_BYTE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>      
    byte bytesread <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>bytesread <span style="color: #339933;">&lt;</span> CODE_LEN<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//wait for the next byte</span>
          <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>next_byte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> STOP_BYTE<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>       
          tag<span style="color: #009900;">&#91;</span>bytesread<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> next_byte<span style="color: #339933;">;</span>                   
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>                
  <span style="color: #009900;">&#125;</span>    
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * Waits for the next incoming tag to see if it matches
 * the current tag.
 */</span>
boolean isCodeValid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  byte next_byte<span style="color: #339933;">;</span> 
  <span style="color: #993333;">int</span> count <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #666666; font-style: italic;">//there is already a STOP_BYTE in buffer</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//probably not a very pure millisecond</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>count<span style="color: #339933;">++</span> <span style="color: #339933;">&gt;</span> VALIDATE_LENGTH<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//throw away extra STOP_BYTE</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>next_byte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> START_BYTE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
    byte bytes_read <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>bytes_read <span style="color: #339933;">&lt;</span> CODE_LEN<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//wait for the next byte      </span>
          <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>next_byte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> STOP_BYTE<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#91;</span>bytes_read<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> next_byte<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>                     
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>                
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>   
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I have tested this as well as I can. I have yet to catch any noise events &#8216;in the wild&#8217; so to speak, which concerns me [<b>read Updates, lol</b>]. But I have tested each case in the isCodeValid() function. I have caused a false validation by timeout and by differing keys [repetitive noise]. But I have also broken it by causing it to read &#8220;half&#8221; of a key. If it still doesn&#8217;t work for you, get creative, there are many ways around the interference issue.</p>
<p>Please let me know if you find faults or improvements and Enjoy <img src='http://www.gumbolabs.org/cms/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Updates</h2>
<p><i>02/07/2010</i> &#8211; For those of you who have been using this code and still getting some noise, I apologize because I just found a bug with the isCodeValid function. For some reason, I was not getting past the line:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>next_byte <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> START_BYTE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></div>

<p>I ran this code right before that line:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">30</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>And this came on the port:</p>
<blockquote><p>
a1r13<br />
a0r-1<br />
a0r-1<br />
a0r-1<br />
a0r-1<br />
a0r-1<br />
a0r-1<br />
a0r10<br />
a6r48<br />
a10r52<br />
a9r49<br />
a8r54<br />
a9r50<br />
a15r66<br />
a17r69<br />
a16r65<br />
a15r49<br />
a14r54<br />
a13r13<br />
a12r10<br />
a11r48<br />
a10r52<br />
a9r49<br />
a8r54<br />
a7r50<br />
a6r66<br />
a5r69<br />
a4r65<br />
a3r49<br />
a2r54
</p></blockquote>
<p>Now, ignore the line </i>a0r10</i>. It is not a bug, it is just that it takes so long to print to the serial port at 2400 baud. Anyway, what is obvious is that my whole function was breaking b/c the STOP_BYTE (13), was still in the buffer. I tried to do a flush before the function but that didn&#8217;t work for whatever reason. So what I did is change the while loop to this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></div>

<p>and then after the while loop breaks, throw that 13 away:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Sorry this took so long for me to figure out, I was on hiatus, I hope it didn&#8217;t mess anyone up. This change is reflected in the whole piece of code.</p>
<img src="http://feeds.feedburner.com/~r/GumboLabs/~4/03FSUC3E0EI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://www.gumbolabs.org/2009/10/17/parallax-rfid-reader-arduino/</feedburner:origLink></item>
		<item>
		<title>Hacking the Asus WL-520GU w/ OpenWRT</title>
		<link>http://feedproxy.google.com/~r/GumboLabs/~3/ZJzEt__bmoo/</link>
		<comments>http://www.gumbolabs.org/2009/10/08/hacking-the-asus-wl-520gu-w-openwrt/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 03:41:08 +0000</pubDate>
		<dc:creator>Benjamin Eckel</dc:creator>
				<category><![CDATA[Tutorial/Documentation]]></category>
		<category><![CDATA[asus]]></category>
		<category><![CDATA[openwrt]]></category>

		<guid isPermaLink="false">http://www.gumbolabs.org/?p=34</guid>
		<description><![CDATA[I was at a Gumbo Labs meeting recently and one of the members, Mark, showed us the router that he had been working on. He had flashed it with OpenWRT, added an SD card, and a serial GPS module. He used it to collect geospatial network information on the way to the meeting for the [...]]]></description>
			<content:encoded><![CDATA[<p>I was at a <a href="http://gumbolabs.org/">Gumbo Labs</a> meeting recently and one of the members, Mark, showed us the router that he had been working on. He had flashed it with <a href="http://openwrt.org/">OpenWRT</a>, added an SD card, and a serial GPS module. He used it to collect geospatial network information on the way to the meeting for the demonstration. What interested me the most was the expansive abilities of OpenWRT, as well as the relative cheapness of some of the routers that could host it. According to Mark&#8217;s logic, why buy an Arduino when you can spend a little more and have linux, wireless, and a higher level programming language? I still think the Arduino has it&#8217;s place in my life, mostly considering you can go from the Arduino to a real, sell-able, AVR prototype easily and for extremely cheap. For certain situations though, using a hacked router is a great idea. So I decided to do some research and I came across the <a href="http://reviews.cnet.com/routers/asus-wl-520gu-wireless/4505-3319_7-32626772.html">Asus WL-520GU</a>.</p>
<div class="wp-caption aligncenter" style="width: 460px"><a href="http://www.thetrailingedge.com/images/products/ASUS%20WL-520gU.jpg"><img title="Asus pic" src="http://www.thetrailingedge.com/images/products/ASUS%20WL-520gU.jpg" alt="the 520gu" width="450" height="450" /></a><p class="wp-caption-text">the 520gu</p></div>
<p>You can pretty much ignore the specs you see online because they aren&#8217;t really important. Here are the real specs to this device:</p>
<ol>
<li>It is extremely small, can run off 5 Volts, and doesn&#8217;t consume much current. You can easily run it on a battery.</li>
<li>You can easily find builds of OpenWRT for the Broadcom chip found in the Asus. Flashing it is simple. OpenWRT is among the more hackable and useful of the WRT firmwares. You can SSH, telnet, or log in over serial.</li>
<li>Asus left a 3.3V serial port right on the board, just solder in a 4 pin header and you got serial communications. You can log into the board from there or you can have your programs access it and send the info out to the world.</li>
<li>There is a USB port. You can use some cross-compiled linux packages to access that serial port. This opens up a lot of room for creativity. The most important thing about it is that it gives you more space to store cool stuff, like a python interpreter!</li>
<li>That leads us to the thing I was most excited about, you can run python scripts on the router. And you can use pySerial to access the serial port!</li>
</ol>
<p>So, how do we go about hacking this? Well, there are a few initial steps. I figured all of this out by reading these two articles</p>
<ul>
<li><a href="# http://lizard43.blogspot.com/2009/03/tweet-we-using-asus-wl-520gu-and-xbee.html" target="_blank">http://lizard43.blogspot.com/2009/03/tweet-we-using-asus-wl-520gu-and-xbee.html</a></li>
<li><a href="# http://www.mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/" target="_blank">http://www.mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/</a></li>
</ul>
<p>but I am going to go through all the steps here so I can clarify some things. You should read those and then reference them when I am not making sense. I copied a lot verbatim.</p>
<p>First off, we must take apart the router.</p>
<div id="attachment_37" class="wp-caption aligncenter" style="width: 310px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/12532330921211.jpg"><img class="size-medium wp-image-37" title="Casing" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/12532330921211-300x225.jpg" alt="Taking off the casing" width="300" height="225" /></a><p class="wp-caption-text">Taking off the casing</p></div>
<p>BTW, sorry for the crummy pics, I had to use my phone. Anyway, to take this thing off, unscrew the two visible screws then flip out the corner of the rubber feet on the top-left and bottom-right. There are two hidden screws there. After we remove the casing, you can pull out the board.</p>
<div id="attachment_38" class="wp-caption aligncenter" style="width: 310px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253233393828.jpg"><img class="size-medium wp-image-38" title="Exposed router" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253233393828-300x225.jpg" alt="After the case is removed" width="300" height="225" /></a><p class="wp-caption-text">After the case is removed</p></div>
<p>Now we need to locate the convenient 3.3V serial port that the Asus designers left on the board. It is pretty easy to spot. It is this empty space for a 4 pin jumper. The pin-outs from top to bottom in this picture are <strong>3.3V &#8211; RX &#8211; TX &#8211; GND</strong>.</p>
<div id="attachment_39" class="wp-caption aligncenter" style="width: 310px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253233414369.jpg"><img class="size-medium wp-image-39" title="Serial Port" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253233414369-300x225.jpg" alt="3.3V serial port left by asus designers" width="300" height="225" /></a><p class="wp-caption-text">3.3V serial port left by asus designers</p></div>
<p>Now you need to desolder this port so you can get access to it. I found this more difficult than it usually is. To keep you from going through the same, I recommend the following steps:</p>
<ol>
<li>Desolder from the bottom of the board. There are some delicate traces on the top and you don&#8217;t want to cause a short.</li>
<li>You may need to use a little solder to get the old solder to flow.</li>
<li>Don&#8217;t heat the board too long, you could damage nearby components or traces.</li>
<li>Use some good wick, not a sucker. This is one of the few times I will recommend you head over to Radio Shack. Their solder wick is great! Unfortunately, I used this bulk Chinese crap.</li>
</ol>
<div id="attachment_40" class="wp-caption aligncenter" style="width: 310px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253233555004.jpg"><img class="size-medium wp-image-40" title="Solder wick" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253233555004-300x225.jpg" alt="Cheap ass thin wick" width="300" height="225" /></a><p class="wp-caption-text">Cheap ass thin wick</p></div>
<p>Here is what happens when you use bad wick:</p>
<div id="attachment_41" class="wp-caption aligncenter" style="width: 310px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253235251444.jpg"><img class="size-medium wp-image-41" title="Desoldered port" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253235251444-300x225.jpg" alt="Desoldered port" width="300" height="225" /></a><p class="wp-caption-text">Desoldered port</p></div>
<p>Not the worst desoldering ever done, I have heard of people bricking routers this way, but certainly not as clean and easy as it should have been.</p>
<p>Next we need to connect this to our computer. Since this is just basically a serial port, you can use a variety of old hardware. Just remember, this doesn&#8217;t follow the standard RS-232 specification of 12 Volts! It is only 3.3. Most people have used the <a href="http://www.ftdichip.com/Products/EvaluationKits/TTL-232R-3V3.htm" target="_self">FTDI TTL serial to usb</a> cable for this. I happened to have a few extra FTDI chips lying around for such hacking occasions.</p>
<div id="attachment_42" class="wp-caption aligncenter" style="width: 310px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253236373284.jpg"><img class="size-medium wp-image-42" title="FTDI 232" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253236373284-300x225.jpg" alt="FTDI 232 chip on breakout board from Sparkfun" width="300" height="225" /></a><p class="wp-caption-text">FTDI 232 chip on breakout board from Sparkfun</p></div>
<p>I couldn&#8217;t find any female headers in the lab so I just grabbed a breadboard and some wires. I soldered the wires directly into the board. You normally want to solder on headers but I didn&#8217;t have a need for this at the time b/c once you get OpenWRT on this thing, you can SSH in. The mapping is simple. Cross RX and TX, makes sense if you think about it, and connect grounds to each other. No need to connect the 3.3V on either side.</p>
<div id="attachment_43" class="wp-caption aligncenter" style="width: 310px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253236357264.jpg"><img class="size-medium wp-image-43" title="hacked" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253236357264-300x225.jpg" alt="Serial conection" width="300" height="225" /></a><p class="wp-caption-text">Serial conection</p></div>
<p>Once I plugged it in, I checked to see if the FTDI drivers were working and the port was recognized. You also need to know the unique name of the device. I opened up the terminal and checked my <strong>/dev</strong> folder for descriptors starting with <strong>tty.usb</strong>.</p>
<div id="attachment_44" class="wp-caption aligncenter" style="width: 532px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-7.png"><img class="size-full wp-image-44" title="terminal" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-7.png" alt="searching for serial interface" width="522" height="69" /></a><p class="wp-caption-text">searching for serial interface</p></div>
<p>Now that I know the port is working and where it is, I wanted to see if I could listen in on the Asus firmware as it starts up. I opened up <a href="http://homepage.mac.com/dalverson/zterm/" target="_self">ZTerm</a>, set it to /dev/tty/usbserial-A3000RBH, set the baud rate to 1152oo, and set the protocol to the standard ASCII 8N1 (8 bits, No parity, 1 stop bit). Then I did a hard restart on the router [turning my surge protector off then on], and saw the boot log stream into my ZTerm window.</p>
<div id="attachment_45" class="wp-caption aligncenter" style="width: 619px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-8.png"><img class="size-full wp-image-45" title="ZTerm Asus" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-8.png" alt="ZTerm showing boot of Asus firmware" width="609" height="423" /></a><p class="wp-caption-text">ZTerm showing boot of Asus firmware</p></div>
<p>Now we need to install openWRT. You can build it yourself, but I recommend getting this <a href="http://mightyohm.com/files/kamikaze-2.4/openwrt-brcm-2.4-squashfs.trx" target="_self">pre-built version from mightyOhm</a>. Next you need <a href="http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol" target="_self">tftp</a>. I know OS X has it, not sure about other OSs. After you have all this gathered, you need to configure your LAN network interface to use a static ip and connect directly to your router. We are going to tftp the openWRT firmware over to the router. The process for this is different for all OSs, but you basically need these settings</p>
<ul>
<li>ip: 192.168.1.XXX       #just make up something for XXX that isn&#8217;t used, like 180</li>
<li>subnet mask: 255.255.255.0</li>
<li>router: 192.168.1.1      #this is the default ip of the router</li>
</ul>
<p>After you are set up, connect up an ethernet cable from your computer to LAN port 1 on your router.</p>
<div id="attachment_46" class="wp-caption aligncenter" style="width: 310px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253236941377.jpg"><img class="size-medium wp-image-46" title="Router ethernet" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/1253236941377-300x225.jpg" alt="plugged into LAN 1" width="300" height="225" /></a><p class="wp-caption-text">plugged into LAN 1</p></div>
<p>Unplug your router, hold down the black restore button, and plug back in. After a few seconds, you will see the router trying to read a tftp connection in your ZTerm window. It will be saying</p>
<blockquote><p>Failed.: Timeout occurred</p>
<p>Reading:: TFTP Server.</p></blockquote>
<p>Over and over again. What you need to do is connect to the router over tftp and upload the openwrt firmware you downloaded earlier.</p>
<p>I opened up a terminal and ran these commands. Your process may slightly differ</p>
<blockquote><p>$ cd ~/Downloads/                 #this is where my trx file was<br />
$ tftp<br />
$ trace<br />
$ timeout 1<br />
$ mode binary<br />
$ connect 192.168.1.1<br />
$ put openwrt-brcm-2.4-squashfs.trx</p></blockquote>
<p>Once you run the last command, you should see the router accept and start to upload. Don&#8217;t touch anything at this point!</p>
<div id="attachment_48" class="wp-caption aligncenter" style="width: 635px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-10.png"><img class="size-full wp-image-48" title="TFTP flash" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-10.png" alt="Flashing the router over tftp" width="625" height="419" /></a><p class="wp-caption-text">Flashing the router over tftp</p></div>
<p>Wait for it to say <strong><em>done.  XXXX bytes written</em></strong> as seen above. It may take a few minutes, be patient. After this, you can restart the router and watch ZTerm and if all goes well, hit enter when asked and you should see openWRT start up!</p>
<div id="attachment_50" class="wp-caption aligncenter" style="width: 633px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-11.png"><img class="size-full wp-image-50" title="OpenWRT" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-11.png" alt="openWRT boot" width="623" height="445" /></a><p class="wp-caption-text">openWRT boot</p></div>
<p>OpenWRT comes with <a href="http://www.busybox.net/" target="_self">busybox</a> so you have most of the normal linux commands like ls:</p>
<div id="attachment_51" class="wp-caption aligncenter" style="width: 674px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-12.png"><img class="size-full wp-image-51" title="LS" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-12.png" alt="LS" width="664" height="485" /></a><p class="wp-caption-text">LS</p></div>
<p>Now, we want to set up our network interface. I wanted to turn the wireless router into a wireless client. All we have as a text editor is vi so you may need to brush up on it&#8217;s use.</p>
<p>First we must set up the wireless interface:</p>
<blockquote>
<pre>root@OpenWrt:~# vi /etc/config/wireless</pre>
</blockquote>
<p>edit it to look like this with your own settings:</p>
<blockquote><pre>
config wifi-device  wl0
	option type     broadcom
	option channel  2  # the channel your wireless network is on

	# REMOVE THIS LINE TO ENABLE WIFI:
	# option disabled 1 (comment out or remove this line entirely)

config wifi-iface
	option device   wl0
	option network	lan
	option mode     sta  # configures the router to connect to your network
	option ssid     MyNetwork # the SSID of your network
	option encryption wep  # the encryption mode of your network
	option key	XXXXXXXXXX  # add this line with your WEP key
</blockquote>
</pre>
<p>Then set up DHCP:</p>
<blockquote>
<pre>root@OpenWrt:~# vi /etc/config/network</pre>
</blockquote>
<p>Edit it to look like this commenting out last 2 lines:</p>
<blockquote>
<pre>#### LAN configuration
config interface lan
      option type     bridge
      option ifname   "eth0.0"
      option proto    dhcp
      #option ipaddr   192.168.1.1
      #option netmask  255.255.255.0</pre>
</blockquote>
<p>Check your resolve.conf file:</p>
<blockquote>
<pre>root@OpenWrt:~# cat /etc/resolv.conf</pre>
</blockquote>
<p>It should say this, if not, make it so:</p>
<blockquote>
<pre>nameserver 127.0.0.1</pre>
</blockquote>
<p>Now we can restart the network interface:</p>
<blockquote>
<pre>root@OpenWrt:/# /etc/init.d/network restart</pre>
</blockquote>
<p>And we should be able to ping something!</p>
<div id="attachment_54" class="wp-caption aligncenter" style="width: 634px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-13.png"><img class="size-full wp-image-54" title="Ping" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-13.png" alt="pinging google!" width="624" height="153" /></a><p class="wp-caption-text">pinging google!</p></div>
<p>After this, we now have a functioning linux machine! Not bad for 25 bucks. Now I desoldered the serial port hack job [unplug first], and I can SSH or telnet into the router:</p>
<div id="attachment_55" class="wp-caption aligncenter" style="width: 595px"><a href="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-14.png"><img class="size-full wp-image-55" title="SSH" src="https://www.gumbolabs.org/cms/wp-content/downloads/2009/10/Picture-14.png" alt="SSHing into the asus" width="585" height="447" /></a><p class="wp-caption-text">SSHing into the asus</p></div>
<p>If I remember correctly, the username and password were both <strong>root</strong>.</p>
<p>I have had a few ideas about what to do with this. I think the one I am going with is a home power monitoring system similar to this one :</p>
<p><a href="http://www.picobay.com/projects/2009/01/real-time-web-based-power-charting.html" target="_blank">http://www.picobay.com/projects/2009/01/real-time-web-based-power-charting.html</a></p>
<p>The basic architecture would be AC clamps in my breaker box -&gt; arduino -&gt; serial port on asus -&gt; python script running off usb -&gt; <a href="http://www.pachube.com/" target="_blank">pachube</a> over wireless connection. I originally thought python would be perfect for this, and it probably is, but I ran into some issues getting USB to work. It was a pain in the ass. Then I realized, do I actually need to write a program to get the info from the serial port to the web? Hello no! I got linux to work with, and linux people have been doing this since the beginning of networks. Fortunately, I found <a href="http://arduinolocalwarming.blogspot.com/" target="_blank">this page</a> that had exactly what I was looking for. Here is the bash script he uses:</p>
<blockquote><p>
#!/bin/sh<br />
while [ 1 ]<br />
do<br />
temp=$(grep -m 1 &#8220;temp&#8221; /dev/ttyS0|cut -d &#8220;=&#8221; -f 2)<br />
curl &#8211;request PUT &#8211;header &#8220;X-PachubeApiKey: your-key-here&#8221; &#8211;data &#8220;$temp&#8221; &#8220;http://www.pachube.com/api/1931.csv&#8221;<br />
sleep 300<br />
done
</p></blockquote>
<p>He is basically just listening in on the serial port and parsing the incoming string then piping it to <a href="http://curl.haxx.se/" target="_blank">curl</a> [which can be obtained on the Asus via the package manager opkg]. He is using it for temperature but it can easily be adapted for my purposes.</p>
<p>I am waiting to get an AC clamp in and when I do, I will write a part 2 with the rest of the project.</p>
<img src="http://feeds.feedburner.com/~r/GumboLabs/~4/ZJzEt__bmoo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.gumbolabs.org/2009/10/08/hacking-the-asus-wl-520gu-w-openwrt/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.gumbolabs.org/2009/10/08/hacking-the-asus-wl-520gu-w-openwrt/</feedburner:origLink></item>
		<item>
		<title>Install GnuCash On Mac OS X</title>
		<link>http://feedproxy.google.com/~r/GumboLabs/~3/an6dgZ_SXcc/</link>
		<comments>http://www.gumbolabs.org/2009/09/27/install-gnucash-on-mac-os-x/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 17:06:12 +0000</pubDate>
		<dc:creator>Simon Dorfman</dc:creator>
				<category><![CDATA[Tutorial/Documentation]]></category>

		<guid isPermaLink="false">http://www.gumbolabs.org/cms/?p=5</guid>
		<description><![CDATA[Install
My quick list of commands for getting GnuCash (plus documentation) installed on Mac OS X 10.5.8 (you&#8217;ll need to have MacPorts installed for this):
sudo port install gnucash
sudo port install gnucash-docs
sudo port deactivate mesa
sudo port -v upgrade outdated
sudo port deactivate mesa
You can read all the details about why mesa needs to be deactivated in this thread.
Launch [...]]]></description>
			<content:encoded><![CDATA[<h2>Install</h2>
<p>My quick list of commands for getting GnuCash (plus documentation) installed on Mac OS X 10.5.8 (you&#8217;ll need to have <a title="MacPorts Documentation for GnuCash" href="http://wiki.gnucash.org/wiki/MacOSX/MacPortsDetail">MacPorts installed</a> for this):</p>
<pre style="padding-left: 30px;"><span>sudo port install gnucash</span>
<span>sudo port install gnucash-docs</span>
<span>sudo port deactivate mesa</span>
<span>sudo port -v upgrade outdated</span>
<span>sudo port deactivate mesa</span></pre>
<p>You can read all the details about why mesa needs to be deactivated <a title="Symbol not found: _gll_noop" href="http://www.nabble.com/Symbol-not-found:-_gll_noop-td22241078.html">in this thread</a>.</p>
<h2>Launch App</h2>
<p>I decided to get all fancy and create <a title="Applescript GnuCash Launcher" href="http://www.gumbolabs.org/cms/wp-content/uploads/2009/09/GnuCash_Launcher.zip">an applescript launcher for GnuCash</a> so that I could launch GnuCash with one click.</p>
<p>If you want to do it the old fashioned way, here&#8217;s how:</p>
<p style="padding-left: 30px;">Open X11 and type:</p>
<pre style="padding-left: 30px;"><span>gnucash</span></pre>
<p style="padding-left: 30px;">&#8230;into the xterm command line to launch GnuCash.</p>
<h2>Read the Documentation</h2>
<p>GnuCash Docs don&#8217;t seem to work out of the box, so I suggest bookmarking this local documentation to read in the browser.</p>
<p><a title="GnuCash Documentation" href="file:///opt/local/share/doc/gnucash/index.html">file:///opt/local/share/doc/gnucash/index.html</a></p>
<p>I also amended the <a title="Applescript GnuCash + Documentation Launcher" href="http://www.gumbolabs.org/cms/wp-content/downloads/2009/09/GnuCash_and_Documentation_Launcher.zip">applescript launcher to also open the documentation</a>.</p>
<h2>Fancy Graphic</h2>
<p>I gave the applescript launchers a fancy graphic so you could easily recognize them if you wanted to keep it in your dock. Feel free to download the <a href="http://www.gumbolabs.org/cms/wp-content/downloads/2009/09/GnuCashIconForMac.zip">zip of PSD files</a> and make changes or do whatever you want with it.</p>
<div id="attachment_17" class="wp-caption alignnone" style="width: 522px"><a href="http://www.gumbolabs.org/cms/wp-content/downloads/2009/09/GnuCashIconForMac.zip"><img class="size-full wp-image-17" title="GnuCashIcon512" src="http://www.gumbolabs.org/cms/wp-content/downloads/2009/09/GnuCashIcon512.gif" alt="PSDs and ICNS in ZIP" width="512" height="512" /></a><p class="wp-caption-text">PSDs and ICNS in ZIP</p></div>
<img src="http://feeds.feedburner.com/~r/GumboLabs/~4/an6dgZ_SXcc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.gumbolabs.org/2009/09/27/install-gnucash-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.gumbolabs.org/2009/09/27/install-gnucash-on-mac-os-x/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 5.129 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-03-09 11:18:16 -->
