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

<channel>
	<title>The Mind of Bill Porter</title>
	<atom:link href="http://www.billporter.info/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.billporter.info</link>
	<description>Blog of Projects and Thoughts</description>
	<lastBuildDate>Sun, 29 Aug 2010 18:46:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ready, Set, Oscillate! The Fastest Way to Change Arduino Pins</title>
		<link>http://www.billporter.info/?p=308</link>
		<comments>http://www.billporter.info/?p=308#comments</comments>
		<pubDate>Wed, 18 Aug 2010 18:39:59 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=308</guid>
		<description><![CDATA[
There are many ways to change an output pin. The way we know and love is the famous digitalWrite() function.
But even the Arduino Reference claims that it is not the most efficient. The Arduino functions do a lot of error checking to make sure the pin is configured right and has to map Arduino numbering [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.billporter.info/wp-content/uploads//2010/08/checkered-flag.gif"><img class="alignleft size-thumbnail wp-image-309" title="checkered-flag" src="http://www.billporter.info/wp-content/uploads//2010/08/checkered-flag-150x150.gif" alt="" width="150" height="150" /></a></p>
<p>There are many ways to change an output pin. The way we know and love is the famous digitalWrite() function.</p>
<p>But even the Arduino Reference claims that it is not the most efficient. The Arduino functions do a lot of error checking to make sure the pin is configured right and has to map Arduino numbering to actual IO ports.  All this cost processor cycles, and time.  But how much? This article is not to teach you how to useIO registers, you can read about it on the <a href="http://www.arduino.cc/en/Reference/PortManipulation">Arduino Port Manipulation</a> page. This is to cover exactly how inefficient the Arduino functions are.</p>
<p>I ran some tests to find out. The test platform was a 16Mhz Arduino and a very nice oscilloscope watching one of its output pins. I ran two tests, one setting the pins to know values(on or off), and one that ‘flips’ the pin from its previous state.  My code was inside a never ending for loop, so the result would always be a square wave form that I could measure in frequency.</p>
<p>The estimated CPU cycles is calculated from ½ the waveform period measured divided by the period of 16Mhz, since it takes two write operations to complete a full period in a waveform.  There could be some differences in the machine instructions it takes to set a bit compared to clearing a bit, so this is somewhat rough.</p>
<p>The 3 methods I tested were</p>
<ul>
<li>digitalWrite(pin, LOW);         digitalWrite(pin, HIGH);</li>
<li>CLR(PORTB, 0) ;     SET(PORTB, 0);</li>
<li>PORTB |= _BV(0);                   PORTB &amp;= ~(_BV(0));</li>
</ul>
<p>The macros used:</p>
<p>#define CLR(x,y) (x&amp;=(~(1&lt;&lt;y)))</p>
<p>#define SET(x,y) (x|=(1&lt;&lt;y))</p>
<p>#define _BV(bit) (1 &lt;&lt; (bit))</p>
<p>The results</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/08/first3.jpg"><img class="alignnone size-full wp-image-353" title="first" src="http://www.billporter.info/wp-content/uploads//2010/08/first3.jpg" alt="" width="516" height="108" /></a></p>
<p>As you can see, digitalWrite takes around 56 cycles to complete, while direct Port addressing takes 2 cycles. That&#8217;s a big difference in time for programs that have lot&#8217;s of IO operations!</p>
<p>Next I tested just flipping a pin. By this I mean I just changed the pin state without knowing what the initial state was without testing. The methods of testing</p>
<ul>
<li>digitalWrite(pin, !digitalRead(pin))</li>
<li>PORTB ^= (_BV(0))</li>
<li>sbi(PINB,0)</li>
</ul>
<p>#define sbi(port,bit) (port)|=(1&lt;&lt;(bit))</p>
<p>The results</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/08/second1.jpg"><img class="alignnone size-full wp-image-350" title="second" src="http://www.billporter.info/wp-content/uploads//2010/08/second1.jpg" alt="" width="516" height="123" /></a></p>
<p>Wow, the Arduino method takes a whopping 121 cycles to flip a pin! The sbi() using the PIN register is a neat trick for what usually is a read only register, and is the fastest at only 2 cycles.</p>
<p>So you see, the Arduino functions take much MUCH longer to complete pin operations then using direct port IO. But there is a reason why. Arduino does a lot of error checking, and has to look up pin number mappings to actual Atmega pins. Direct port access is not for the faint of heart, but it can be much faster for when you are ready to take off some of the Arduino training wheels.</p>
<p><em>Credit to Webbot for showing us the PIN register trick.</em></p>
<p><em><a href="http://www.billporter.info/wp-content/uploads//2010/08/2010-08-18-11.27.53.jpg"><img class="alignnone size-full wp-image-347" title="2010-08-18 11.27.53" src="http://www.billporter.info/wp-content/uploads//2010/08/2010-08-18-11.27.53.jpg" alt="" /></a></em></p>
<p><strong>UPDATE: </strong>Well, it seems the attention of my article has made me aware of a<a href="http://code.google.com/p/digitalwritefast/downloads/list"> neat-o library</a> for Arduino that keeps the code simple, but runs just as fast as direct port manipulation. <a href="http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267553811/0">Arduino Forum post here.</a> I just tested the digitalWriteFast2() function and it also seems to only require 2 cycles to complete.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=308" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=308" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=308</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>SAGAR Update, New Motor Controller and Motors</title>
		<link>http://www.billporter.info/?p=286</link>
		<comments>http://www.billporter.info/?p=286#comments</comments>
		<pubDate>Sun, 08 Aug 2010 03:50:43 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Autonomous Rover]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=286</guid>
		<description><![CDATA[ Hey Guys,
It&#8217;s been a while since I posted an update on SAGAR, but here&#8217;s the latest.
I wanted her to go faster. My original motors would only do about 1.2 m/s tops. Well, with a little help from a friend, I found new motors that would bring up the top speed to well over 3 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.billporter.info/wp-content/uploads//2010/02/IMG_2545.jpg"><img class="alignleft size-thumbnail wp-image-177" title="IMG_2545" src="http://www.billporter.info/wp-content/uploads//2010/02/IMG_2545-150x150.jpg" alt="" width="150" height="150" /></a> Hey Guys,</p>
<p>It&#8217;s been a while since I posted an update on SAGAR, but here&#8217;s the latest.</p>
<p>I wanted her to go faster. My original motors would only do about 1.2 m/s tops. Well, with a little help from a friend, I found new motors that would bring up the top speed to well over 3 m/s. However, they require more current to reach that speed, more then my original controller could handle. So it had to be replaced.</p>
<p>I wanted to build a single board motor controller from scratch, but couldn&#8217;t find the parts I needed with the support for the higher current. I decided on a motor driver board from Pololu, and designed my own &#8216;daughter board&#8217; to connect to it.</p>
<p>The daughter board is an Arduino board of my own design. It mates directly with the Pololu driver board, and included the pin headers for motor encoders, and a connector for a Dimension Engineering voltage regulator. The regulator will be providing the 5V rail for all the electronics in SAGAR.</p>
<p>I have several copies of the daughter board if anyone wants them. They are yours for free but you pay shipping. Leave a comment if you would like one.</p>
<p>Here are some pictures: (click for full size)</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/08/schematic.png"><img class="alignnone size-full wp-image-368" title="schematic" src="http://www.billporter.info/wp-content/uploads//2010/08/schematic.png" alt="" /></a></p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/07/board2.png"><img class="alignnone size-medium wp-image-284" title="board" src="http://www.billporter.info/wp-content/uploads//2010/07/board2-300x249.png" alt="" width="300" height="249" /></a></p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2968-Medium.jpg"><img class="alignnone size-full wp-image-291" title="IMG_2968 (Medium)" src="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2968-Medium.jpg" alt="" /></a><a href="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2967-Medium.jpg"><img class="alignnone size-full wp-image-290" title="IMG_2967 (Medium)" src="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2967-Medium.jpg" alt="" /></a><a href="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2966-Medium.jpg"><img class="alignnone size-full wp-image-289" title="IMG_2966 (Medium)" src="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2966-Medium.jpg" alt="" /></a><a href="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2964-Medium.jpg"><img class="alignnone size-full wp-image-288" title="IMG_2964 (Medium)" src="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2964-Medium.jpg" alt="" /></a><a href="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2961-Medium.jpg"><img class="alignnone size-full wp-image-287" title="IMG_2961 (Medium)" src="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2961-Medium.jpg" alt="" /></a></p>
<p>New</p>
<p>Some more pictures:</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2969-Medium.jpg"><img class="alignnone size-full wp-image-300" title="IMG_2969 (Medium)" src="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2969-Medium.jpg" alt="" /></a></p>
<p>The old Motor Driver. I feel like it was such a messy job now.</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2971-Medium.jpg"><img class="alignnone size-full wp-image-301" title="IMG_2971 (Medium)" src="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2971-Medium.jpg" alt="" /></a></p>
<p>With the Voltage and Current Sensor</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2973-Medium.jpg"><img class="alignnone size-full wp-image-302" title="IMG_2973 (Medium)" src="http://www.billporter.info/wp-content/uploads//2010/08/IMG_2973-Medium.jpg" alt="" /></a></p>
<p>Installed. Man it looks sexy!</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=286" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=286" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=286</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Getting Data BACK From Google Earth and Into LabView</title>
		<link>http://www.billporter.info/?p=268</link>
		<comments>http://www.billporter.info/?p=268#comments</comments>
		<pubDate>Thu, 24 Jun 2010 00:26:10 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Autonomous Rover]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=268</guid>
		<description><![CDATA[I wanted to be able to get information back from Google Earth. It&#8217;s already easy to plot information on Google Earth, but getting information back, like the GPS coordinates under the mouse pointer, was another story. Well, I slaved myself to my desk for a few days and figured it out. I created a sample [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.billporter.info/wp-content/uploads//2010/06/2413511031_e5c3931b58_m.jpg"><img class="alignleft size-thumbnail wp-image-269" title="2413511031_e5c3931b58_m" src="http://www.billporter.info/wp-content/uploads//2010/06/2413511031_e5c3931b58_m-150x150.jpg" alt="" width="116" height="116" /></a>I wanted to be able to get information back from Google Earth. It&#8217;s already easy to plot information on Google Earth, but getting information back, like the GPS coordinates under the mouse pointer, was another story. Well, I slaved myself to my desk for a few days and figured it out. I created a sample VI program that displays the GPS coordinates of the Mouse over the globe, and captures the coordinates on a left mouse click. It then feeds them back into Google Earth as a point.</p>
<p>My Source VI can be <a href="../wp-content/uploads//2010/06/GoogleEarthLabViewDemo.zip">Downloaded  Here</a></p>
<p>LabView V8.6 <a href="http://www.billporter.info/wp-content/uploads//2010/06/GoogleEarthDEMO-8_6.zip">HERE</a></p>
<p>The following video showcases my sample program.<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="340" 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://www.youtube.com/v/_eS_OziE6J4&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="340" src="http://www.youtube.com/v/_eS_OziE6J4&amp;hl=en_US&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=268" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=268" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=268</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PlayStation 2 Controller Arduino Library v1.0</title>
		<link>http://www.billporter.info/?p=240</link>
		<comments>http://www.billporter.info/?p=240#comments</comments>
		<pubDate>Sat, 05 Jun 2010 18:40:43 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=240</guid>
		<description><![CDATA[The first fully working version (v1.0) is now available. I split this into a new blog post, as many things have changed.
The big change is you can now define what pins of the Arduino are used, no longer are you tied to pins 10-13.
Also, vibration (Rumble) and analog button pressure readings (how hard is a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.billporter.info/wp-content/uploads//2010/05/PlayStation-2-Dualshock-Controller-Black-B00004YRQ9-L.jpg"><img class="alignleft size-thumbnail wp-image-220" title="PlayStation-2-Dualshock-Controller-Black-B00004YRQ9-L" src="http://www.billporter.info/wp-content/uploads//2010/05/PlayStation-2-Dualshock-Controller-Black-B00004YRQ9-L-150x150.jpg" alt="" width="150" height="150" /></a>The first fully working version (v1.0) is now available. I split this into a new blog post, as many things have changed.</p>
<p>The big change is you can now define what pins of the Arduino are used, no longer are you tied to pins 10-13.</p>
<p>Also, vibration (Rumble) and analog button pressure readings (how hard is a button being pressed) are now working.</p>
<p>The library has changed names. PSX -&gt; PS2X to avoid confusion with other sets of code. Sorry for those that need to change a bunch of their programs.</p>
<p>I had to rewrite a lot of code that powers the library, there is not much left of the original code written by Shutter of Arduino forums. There were many bug fixes, now the controller should automatically be in analog mode, and the mode button should be locked. There&#8217;s also a catch to make sure not to much time has past since the last controller reading. If there was, it will configure the controller again, in case it timed out.</p>
<p>Download here:</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/06/PS2X_lib_v1_41.zip">PS2X lib v1.41</a></p>
<p>Old Versions:</p>
<p><a href="../wp-content/uploads//2010/06/PS2X_lib_v1_0.zip">PS2X_lib_v1.0</a></p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/06/PS2X_lib_v1_3.zip">PS2X_lib v1.3</a></p>
<p><a href="../wp-content/uploads//2010/06/PS2X_lib_v1_4.zip">PS2X lib v1.4</a></p>
<p>For those who missed the excitement the first time, here&#8217;s a wiring diagram(from the amazing <a href="http://store.curiousinventor.com/guides/PS2">CuriousInventor PS2 Interface Guide</a>) and demonstration video:</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/05/wiring.jpg"><img class="aligncenter size-full wp-image-223" title="wiring" src="http://www.billporter.info/wp-content/uploads//2010/05/wiring.jpg" alt="" width="500" height="565" /></a>Image Source:<a href="http://store.curiousinventor.com/guides/PS2"> CuriousInventor</a></p>
<p><strong>Here&#8217;s a video demonstrating the library.</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="385" 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://www.youtube.com/v/LMgzF7qeeEY&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="385" src="http://www.youtube.com/v/LMgzF7qeeEY&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=240" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=240" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=240</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>OLD PlayStation 2 Controller Arduino Library</title>
		<link>http://www.billporter.info/?p=219</link>
		<comments>http://www.billporter.info/?p=219#comments</comments>
		<pubDate>Tue, 01 Jun 2010 03:43:30 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=219</guid>
		<description><![CDATA[
Outdated. Go to new library HERE
A while ago, I spent countless days trying to interface an Arduino and a Play Station 2 controller. I wanted to build a controller for my SAGAR robot, and figured PS2 + Arduino would be perfect. However, no matter what I did, no existing library would work for me. I [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.billporter.info/wp-content/uploads//2010/05/PlayStation-2-Dualshock-Controller-Black-B00004YRQ9-L.jpg"><img class="alignleft size-thumbnail wp-image-220" title="PlayStation-2-Dualshock-Controller-Black-B00004YRQ9-L" src="http://www.billporter.info/wp-content/uploads//2010/05/PlayStation-2-Dualshock-Controller-Black-B00004YRQ9-L-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>Outdated. <a href="http://www.billporter.info/?p=240" target="_self">Go to new library HERE</a></p>
<p>A while ago, I spent countless days trying to interface an Arduino and a Play Station 2 controller. I wanted to build a controller for my SAGAR robot, and figured PS2 + Arduino would be perfect. However, no matter what I did, no existing library would work for me. I shelfed the project for a while, but recently found <a href="http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1203744779/30" target="_blank">this</a> forum post with some code by a member named Shutter. I tried out the code, and to my surprise, IT WORKED!!! Well, mostly anyway. It didn&#8217;t really have analog stick support, nor was it formatted into an easy to use library.</p>
<p>Well, through need I spent some time adding analog stick support, and formatted it into a library. It works fine on my Arduino Pro mini.</p>
<p>Here are my library files, and an example Arduino sketch that uses it. Enjoy, and comment here with any bugs you find.</p>
<p>To install the lib, unzip the Source Files zip into your Arduino/hardware/libraries directory.</p>
<p>Go to new  library page  <a href="http://www.billporter.info/?p=240">HERE</a> to download.</p>
<p>Note: The library is hard coded to use pins 10-13 for interfacing the controller. When I get time, I&#8217;ll add code that lets you change the pins when initialized. For now, the pin-out is as follows:</p>
<p><span style="text-decoration: underline;">PIN     Name             Color</span></p>
<p>10        Attention     Yellow</p>
<p>11        Command     Orange</p>
<p>12        Data              Brown</p>
<p>13       Clock            Blue</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/05/wiring.jpg"><img class="aligncenter size-full wp-image-223" title="wiring" src="http://www.billporter.info/wp-content/uploads//2010/05/wiring.jpg" alt="" width="500" height="565" /></a>Image Source:<a href="http://store.curiousinventor.com/guides/PS2"> CuriousInventor</a></p>
<p>Hack-a-day Visitors:  I&#8217;m honored to be featured on Hack-a-day, and hope this helps out some fellow builders. I also want to re-iterate that I started out with existing code by Shutter of Arduino forums and added analog support, as well as turned the code into a working library.  I can&#8217;t take all the credit.</p>
<p><strong>Here&#8217;s a video demonstrating the library.</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="385" 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://www.youtube.com/v/LMgzF7qeeEY&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="385" src="http://www.youtube.com/v/LMgzF7qeeEY&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;color1=0x2b405b&amp;color2=0x6b8ab6" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
This code is demonstrated in the video. The program works by setting up the library, initializing the controller, and continuously reading the controller and sending the data to the robot.<br />
<a href="http://www.billporter.info/wp-content/uploads//2010/05/better-code.png"><img class="aligncenter size-full wp-image-235" title="better code" src="http://www.billporter.info/wp-content/uploads//2010/05/better-code.png" alt="" width="447" height="667" /></a></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=219" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=219" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=219</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>The Trouble With Communications.</title>
		<link>http://www.billporter.info/?p=214</link>
		<comments>http://www.billporter.info/?p=214#comments</comments>
		<pubDate>Thu, 29 Apr 2010 01:03:41 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=214</guid>
		<description><![CDATA[A person has already come to me asking how to interface an Axon Microcontroller to LabView. Instead of a bland answer to the effect of “It’s nothing special”, I decided to write a quick write-up about communications between computer systems; and I will use the communication between my SAGAR robot and LabView operator panel as [...]]]></description>
			<content:encoded><![CDATA[<p>A person has already come to me asking how to interface an Axon Microcontroller to LabView. Instead of a bland answer to the effect of “It’s nothing special”, I decided to write a quick write-up about communications between computer systems; and I will use the communication between my SAGAR robot and LabView operator panel as an example.</p>
<p>First, you need to connect the two systems at the physical level, IE you need to wire the two devices together. For my project, I used an XBEE radio link. This emulates a serial cable between the Axon and my laptop. I used an Axon’s uart port, and a USB port on my laptop for the USB to Uart chip. LabView has VISA libraries to read from a serial port.  This is the easy part of any communication system.</p>
<p>The tricky part is how to convey information between the two. I need to go back to a basic level to fully explain this. For us 10 fingered humans, we express numbers in base 10. The number ‘6’ means this many ( * * * * * *) things. We say ‘6’ to express that many items to another human, and the base 10 number systems is commonly accepted by the human race as THE way to express the number of things. Computers are different. They can only express things in binary, base 2. So ‘6’ to a computer is 110. The problem is that there are many ways to express ‘6’ in a computer. It could be 0110 or 1010 or 01111010. We tell the computer how to represent a number when we declare it as an int, double, etc. So if we were to send data at a binary level, we would have to keep track of how either system is representing it’s numbers. If they don’t match, they won’t understand each other.</p>
<p>There’s also this little thing called big/little endian. This describes the order of how a number is stored in a computer. One way is the way we would consider normal, IE 231 is stored as 2 – 3 – 1. The other way stores numbers backwards, 1 – 3 – 2 .  If the two systems as mismatched, again you get communications errors.</p>
<p>These two variables of computer systems are hard to keep track of, and make communications challenging. A way around this is to convert all communications to the ‘human’ standard, something we organic life forms can understand. I use printf() statements to output a sentence of data in a comma delimited form otherwise known as a NMEA sentence.  For example,</p>
<p>$SAGAN,20,2,30.193392,-85.797508,55,193*75</p>
<p>Conveys information about the waypoint mission SAGAR is running. The first field, the ‘header’, tells LabView what sentence this is, ie what it conveys. The next fields give the number of waypoints, the current waypoint, the coordinates of the waypoint, the range and bearing to that waypoint. The sentence ends with a * and a checksum to check integrity of the sentence.</p>
<p>Because we are converting all binary data to ascii representations of base 10 numbers, there is no way to confuse the data, no need to worry about how it’s declared in either system nor how it’s stored in memory.</p>
<p>When LabView receives the sentence through a serial port, it checks the sentence against the checksum to confirm its integrity, scans the header to determine its contents, and then breaks it apart into ‘tokens’. These tokens are sub-strings of the numbers between the commas. Then they can be converted into computer numbers using the LabView equivalent of atof(). (Ascii to float).<br />
<a href="http://www.billporter.info/wp-content/uploads//2010/04/labview.png"><img class="size-full wp-image-215 alignnone" title="labview" src="http://www.billporter.info/wp-content/uploads//2010/04/labview.png" alt="" width="510" height="132" /></a></p>
<p>And there we have it. We successfully conveyed a number from an Axon Microcontroller to a laptop running LabView, without messing with how numbers are declared or stored. The tradeoff, however, is it takes more bandwidth to send ascii sentences then it does to send binary data, but the ease in which to integrate the two systems is worth it, at least in my opinion.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=214" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=214" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=214</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SAGAR System Overview, Part 1</title>
		<link>http://www.billporter.info/?p=202</link>
		<comments>http://www.billporter.info/?p=202#comments</comments>
		<pubDate>Tue, 20 Apr 2010 14:22:20 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Autonomous Rover]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=202</guid>
		<description><![CDATA[My SAGAR project has gotten to a point where I would like to document the system design through a series of detailed posts.
First I&#8217;ll show the new interface, and talk about how it  communicates with SAGAR.
Here  is a video of the new interface, with an inset of SAGAR as it runs the  [...]]]></description>
			<content:encoded><![CDATA[<p>My SAGAR project has gotten to a point where I would like to document the system design through a series of detailed posts.</p>
<p>First I&#8217;ll show the new interface, and talk about how it  communicates with SAGAR.</p>
<p>Here  is a video of the new interface, with an inset of SAGAR as it runs the  mission.</p>
<p>NMCI friendly:<br />
<object type="application/x-shockwave-flash" style="width:448px;height:386px" data="http://www.billporter.info/wp-content/plugins/xhtml-video-embed/mediaplayer.swf?flv=http://www.billporter.info/wp-content/uploads//2010/04/SAGAR.mp4&amp;autoplay=0&amp;autoload=0&amp;volume=100&amp;bgcolor1=4f4f4f&amp;bgcolor2=4f4f4f&amp;showstop=1&amp;showvolume=1&amp;showtime=2&amp;showloading=always&amp;showfullscreen=1&amp;&amp;ondoubleclick=fullscreen&amp;shortcut=1&amp;loadonstop=0&amp;margin=4&amp;showiconplay=1&amp;iconplaybgalpha=50"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="quality" value="best" /><param name="movie" value="http://www.billporter.info/wp-content/plugins/xhtml-video-embed/mediaplayer.swf?flv=http://www.billporter.info/wp-content/uploads//2010/04/SAGAR.mp4&amp;autoplay=0&amp;autoload=0&amp;volume=100&amp;bgcolor1=4f4f4f&amp;bgcolor2=4f4f4f&amp;showstop=1&amp;showvolume=1&amp;showtime=2&amp;showloading=always&amp;showfullscreen=1&amp;&amp;ondoubleclick=fullscreen&amp;shortcut=1&amp;loadonstop=0&amp;margin=4&amp;showiconplay=1&amp;iconplaybgalpha=50" /><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer" />If you can see this, then you might need a Flash Player upgrade or you need to install Flash Player if it's missing. Get <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash Player</a> from Adobe.</object><br/>
		<!-- Valid XHTML flash object delivered by XHTML Video Embed. Get it at: http://saltwaterc.net/xhtml-video-embed -->
		</p>
<p>YouTube:<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="460" height="260" 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://www.youtube.com/v/cNZccRC8Zek&amp;hl=en_US&amp;fs=1&amp;hd=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="460" height="260" src="http://www.youtube.com/v/cNZccRC8Zek&amp;hl=en_US&amp;fs=1&amp;hd=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>During the run we recorded, there was a glitch half way through. It  appears Labview started to slow down and the gap between live events and  what was being displayed grew, until the Labview buffer overflowed and  sentences where lost. I have yet to look into that problem, as it is the  first time we have observed it.</p>
<p>When my girlfriend came to me  for ideas for her LabView class, I suggested she write an interface for  my robot. I knew I would have to develop a communication protocol that I  could hand to her from the start. I took a look at the structure of the  ArduPilot communications, and it seemed odd to me. Is the structure a  known protocol? I&#8217;m sure one of the developers will tell me.</p>
<p>I  decided to stick to something I knew, the NMEA protocol. For those who  are not aware, GPS systems communicate via the NMEA protocol, as do many  other robotics systems. The structure of a NMEA sentences starts with a  header that identifies the sentence, then comma delimited fields that  contain the data to be passed. The sentence is usually followed by a  checksum, to validate the integrity of the data. I came up with my own  header, and added the fields of sensor data I wanted to have displayed  on the interface. Here is an example of my structure.</p>
<p>$SAGAR,heading,pitch,roll,wheelspeed(Commanded l+r, actual l+r),</p>
<p>distance_trav,GPS_Fix,GPS_Lat,GPA_lon,GPS_speed,GPS_COG,</p>
<p>Battery_V,Battery_I,processor_load*CS</p>
<p>This is one of two sentences SAGAR will send to  the interface. The other sentence contains mission statistics like  current waypoint number, distance to waypoint, etc. There are also 4  sentences that the interface sends to SAGAR, each representing a  different mode for SAGAR to enter, and commands to follow. There is a  fail-safe in place, if SAGAR doesn&#8217;t receive a command sentence in  500ms, it halts and enters stand-by.</p>
<p>SAGAR started as a bag of  parts nearly a year ago, and grew from there. (Almost) everything is  from scratch, down to DIY battery packs.</p>
<p>Not too shabby? Forgive  and spelling/grammar, I am definitely bad at both.</p>
<p>Coming up  next: The importance of a good chassis, and building my own closed loop  motor controller.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=202" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=202" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=202</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.billporter.info/wp-content/uploads//2010/04/SAGAR.mp4" length="35258721" type="video/mp4" />
		</item>
		<item>
		<title>SAGAR Update!! Mission Mode with LabView Panel</title>
		<link>http://www.billporter.info/?p=195</link>
		<comments>http://www.billporter.info/?p=195#comments</comments>
		<pubDate>Tue, 13 Apr 2010 23:47:56 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Autonomous Rover]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=195</guid>
		<description><![CDATA[In a joint effort between my girlfriend and I, SAGAR now has a super fancy LabView based graphical user interface. The video below is a screen capture of the interface as SAGAR runs a mission taking it around a parking lot. All communications are in the form of NMEA sentences. The DIYdrones ground station gave [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.billporter.info/wp-content/uploads//2010/02/IMG_2546.jpg"><img class="alignleft size-thumbnail wp-image-178" title="IMG_2546" src="http://www.billporter.info/wp-content/uploads//2010/02/IMG_2546-150x150.jpg" alt="" width="150" height="150" /></a>In a joint effort between my girlfriend and I, SAGAR now has a super fancy LabView based graphical user interface. The video below is a screen capture of the interface as SAGAR runs a mission taking it around a parking lot. All communications are in the form of NMEA sentences. The DIYdrones ground station gave us a few ideas of what we wanted to do.</p>
<p>The terrain isn&#8217;t actually that rough, SAGAR&#8217;s orientation sensor is just noisy. I&#8217;ll have to take a look at it later. The current position of SAGAR is plotted real time on Google Earth, as well as the current WayPoint goal.</p>
<p>Watch the video on Youtube <a href="http://www.youtube.com/watch?v=lHI_m-GH_Qc&amp;hd=1">here.</a></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=195" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=195" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=195</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>S.A.G.A.R. update &#8211; IT&#8217;S ALIVE!!!!</title>
		<link>http://www.billporter.info/?p=192</link>
		<comments>http://www.billporter.info/?p=192#comments</comments>
		<pubDate>Wed, 07 Apr 2010 05:10:14 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Autonomous Rover]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=192</guid>
		<description><![CDATA[Ok, so I&#8217;m a little overexcited. I just got back from watching SAGAR complete it&#8217;s first autonomous mission. I just finished coding the navigation functions and couldn&#8217;t wait till the next day to test. Attached is an image of the mission it ran.
I used a Ardupilot program to generate the mission file with waypoints, convert [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.billporter.info/wp-content/uploads//2010/04/mission3.png"><img class="alignleft size-thumbnail wp-image-191" title="mission3" src="http://www.billporter.info/wp-content/uploads//2010/04/mission3-150x150.png" alt="" width="150" height="150" /></a>Ok, so I&#8217;m a little overexcited. I just got back from watching SAGAR complete it&#8217;s first autonomous mission. I just finished coding the navigation functions and couldn&#8217;t wait till the next day to test. Attached is an image of the mission it ran.</p>
<p>I used a Ardupilot program to generate the mission file with waypoints, convert it to a hex file using gcc, and I manually flash that into the Axon&#8217;s EEPROM memory. When SAGAR comes online, I give it a command to scan the mission file in memory, then I command it to run the mission.</p>
<p>It worked rather well, I had to stop it a few times to avoid hitting a curb or two, but other then that it hit all the waypoints in it&#8217;s mission. The cheapo Venus GPS I&#8217;m using for SAGAR apparently is really inaccurate at times.</p>
<p>More to come&#8230;</p>
<p><a href="http://www.billporter.info/wp-content/uploads//2010/04/mission3.png"><img class="aligncenter size-full wp-image-191" title="mission3" src="http://www.billporter.info/wp-content/uploads//2010/04/mission3.png" alt="" width="522" height="476" /></a></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=192" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=192" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=192</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>S.A.G.A.R. Update, Compass Woes</title>
		<link>http://www.billporter.info/?p=174</link>
		<comments>http://www.billporter.info/?p=174#comments</comments>
		<pubDate>Sat, 06 Feb 2010 19:22:36 +0000</pubDate>
		<dc:creator>Bill</dc:creator>
				<category><![CDATA[Autonomous Rover]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.billporter.info/?p=174</guid>
		<description><![CDATA[I have been asked by a few people how SAGAR is going, so I guess I need to do some updates more often. Anyway, SAGAR was shelved for a while. The last tests of the closed loop heading controller showed I had something messing with the compass readings. Further tests concluded that my batteries were [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.billporter.info/wp-content/uploads//2010/02/Compass.jpg"><img class="alignleft size-thumbnail wp-image-185" title="Compass" src="http://www.billporter.info/wp-content/uploads//2010/02/Compass-150x150.jpg" alt="" width="150" height="150" /></a>I have been asked by a few people how SAGAR is going, so I guess I need to do some updates more often. Anyway, SAGAR was shelved for a while. The last tests of the closed loop heading controller showed I had something messing with the compass readings. Further tests concluded that my batteries were biasing my compass.</p>
<p>I ordered some parts for SAGAR, moved the compass out of the main body and up on some standoffs. I added a top deck to protect the compass. The upper deck will be used in the future to hold the ultrasonic rangefinders when I move to feature based navigation.</p>
<p>Pictures of the new design below.</p>

<a href='http://www.billporter.info/?attachment_id=176' title='IMG_2544'><img width="150" height="150" src="http://www.billporter.info/wp-content/uploads//2010/02/IMG_2544-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_2544" /></a>
<a href='http://www.billporter.info/?attachment_id=177' title='IMG_2545'><img width="150" height="150" src="http://www.billporter.info/wp-content/uploads//2010/02/IMG_2545-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_2545" /></a>
<a href='http://www.billporter.info/?attachment_id=178' title='IMG_2546'><img width="150" height="150" src="http://www.billporter.info/wp-content/uploads//2010/02/IMG_2546-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_2546" /></a>
<a href='http://www.billporter.info/?attachment_id=179' title='IMG_2547'><img width="150" height="150" src="http://www.billporter.info/wp-content/uploads//2010/02/IMG_2547-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_2547" /></a>
<a href='http://www.billporter.info/?attachment_id=185' title='Compass'><img width="150" height="150" src="http://www.billporter.info/wp-content/uploads//2010/02/Compass-150x150.jpg" class="attachment-thumbnail" alt="" title="Compass" /></a>

<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=174" target="_blank"><img src="http://www.billporter.info/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.billporter.info/?p=174" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.billporter.info/?feed=rss2&amp;p=174</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
