<?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>Marginally Clever &#187; Uncategorized</title>
	<atom:link href="http://www.marginallyclever.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marginallyclever.com</link>
	<description>DIY Robotics, automation, tools, manufacturing, and everything related</description>
	<lastBuildDate>Sun, 05 Feb 2012 22:32:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Kinect based art project</title>
		<link>http://www.marginallyclever.com/2012/01/kinect-based-art-project/</link>
		<comments>http://www.marginallyclever.com/2012/01/kinect-based-art-project/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 22:31:28 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[art]]></category>
		<category><![CDATA[kinect]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=396</guid>
		<description><![CDATA[An 8 foot pole, atop which are 9 kinect bars facing outward. Together they form a color 3d map of the entire surroundings. The math is done on, say, a mac mini in a backpack, and then the image is displayed on a tablet for the user. The user can pan, tilt, and zoom the [...]]]></description>
			<content:encoded><![CDATA[<p>An 8 foot pole, atop which are 9 kinect bars facing outward.  Together they form a color 3d map of the entire surroundings.  The math is done on, say, a mac mini in a backpack, and then the image is displayed on a tablet for the user.  The user can pan, tilt, and zoom the 3d view as they walk around, building a map of the environment.</p>
<p>Tied with google earth or a UAV drone, the system becomes even more powerful &#8211; the user has eyes in the back of their head, as well as around corners.</p>
<p>I could probably come up with a lot of BS about human interaction, the nature of technology in society, man&#8217;s relation to himself when reduced to an avatar, etc&#8230; but the truth is I think it&#8217;s just a really neat idea and I don&#8217;t know what effect it would have until I build it.</p>
<p>Do you feel the same?  Maybe you can help.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2012/01/kinect-based-art-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Delta Robot Part 1: Defining Success</title>
		<link>http://www.marginallyclever.com/2012/01/building-a-delta-robot-part-1-defining-success/</link>
		<comments>http://www.marginallyclever.com/2012/01/building-a-delta-robot-part-1-defining-success/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 20:43:21 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=397</guid>
		<description><![CDATA[What is a delta robot? My goal is to make a delta robot that draws pictures.  Later I&#8217;d like to 3D print in ABS plastic.  So what am I looking to achieve? Repeatable accuracy: 0.25mm.  Say the robot is holding a pen pointing at a grid on a piece of paper.  It starts at (0,0,0), [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.youtube.com/watch?v=SrOjtzllLTg&amp;feature=results_main&amp;playnext=1&amp;list=PLCA2D16A480CD47BE">What is a delta robot?</a></p>
<p>My goal is to make a delta robot that draws pictures.  Later I&#8217;d like to 3D print in ABS plastic.  So what am I looking to achieve?</p>
<ol>
<li><em>Repeatable accuracy</em>: 0.25mm.  Say the robot is holding a pen pointing at a grid on a piece of paper.  It starts at (0,0,0), moves around, comes back and is within 0.25mm of (0,0,0).  It might be right on.  It might stop at (0,0.125,0).</li>
<li><em>Envelope size</em>: 15cm*15cm*15cm.  That&#8217;s the maximum range of motion for the tool the robot is holding.  So from (0,0,0) it can move from (-7.5,-7.5,0) to (7.5,7.5,15).  This is easy to test</li>
<li><em>Weight limit</em>: 50 grams.  Delta robots aren&#8217;t known for carrying a lot of weight, and all I&#8217;m moving is a pen.  I&#8217;ll probably have to use stronger stepper motors if I ever try 3D printing.</li>
<li><em>Play/Slop:</em> Does the tool undercut or overshoot the target line?</li>
<li><em>Maximum velocity</em>: 20cm/s?</li>
<li><em>Maximum acceleration</em>: 20cm/s/s?</li>
<li><em>Automatic calibration</em>: I want the robot to know where (0,0,0) the moment I turn it on.  No guess work.</li>
</ol>
<p>I plan to test each of these conditions as follows:</p>
<ol>
<li>I&#8217;ll mount a <a href="http://www.mahr.com/index.php?NodeID=10865">3D digital touch probe</a> to the table and a metal cone to the tool tip.  After each movement the computer can record the amount of push on the probe.  After a few hundred samples a pretty clear picture should form.  The tests would then be repeated near the corners of the envelope.  To make life easier our math is going to try to do better than 0.25mm.</li>
<li>Using the same cone, and a ruler taped to the table.  Test that the cone can travel from (0,0,0) to the desired distance on the rule.  Repeat in every direction.</li>
<li>The metal cone should weigh 50 grams so that the previous tests are done at maximum load, when the machine is being strained to the limit.</li>
<li>I&#8217;ll print a test pattern on a normal printer, tape it to the table, and then have the machine draw the same design and see if they match.  This will depend a lot on the physics of momentum.</li>
<li>I&#8217;m not sure.  The cone could touch a switch at either end of the envelope a few dozen times and then I&#8217;d have a measure of top speed.</li>
<li>See #5</li>
<li>The same touch switches could be used to tell when the robot has re-centered itself.</li>
</ol>
<p>In the next installment I&#8217;m going to<del> cover the math and look at how it will help us design to spec</del> <a href="http://www.marginallyclever.com/2012/01/building-a-delta-robot3d-model-version-1/">build a computer model</a> and then adjust it to fit the math.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2012/01/building-a-delta-robot-part-1-defining-success/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Five steps to building a better robot</title>
		<link>http://www.marginallyclever.com/2012/01/five-steps-to-building-a-better-robot/</link>
		<comments>http://www.marginallyclever.com/2012/01/five-steps-to-building-a-better-robot/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 22:19:06 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=392</guid>
		<description><![CDATA[I&#8217;ve been trying to write a tutorial on delta robots and my writer&#8217;s block is pretty bad.  The problem is that I start to write and realize I&#8217;m only teaching my readers the things that I learned online.  I&#8217;m not contributing anything new which means they&#8217;re going to produce the same half-assed robots as I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to write a tutorial on delta robots and my writer&#8217;s block is pretty bad.  The problem is that I start to write and realize I&#8217;m only teaching my readers the things that I learned online.  I&#8217;m not contributing anything new which means they&#8217;re going to produce the same <a href="http://www.youtube.com/aggrav8d/" target="_blank">half-assed robots</a> as I did.  UNACCEPTABLE!</p>
<p>So here now is a soul-bearing expose of what should be done and then I&#8217;ll give a breakdown of where I got it wrong.  Learn from my mistakes and your robots will be better than mine.</p>
<p>The five major steps to building a better robot are:</p>
<ol>
<li>Decide what your robot will do and how you will test for success.  Some of you may know this as <a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">test-driven development</a>.</li>
<li>Build a theoretical model in a computer.  Start with a mathematical model and then build a simulation of your robot.  The more accurate your simulation the more likely you are to detect problems early.</li>
<li>Program the model to behave the way you want.  If you do it right then it will take almost no effort to use the same program to move your real robot when it&#8217;s ready.</li>
<li>Acquire hardware &amp; build robot to spec.  Since you already have the models built you can be very specific about what you&#8217;re looking for.  Good suppliers will be happy to help you sort through their catalogs and get the right parts.</li>
<li>Test.  Get it on video.  Safety third.  If tests fail post it on Youtube, then go to step 2.</li>
</ol>
<p>So where did I go wrong?</p>
<ol>
<li>I didn&#8217;t have enough tests defined at the start.  In other words I didn&#8217;t have a clear enough picture of what the robot was supposed to do.</li>
<li>Because I didn&#8217;t have enough tests, I was able to get lazy with the theoretical model.  I didn&#8217;t concern myself with how accurate the robot would be, I only cared if it would work *at all*.  It was only afterwards that I realized how poorly it worked.  In one case I built a great model and only fudged one part.  When I got the machine assembled that one uncertain part meant that two other pieces collided and I almost broke many things.</li>
<li>The UI was crummy so nobody else wants to use it and the simulation doesn&#8217;t really take into account all the physical properties like moment of inertia, mass, speed, and acceleration.  It&#8217;s too &#8220;perfect&#8221; and that means it has little connection to the real world.</li>
<li>Making one of a part is a lot more expensive than making 1000 of a part (per part).  It follows that it&#8217;s cheaper to get a part that already does what you want than to make your own.  Having said that&#8230; gears and gearboxes are no fun to source. Also: it&#8217;s better to plug than to solder.  Plugs can be safely disconnected, and in the event of an accident it&#8217;s the plug that will go, not the expensive circuit board.</li>
<li>Because I didn&#8217;t do so well on step 1, all I could do was measure the results and feel disappointed.  Maybe I&#8217;ve achieved a miracle with the parts I picked, but how would I know?</li>
</ol>
<p>Now before anyone says I sound too negative, let me point out what went right:</p>
<ol>
<li>I set myself a goal (however vague) and I created a map to get me from no robot to finished robot.</li>
<li>I dedicated time every day to completing the project and I didn&#8217;t let my setbacks get me down.</li>
<li>I put the skills I had to use (programming) and when I needed to I gained valuable new skills (soldering, electronics, mechanical engineering)</li>
<li>I made interesting new friends and lots of business contacts.</li>
</ol>
<p>It feels good to put my mistakes down on paper.  I should do post-mortems more often!</p>
<p>So how will my future designs change?  Well for starters when I write tutorials on building robots I&#8217;m going to tell you where there are gaps in my knowledge.  I hope that someone will comment to fill in the gaps in my understanding for everyone&#8217;s benefit.</p>
<p>In news, the final pieces of my 3D printer are shipping tomorrow.  It should be here by the end of the month!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2012/01/five-steps-to-building-a-better-robot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>BC help for startup businesses</title>
		<link>http://www.marginallyclever.com/2011/12/bc-help-for-startup-businesses/</link>
		<comments>http://www.marginallyclever.com/2011/12/bc-help-for-startup-businesses/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 19:43:55 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=387</guid>
		<description><![CDATA[BC innovation Center &#8211; http://www.bcic.ca/ BCIT commercialization program &#8211; http://www.bcit.ca/appliedresearch/arlo/caps/ BCIT applied research liaison office &#8211; http://www.bcit.ca/appliedresearch/arlo/ BC center for small business financing &#8211; http://www.grants-loans.org/bc-grants.php Know of any more? Comment below!]]></description>
			<content:encoded><![CDATA[<p>BC innovation Center &#8211; http://www.bcic.ca/<br />
BCIT commercialization program &#8211; http://www.bcit.ca/appliedresearch/arlo/caps/<br />
BCIT applied research liaison office &#8211; http://www.bcit.ca/appliedresearch/arlo/<br />
BC center for small business financing &#8211; http://www.grants-loans.org/bc-grants.php</p>
<p>Know of any more?  Comment below!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2011/12/bc-help-for-startup-businesses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>6DOF Robotic Arm design complete?</title>
		<link>http://www.marginallyclever.com/2011/11/6dof-robotic-arm-design-complete/</link>
		<comments>http://www.marginallyclever.com/2011/11/6dof-robotic-arm-design-complete/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 19:18:06 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=379</guid>
		<description><![CDATA[I think I&#8217;ve finally figured out how to complete my robotic arm. The bottom of the arm (at the shoulder) took longer to solve than anything else, even though it should have been the simplest part. Wierd, huh?]]></description>
			<content:encoded><![CDATA[<p>I think I&#8217;ve finally figured out how to complete my robotic arm.  The bottom of the arm (at the shoulder) took longer to solve than anything else, even though it should have been the simplest part.  Wierd, huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2011/11/6dof-robotic-arm-design-complete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do I Drive a High Amp Stepper Motor from an Arduino?</title>
		<link>http://www.marginallyclever.com/2011/11/how-do-i-drive-a-high-amp-stepper-motor-from-an-arduino/</link>
		<comments>http://www.marginallyclever.com/2011/11/how-do-i-drive-a-high-amp-stepper-motor-from-an-arduino/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 20:58:19 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=381</guid>
		<description><![CDATA[http://en.wikipedia.org/wiki/Stepper_motor#See_also http://ams2000.com/stepping101.html What you want are drivers from CNC machines like automated lathes, mills, and routers. Your Arduino will be the encoder generating the pulses that tell the drivers when to move each stepper. When you build your machine, you&#8217;ll need code to make it move. My code contains a virtual model of my machine. [...]]]></description>
			<content:encoded><![CDATA[<p>http://en.wikipedia.org/wiki/Stepper_motor#See_also</p>
<p>http://ams2000.com/stepping101.html</p>
<p>What you want are drivers from CNC machines like automated lathes, mills, and routers.  Your Arduino will be the encoder generating the pulses that tell the drivers when to move each stepper.</p>
<p>When you build your machine, you&#8217;ll need code to make it move.  My code contains a virtual model of my machine.  When I want to move the machine to XYZ, my code adjusts the virtual model, figures out where the steppers need to be to make that happen, and then instructs the Arduino what to do.  Going from model->steppers is known as Inverse Kinematics.  Forward Kinematics is when you go steppers->model: You know what the steppers are capable of and what they&#8217;re doing right now, and from that you figure out what the virtual model is doing.  It is often a lot more challenging to calculate but it pays off in other ways &#8211; like it helps you calculate how accurate your machine will be if you use parts AB&#038;C. </p>
<p>If you design your machine in a program like Alibre or SolidWorks then you&#8217;ve already got a virtual model, which makes things a lot easier.</p>
<p>More than that I can&#8217;t really tell you because<br />
a) It depends on your implementation and<br />
b) I&#8217;m in talks to build some similar machines myself</p>
<p>I hope that helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2011/11/how-do-i-drive-a-high-amp-stepper-motor-from-an-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BuildYourCNC WhiteAnt 3D Printer coming!</title>
		<link>http://www.marginallyclever.com/2011/11/buildyourcnc-whiteant-3d-printer-coming/</link>
		<comments>http://www.marginallyclever.com/2011/11/buildyourcnc-whiteant-3d-printer-coming/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 22:39:22 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[buildyourcnc]]></category>
		<category><![CDATA[buildyourcnc.com]]></category>
		<category><![CDATA[makerbot]]></category>
		<category><![CDATA[printer]]></category>
		<category><![CDATA[rapid prototyping]]></category>
		<category><![CDATA[whiteant]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=377</guid>
		<description><![CDATA[www.youtube.com/watch?v=vFLLqS0DkSc http://buildyourcnc.com/ is shipping their WhiteAnt 3D printer and mine is on the way. With an print envelope of 160mm* 190mm * 125mm, it can print objects two and a half times bigger than a Makerbot MK7. At $730, that&#8217;s 44% less expensive. Bigger prints, lower cost, DIY&#8230; I&#8217;m so excited!]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.youtube.com/watch?v=vFLLqS0DkSc">www.youtube.com/watch?v=vFLLqS0DkSc</a></p>
<p>http://buildyourcnc.com/ is shipping their WhiteAnt 3D printer and mine is on the way.  With an print envelope of 160mm* 190mm * 125mm, it can print objects two and a half times bigger than a Makerbot MK7.  At $730, that&#8217;s 44% less expensive.  Bigger prints, lower cost, DIY&#8230;  I&#8217;m so excited!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2011/11/buildyourcnc-whiteant-3d-printer-coming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling a linear actuator with an h bridge</title>
		<link>http://www.marginallyclever.com/2011/10/controlling-a-linear-actuator-with-an-h-bridge/</link>
		<comments>http://www.marginallyclever.com/2011/10/controlling-a-linear-actuator-with-an-h-bridge/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 21:34:16 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Firgelli linear actuator L16P h-bridge arduino 2560 hexapod Stewart platform Canakit solarbotics]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=365</guid>
		<description><![CDATA[www.youtube.com/watch?v=8xQ6algm8qI Canakit h bridges are twice the price of Solarbotics. Lesson learned. The secret is to use analogWrite on the output pins, works much better than Servo::write(). I want to build robots with your products and review your new hardware. If you&#8217;re looking to boost your SEO, I&#8217;m the best choice.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.youtube.com/watch?v=8xQ6algm8qI">www.youtube.com/watch?v=8xQ6algm8qI</a></p>
<p>Canakit h bridges are twice the price of Solarbotics. Lesson learned.</p>
<p>The secret is to use analogWrite on the output pins, works much better than Servo::write().</p>
<p>I want to build robots with your products and review your new hardware.  If you&#8217;re looking to boost your SEO, I&#8217;m the best choice.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2011/10/controlling-a-linear-actuator-with-an-h-bridge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hypocycloid reduction drives</title>
		<link>http://www.marginallyclever.com/2011/10/hypocycloid-reduction-drives/</link>
		<comments>http://www.marginallyclever.com/2011/10/hypocycloid-reduction-drives/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 21:34:16 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[drive]]></category>
		<category><![CDATA[equations]]></category>
		<category><![CDATA[gear]]></category>
		<category><![CDATA[gearbox]]></category>
		<category><![CDATA[hypocycloid]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[reduction]]></category>
		<category><![CDATA[reference]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=353</guid>
		<description><![CDATA[www.youtube.com/watch?v=SH46bpe1cNA http://www.thingiverse.com/thing:3617 http://www.zincland.com/hypocycloid/ Note to self: Make this into a javascript / canvas app]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.youtube.com/watch?v=SH46bpe1cNA">www.youtube.com/watch?v=SH46bpe1cNA</a></p>
<p>http://www.thingiverse.com/thing:3617</p>
<p>http://www.zincland.com/hypocycloid/</p>
<p>Note to self: Make this into a javascript / canvas app</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2011/10/hypocycloid-reduction-drives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling your Arduino through the Serial Monitor</title>
		<link>http://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/</link>
		<comments>http://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 17:10:08 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.marginallyclever.com/?p=356</guid>
		<description><![CDATA[When I&#8217;m developing Arduino code, I often have variables that need to be tweaked during testing &#038; calibration. Rather than recompile and upload the code (a time consumin process) I wrote a few lines to let me open the Serial Monitor and send commands directly. I hope you find this useful &#8211; I use it [...]]]></description>
			<content:encoded><![CDATA[<p>When I&#8217;m developing Arduino code, I often have variables that need to be tweaked during testing &#038; calibration.<br />
Rather than recompile and upload the code (a time consumin process) I wrote a few lines to let me open the Serial Monitor and send commands directly.</p>
<p>I hope you find this useful &#8211; I use it in all my robots!</p>
<pre class="brush: cpp; title: ; notranslate">
//------------------------------------------------------------------------------
// Serial Monitor control example
// dan@marginallyclever.com 2011-10-17
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// constants
//------------------------------------------------------------------------------
#define DELAY   (5)
#define BAUD    (57600)
#define MAX_BUF (64)

//------------------------------------------------------------------------------
// global variables
//------------------------------------------------------------------------------
char buffer[MAX_BUF];
int sofar;

char test_on=0;  // only used in processCommand as an example.
float pos_x;
float pos_y;
float pos_z;

//------------------------------------------------------------------------------
// methods
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
void jog(float x, float y, float z) {
  // do some tests here to validate x, y, and z.
  pos_x=x;
  pos_y=y;
  pos_z=z;
}

//------------------------------------------------------------------------------
void processCommand() {
  if(!strncmp(buffer,&quot;help&quot;,4)) {
    Serial.println(&quot;commands: where; test (1/0); jog [x(float)] [y(float)] [z(float)];&quot;);
  } else if(!strncmp(buffer,&quot;where&quot;,5)) {
    // no parameters
    Serial.print(pos_x);
    Serial.print(&quot;, &quot;);
    Serial.print(pos_y);
    Serial.print(&quot;, &quot;);
    Serial.println(pos_z);
  } else if(!strncmp(buffer,&quot;test&quot;,4)) {
    // one whole number parameter
    char *state=strchr(buffer,' ')+1;
    Serial.println(state);
    if(state[0]=='0') {
      Serial.println(&quot;End test&quot;);
      test_on=0;
    } else {
      Serial.println(&quot;Start test&quot;);
      test_on=1;
    }
  } else if(!strncmp(buffer,&quot;jog&quot;,3)) {
    // several optional float parameters.
    // then calls a method to do something with those parameters.
    float xx=pos_x;
    float yy=pos_y;
    float zz=pos_z;

    char *ptr=buffer;
    while(ptr &amp;&amp; ptr&lt;buffer+sofar) {
      ptr=strchr(ptr,' ')+1;
      switch(*ptr) {
      case 'x': case 'X': xx=atof(ptr+1);  Serial.print('x'); Serial.println(xx); break;
      case 'y': case 'Y': yy=atof(ptr+1);  Serial.print('y'); Serial.println(yy); break;
      case 'z': case 'Z': zz=atof(ptr+1);  Serial.print('z'); Serial.println(zz); break;
      default: ptr=0; break;
      }
    }

    jog(xx,yy,zz);
  }
}

//------------------------------------------------------------------------------
void setup() {
  Serial.begin(BAUD);
  Serial.println(&quot;Init...&quot;);
  Serial.println(&quot;Stretching...&quot;);

  sofar=0;
  Serial.println(&quot;** AWAKE **&quot;);
}

//------------------------------------------------------------------------------
void loop() {
  // listen for serial commands
  while(Serial.available() &gt; 0) {
    buffer[sofar++]=Serial.read();
    if(buffer[sofar-1]==';') break;  // in case there are multiple instructions
  }

  // if we hit a semi-colon, assume end of instruction.
  if(sofar&gt;0 &amp;&amp; buffer[sofar-1]==';') {
    // what if message fails/garbled?

    // echo confirmation
    buffer[sofar]=0;
    Serial.println(buffer);

    // do something with the command
    processCommand();

    // reset the buffer
    sofar=0;

    // echo completion
    Serial.println(&quot;Done.&quot;);
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

