<?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>Silveira Neto &#187; Arduino</title>
	<atom:link href="http://silveiraneto.net/tag/arduino/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description>the world is a pixel</description>
	<lastBuildDate>Sun, 08 Jan 2012 05:17:57 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Arduino The Documentary</title>
		<link>http://silveiraneto.net/2011/01/15/arduino-the-documentary/</link>
		<comments>http://silveiraneto.net/2011/01/15/arduino-the-documentary/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 20:03:18 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[documentary]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[open source hardware]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3607</guid>
		<description><![CDATA[Arduino The Documentary (2010) English HD from gnd on Vimeo. :D]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><iframe src="http://player.vimeo.com/video/18539129?title=0&amp;byline=0&amp;portrait=0" width="400" height="225" frameborder="0"></iframe>
<p><a href="http://vimeo.com/18539129">Arduino The Documentary (2010) English HD</a> from <a href="http://vimeo.com/gnd">gnd</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
</p>
<p>:D</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2011/01/15/arduino-the-documentary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BumbaBot-1</title>
		<link>http://silveiraneto.net/2009/03/16/bumbabot-1/</link>
		<comments>http://silveiraneto.net/2009/03/16/bumbabot-1/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 03:43:42 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[boi bumbá]]></category>
		<category><![CDATA[bumba meu boi]]></category>
		<category><![CDATA[bumbabot-1]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[High-Current Darlington Transistor Arrays]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Hardware]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[roboitcs]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ULN2003A]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2384</guid>
		<description><![CDATA[ ]]></description>
			<content:encoded><![CDATA[<p>I got a simple motor from a broken domestic printer. It&#8217;s a <a title="Mitsumi product" href="http://www.mitsumi.co.jp/Catalog/compo/motor/m35sp9_e.html">Mitsumi m355P-9T stepping motor</a>. Any other common stepping motor should fits. You can find one in printers, multifunction machines, copy machines, FAX, and such.</p>
<p style="text-align: center;"><a title="bumbabot v01 by Silveira Neto, on Flickr" href="http://www.flickr.com/photos/silveiraneto/3358845802/"><img class="aligncenter" src="http://farm4.static.flickr.com/3460/3358845802_286e74ee01.jpg" alt="bumbabot v01" width="500" height="375" /></a></p>
<p>With a flexible cap of water bottle with a hole we make a connection between the motor axis and other objects.</p>
<p style="text-align: center;"><a title="bumbabot v01 by Silveira Neto, on Flickr" href="http://www.flickr.com/photos/silveiraneto/3358029549/"><img class="aligncenter" src="http://farm4.static.flickr.com/3571/3358029549_0b9680180a.jpg" alt="bumbabot v01" width="500" height="375" /></a></p>
<p style="text-align: center;"><a title="bumbabot v01 by Silveira Neto, on Flickr" href="http://www.flickr.com/photos/silveiraneto/3358031295/"><img class="aligncenter" src="http://farm4.static.flickr.com/3582/3358031295_fb8ed598cc.jpg" alt="bumbabot v01" width="500" height="375" /></a></p>
<p>With super glue I attached to the cap a little handcraft clay ox statue.</p>
<p style="text-align: center;"><a title="bumbabot v01 by Silveira Neto, on Flickr" href="http://www.flickr.com/photos/silveiraneto/3358032255/"><img class="aligncenter" src="http://farm4.static.flickr.com/3612/3358032255_3686d7e295.jpg" alt="bumbabot v01" width="500" height="375" /></a></p>
<p>It&#8217;s a representation from a Brazilian folkloric character <a title="Wikipedia, english" href="http://en.wikipedia.org/wiki/Bumba_Meu_Boi">Boi Bumbá</a>. In some traditional parties in Brazil, someone dress a structure-costume and dances in circular patterns interacting with the public.</p>
<p style="text-align: center;"><a href="http://www.flickr.com/photos/canoafurada/776513346/"><img class="size-full wp-image-2392 aligncenter" title="776513346_c31db6843b_m" src="http://silveiraneto.net/wp-content/uploads/2009/03/776513346_c31db6843b_m.jpg" alt="776513346_c31db6843b_m" width="198" height="240" /></a></p>
<p style="text-align: center;"><a href="http://www.flickr.com/photos/canoafurada/2246467684/"><img class="size-full wp-image-2393 aligncenter" title="2246467684_49164d3397_m" src="http://silveiraneto.net/wp-content/uploads/2009/03/2246467684_49164d3397_m.jpg" alt="2246467684_49164d3397_m" width="240" height="160" /></a><br />
<small>Photos by <a href="http://www.flickr.com/people/canoafurada/">Marcus Guimarães</a>.</small></p>
<p>Controlling a stepper motor is not difficult.  There&#8217;s a good documentation on how to that on the <a title="Arduino Docs" href="http://www.arduino.cc/en/Tutorial/StepperUnipolar">Arduino Stepper Motor Tutorial</a>. Basically it&#8217;s about sending a logical signal for each coil in a circular order (that is also called full step).</p>
<p style="text-align: center;"><img class="size-full wp-image-2403 aligncenter" title="full step" src="http://silveiraneto.net/wp-content/uploads/2009/03/animacompleto1.gif" alt="full step" width="97" height="97" /></p>
<p style="text-align: center;"><small>Animation from <a href="http://www.rogercom.com/pparalela/IntroMotorPasso.htm">rogercom.com</a>.</small></p>
<p style="text-align: center;"><img class="size-full wp-image-2400 aligncenter" title="stepper motor diagram" src="http://silveiraneto.net/wp-content/uploads/2009/03/stepper_motor_diagram.png" alt="stepper motor diagram" width="348" height="265" /></p>
<p>You&#8217;ll probably also use a driver chip ULN2003A or similar to give to the motor more current than your Arduino can provide and also for protecting it from a power comming back from the motor. It&#8217;s a very easy find this tiny chip on electronics or automotive  stores or also from broken printers where you probably found your stepped motor.</p>
<p style="text-align: center;"><img class="size-full wp-image-2404 aligncenter" title="Arduino Stepper Motor UNL2003A" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_stepper_motor_uln2003a.jpg" alt="Arduino Stepper Motor UNL2003A" width="400" height="514" /></p>
<p>With a simple program you can already controlling your motor.</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Simple stepped motor spin</span>
<span style="color: #666666; font-style: italic;">// by Silveira Neto, 2009, under GPLv3 license</span>
<span style="color: #666666; font-style: italic;">// http://silveiraneto.net/2009/03/16/bumbabot-1/</span>
<span style="color: #993333;">int</span> coil1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">8</span>;
<span style="color: #993333;">int</span> coil2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span>;
<span style="color: #993333;">int</span> coil3 <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span>;
<span style="color: #993333;">int</span> coil4 <span style="color: #339933;">=</span> <span style="color: #0000dd;">11</span>;
<span style="color: #993333;">int</span> step <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">int</span> interval <span style="color: #339933;">=</span> <span style="color: #0000dd;">100</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>
  pinMode<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</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>
  digitalWrite<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> step<span style="color: #339933;">==</span><span style="color:#800080;">0</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> step<span style="color: #339933;">==</span><span style="color: #0000dd;">1</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> step<span style="color: #339933;">==</span><span style="color: #0000dd;">2</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> step<span style="color: #339933;">==</span><span style="color: #0000dd;">3</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  delay<span style="color: #009900;">&#40;</span>interval<span style="color: #009900;">&#41;</span>;
  step <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>step<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span><span style="color:#800080;">4</span>;
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p style="text-align: center;"><object width="425" height="344" data="http://www.youtube.com/v/roq9z3tpEhI&amp;hl=pt-br&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/roq9z3tpEhI&amp;hl=pt-br&amp;fs=1" /><param name="allowfullscreen" value="true" /></object><br />
Writing a little bit more generally code we can create function to step forward and step backward.</p>
<p>My motor needs 48 steps to run a complete turn. So 360º/48 steps give us 7,5º per step. Arduino has a simple <a title="Arduino Reference" href="http://www.arduino.cc/en/Reference/Stepper">Stepper Motor Library</a> but it doesn&#8217;t worked with me and it&#8217;s also oriented to steps and I&#8217;d need something oriented to angles instead. So I wrote some routines to do that.</p>
<p>For this first version of BumbaBot I mapped angles with letters to easy the communication between the programs.</p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-2411" title="motor angle step control" src="http://silveiraneto.net/wp-content/uploads/2009/03/motor_angle_control_map.png" alt="motor angle step control" width="300" height="236" /></p>
<p>Notice that <strong>it&#8217;s not the final version and there&#8217;s still some bugs!</strong></p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Stepped motor control by letters</span>
<span style="color: #666666; font-style: italic;">// by Silveira Neto, 2009, under GPLv3 license</span>
<span style="color: #666666; font-style: italic;">// http://silveiraneto.net/2009/03/16/bumbabot-1/</span>
&nbsp;
<span style="color: #993333;">int</span> coil1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">8</span>;
<span style="color: #993333;">int</span> coil2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span>;
<span style="color: #993333;">int</span> coil3 <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span>;
<span style="color: #993333;">int</span> coil4 <span style="color: #339933;">=</span> <span style="color: #0000dd;">11</span>;
&nbsp;
<span style="color: #993333;">int</span> delayTime <span style="color: #339933;">=</span> <span style="color: #0000dd;">50</span>;
<span style="color: #993333;">int</span> steps <span style="color: #339933;">=</span> <span style="color: #0000dd;">48</span>;
<span style="color: #993333;">int</span> step_counter <span style="color: #339933;">=</span> <span style="color:#800080;">0</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>
  pinMode<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</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: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// tells motor to move a certain angle</span>
<span style="color: #993333;">void</span> moveAngle<span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span> angle<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> i;
  <span style="color: #993333;">int</span> howmanysteps <span style="color: #339933;">=</span> angle<span style="color: #339933;">/</span>stepAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>howmanysteps<span style="color: #339933;">&lt;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    howmanysteps <span style="color: #339933;">=</span> <span style="color: #339933;">-</span> howmanysteps;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>angle<span style="color: #339933;">&gt;</span><span style="color:#800080;">0</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>i <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;i<span style="color: #339933;">&lt;</span>howmanysteps; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      step<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span><span style="color:#800080;">4</span><span style="color: #009900;">&#41;</span>;
      delay<span style="color: #009900;">&#40;</span>delayTime<span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color:#800080;">0</span>;i<span style="color: #339933;">&lt;</span>howmanysteps;i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      backstep<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span><span style="color:#800080;">4</span><span style="color: #009900;">&#41;</span>;
      delay<span style="color: #009900;">&#40;</span>delayTime<span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// tells motor to move to a certain angle</span>
<span style="color: #993333;">void</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span> angle<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  moveAngle<span style="color: #009900;">&#40;</span>angle<span style="color: #339933;">-</span>actualAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// actual stepper motor angle</span>
<span style="color: #993333;">float</span> actualAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> step_counter<span style="color: #339933;">*</span>stepAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// angle made by each step</span>
<span style="color: #993333;">float</span> stepAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color:#800080;">360.0</span><span style="color: #339933;">/</span>steps;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// backward step</span>
<span style="color: #993333;">void</span> backstep<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> coil<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  step_counter--;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// forward step</span>
<span style="color: #993333;">void</span> step<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> coil<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span>;
  step_counter++;
<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>
  byte val;
  <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: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    val <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: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'A'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span>  <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">break</span>;
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'B'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">45</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">break</span>;
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'C'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">90</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">break</span>;
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'D'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">135</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">break</span>;
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'E'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">180</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">break</span>;
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'F'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">225</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">break</span>;
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'G'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">270</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">break</span>;
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'H'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">315</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">break</span>;
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'I'</span><span style="color: #339933;">:</span> backstep<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>; backstep<span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">break</span>;
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'J'</span><span style="color: #339933;">:</span> step<span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>; step<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>;   <span style="color: #000000; font-weight: bold;">break</span>;
    <span style="color: #009900;">&#125;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>In another post I wrote <a title="Arduino and Java" href="http://silveiraneto.net/2009/03/01/arduino-and-java/">how create a Java program to talk with Arduino</a>. We&#8217;ll use this to send messages to Arduino to it moves. </p>
<p style="text-align: center;"><img src="http://silveiraneto.net/wp-content/uploads/2009/03/captura_de_tela-bumba01-netbeans-ide-65-500x283.png" alt="captura_de_tela-bumba01-netbeans-ide-65" title="captura_de_tela-bumba01-netbeans-ide-65" width="500" height="283" class="alignnone size-medium wp-image-2416" /></p>
<p>[put final video here]</p>
<p><strong>To be continued&#8230; </strong>:)</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/03/16/bumbabot-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arduino and Java</title>
		<link>http://silveiraneto.net/2009/03/01/arduino-and-java/</link>
		<comments>http://silveiraneto.net/2009/03/01/arduino-and-java/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 02:31:34 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Comm]]></category>
		<category><![CDATA[Dave Brink]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[Robotics]]></category>
		<category><![CDATA[RXTX]]></category>
		<category><![CDATA[Serial]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2344</guid>
		<description><![CDATA[Arduino is a free popular platform for embedded programming based on a simple I/O board easily programmable. Interfacing it with Java allow us to create sophisticated interfaces and take advantages from the several API available in the Java ecosystem. I&#8217;m following the original Arduino and Java interfacing tutorial by Dave Brink but in a more [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino.png"><img class="size-full wp-image-2356 aligncenter" title="Arduino" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino.png" alt="Arduino" width="559" height="316" /></a></p>
<p><a title="Arduino Project" href="http://arduino.cc">Arduino</a> is a free popular platform for embedded programming based on a simple I/O board easily programmable. Interfacing it with Java allow us to create sophisticated interfaces and take advantages from the several API available in the Java ecosystem.</p>
<p><small>I&#8217;m following the original <a title="Dave Brink" href="http://www.arduino.cc/playground/Interfacing/Java">Arduino and Java interfacing tutorial by Dave Brink</a> but in a more practical approach and with more details.</small></p>
<p><strong>Step 1) Install the Arduino IDE</strong></p>
<p>This is not a completely mandatory step but it will easy a lot our work. Our program will borrow some <a title="Arduino Software" href="http://arduino.cc/en/Main/Software">Arduino IDE</a> libraries and configurations  like which serial port it is using and at which <a title="Boud Rate at Wikipedia" href="http://en.wikipedia.org/wiki/Baud">boud rate</a>. At the moment I wrote this tutorial the version of Arduino IDE was 0013.</p>
<p><strong>Step 2) Prepare your Arduino</strong></p>
<p>Connect your Arduino to the serial port in your computer. Here I&#8217;m connecting my Arduino with my laptop throught a USB.</p>
<pre style="text-align: center;" lang="C"><img src="http://farm4.static.flickr.com/3562/3321316792_993cbff274.jpg" alt="Arduino" /></pre>
<p>Make sure your Arduino IDE is configured and communicating well if your Arduino. Let put on it a little program that sends to us a mensage:</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><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;">9600</span><span style="color: #009900;">&#41;</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>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Is there anybody out there?&quot;</span><span style="color: #009900;">&#41;</span>;
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p><strong>Step 3) Install RXTX Library</strong></p>
<p>We will use some libraries to acess the serial port, some of them relies on binary implementations on our system. Our first step is to install the <a title="RXTX" href="http://www.rxtx.org/">RXTX library</a> (Java CommAPI) in your system. In a Debian like Linux you can do that by:</p>
<blockquote><p>sudo apt-get install librxtx-java</p></blockquote>
<p>Or using a graphical package tool like Synaptic:</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_00.png"><img class="size-medium wp-image-2345 aligncenter" title="installing rxtx" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_00-500x296.png" alt="installing rxtx" width="500" height="296" /></a></p>
<p>For others systems like Windows see the <a title="RXTX Install" href="http://rxtx.qbang.org/wiki/index.php/Installation">RXTX installation docs</a>.</p>
<p><strong>Step 4) Start a new NetBeans project</strong></p>
<p>Again<strong>,</strong> this is not a mandatory step but will easy a lot our work. <a href="http://netbeans.org">NetBeans</a> is a free and open source Java IDE that will help us to develop our little application. Create a new project at <em>File → New Project</em> and choose at <em>Java</em> at <em>Categories </em>and <em>Java Application</em> at <em>Projects</em>.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_01.png"><img class="size-medium wp-image-2346 aligncenter" title="netbeans new project" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_01-500x323.png" alt="netbeans new project" width="500" height="323" /></a></p>
<p>Chose a name for your project. I called mine <em>SerialTalker</em>.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_02.png"><img class="size-medium wp-image-2347 aligncenter" title="name your project" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_02-500x314.png" alt="name your project" width="500" height="314" /></a></p>
<p><small>At the moment I wrote this tutorial I was using Netbeans version 6.5 and Java 6 update 10 but should work as well on newer and some older versions</small></p>
<p><strong>Step 5) Adding Libraries and a Working Directory<br />
</strong></p>
<p>On NetBeans the <em>Projects</em> tab, right-click your project and choose <em>Properties</em>.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_03.png"><img class="size-medium wp-image-2348 aligncenter" title="libraries" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_03-500x283.png" alt="libraries" width="500" height="283" /></a></p>
<p>On the <em>Project Properties</em> window select the <em>Libraries</em> on the <em>Categories</em> panel.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_04.png"><img class="size-medium wp-image-2349 aligncenter" title="Netbeans project libraries" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_04-499x340.png" alt="Netbeans project libraries" width="499" height="340" /></a></p>
<p>Click the <em>Add JAR/Folder</em> button.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_05.png"><img class="size-medium wp-image-2350 aligncenter" title="arduino directory" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_05-500x307.png" alt="arduino directory" width="500" height="307" /></a></p>
<p>Find where you placed your Arduino IDE installation. Inside this directory there&#8217;s a lib directory will some JAR files. Select all them and click <em>Ok</em>.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_06.png"><img class="size-medium wp-image-2351" title="jars libraries" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_06-500x307.png" alt="jars libraries" width="500" height="307" /></a></p>
<p>As we want to borrow the Arduino IDE configuration the program needs to know where is they configuration files.  There&#8217;s a simple way to do that.</p>
<p>Still in the  <em>Project Properties</em> window select <em>Run</em> at <em>Categories</em> panel. At <em>Working Directory</em> click in the <em>Browse</em> button and select the directory of your Arduino IDE. Mine is at <em>/home/silveira/arduino-0013</em>.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_08.png"><img class="size-medium wp-image-2353 aligncenter" title="Working directory" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_08-499x340.png" alt="Working directory" width="499" height="340" /></a></p>
<p>You can close now the <em>Project Properties</em> window. At this moment in autocomplete for these libraries are enable in your code.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_07.png"><img class="size-medium wp-image-2352 aligncenter" title="netbeans autocomplete" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_07-500x283.png" alt="netbeans autocomplete" width="500" height="283" /></a></p>
<p><strong>Step 6) Codding and running</strong></p>
<p>Here is the code you can replace at Main.java in your project:</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;">package serialtalk;
&nbsp;
import gnu.<span style="color: #202020;">io</span>.<span style="color: #202020;">CommPortIdentifier</span>;
import gnu.<span style="color: #202020;">io</span>.<span style="color: #202020;">SerialPort</span>;
import java.<span style="color: #202020;">io</span>.<span style="color: #202020;">InputStream</span>;
import java.<span style="color: #202020;">io</span>.<span style="color: #202020;">OutputStream</span>;
import processing.<span style="color: #202020;">app</span>.<span style="color: #202020;">Preferences</span>;
&nbsp;
public class Main <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">static</span> InputStream input;
    <span style="color: #993333;">static</span> OutputStream output;
&nbsp;
    public <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> throws Exception<span style="color: #009900;">&#123;</span>
        Preferences.<span style="color: #202020;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        System.<span style="color: #202020;">out</span>.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Using port: &quot;</span> <span style="color: #339933;">+</span> Preferences.<span style="color: #202020;">get</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;serial.port&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
        CommPortIdentifier portId <span style="color: #339933;">=</span> CommPortIdentifier.<span style="color: #202020;">getPortIdentifier</span><span style="color: #009900;">&#40;</span>
                Preferences.<span style="color: #202020;">get</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;serial.port&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
        SerialPort port <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SerialPort<span style="color: #009900;">&#41;</span>portId.<span style="color: #202020;">open</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;serial talk&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">4000</span><span style="color: #009900;">&#41;</span>;
        input <span style="color: #339933;">=</span> port.<span style="color: #202020;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        output <span style="color: #339933;">=</span> port.<span style="color: #202020;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        port.<span style="color: #202020;">setSerialPortParams</span><span style="color: #009900;">&#40;</span>Preferences.<span style="color: #202020;">getInteger</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;serial.debug_rate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                SerialPort.<span style="color: #202020;">DATABITS_8</span><span style="color: #339933;">,</span>
                SerialPort.<span style="color: #202020;">STOPBITS_1</span><span style="color: #339933;">,</span>
                SerialPort.<span style="color: #202020;">PARITY_NONE</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</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>input.<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:#800080;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                System.<span style="color: #202020;">out</span>.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>input.<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: #009900;">&#41;</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>
<p>Now just compile and run (with your Arduino attached in your serial port and running the program of step 2).</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_09.png"><img class="size-medium wp-image-2354 aligncenter" title="voillá" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_java_netbeans_09-500x283.png" alt="voillá" width="500" height="283" /></a></p>
<p>There is. Now you can make your Java programs to talk with your Arduino using a IDE like NetBeans to create rich interfaces.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/03/01/arduino-and-java/feed/</wfw:commentRss>
		<slash:comments>73</slash:comments>
		</item>
		<item>
		<title>Morse Code Translator with Arduino</title>
		<link>http://silveiraneto.net/2009/02/28/morse-code-translator-with-arduino/</link>
		<comments>http://silveiraneto.net/2009/02/28/morse-code-translator-with-arduino/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 16:16:58 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[buzzer]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Diecimila]]></category>
		<category><![CDATA[embedded device]]></category>
		<category><![CDATA[Free Software]]></category>
		<category><![CDATA[Freeduino]]></category>
		<category><![CDATA[Open Hardware]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sound]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2328</guid>
		<description><![CDATA[You write in your computer, sends a message thought USB and Arduino translates it into a Morse code. Just a Arduino board with a buzzer connected at the digital output 12 (one wire in the ground and the other in the 12). I tried to make the code as general as possible so you can [...]]]></description>
			<content:encoded><![CDATA[<p>You write in your computer, sends a message thought USB and Arduino translates it into a <a href="http://en.wikipedia.org/wiki/Morse_code">Morse code</a>.</p>
<p style="text-align: center;"><object width="425" height="344" data="http://www.youtube.com/v/1_X5AwVrkUo&amp;hl=pt-br&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/1_X5AwVrkUo&amp;hl=pt-br&amp;fs=1" /><param name="allowfullscreen" value="true" /></object></pre>
<p>Just a Arduino board with a buzzer connected at the digital output 12 (one wire in the ground and the other in the 12).</p>
<p style="text-align: center;"><img src='http://farm4.static.flickr.com/3495/3315777991_75f0f92578.jpg' alt='Arduino'/></pre>
<p>I tried to make the code as general as possible so you can easily adapt it for anthers ways of transmitting a Morse code. To do that you just need to rewrite a few functions.</p>
<p style="text-align: center;">
<pre>
                                                  +-------------------+
                                                  | 3) Interpretation |
                                                  +-------------------+
                                                  |   2) Translation  |
+-------------------+                             +-------------------+
|     Computer      |<========USB (Serial)=======>|     1) Reading    |
+-------------------+                             +-------------------+
</pre>
</p>
<ol>
<li>Reads a character from Serial. Main function loop().</li>
<li>Translate a ascii char into a Morse code using a reference table. A letter 'K' becomes a string word "-.-". Function say_char().</li>
<li>Interpret the Morse word as light and sound. Mostly at function say_morse_word(). The Interpretation needs 5 functions to say all Morse words, dot(), dash(), shortgap(), mediumgap() and intragap().</li>
</ol>
<p>For a more details on Morse code I strongly recommend the <a href="http://en.wikipedia.org/wiki/Morse_code">English Wikipedia article on it</a>.</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><span style="color: #993333;">int</span> led <span style="color: #339933;">=</span> <span style="color: #0000dd;">13</span>;                   <span style="color: #666666; font-style: italic;">// LED connected to digital pin 13</span>
<span style="color: #993333;">int</span> buzzer <span style="color: #339933;">=</span> <span style="color: #0000dd;">12</span>;                <span style="color: #666666; font-style: italic;">// buzzer connected to digital pin 12</span>
<span style="color: #993333;">int</span> unit <span style="color: #339933;">=</span> <span style="color: #0000dd;">50</span>;                  <span style="color: #666666; font-style: italic;">// duration of a pulse</span>
&nbsp;
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span> morsecode<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: #ff0000;">&quot;-----&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 0</span>
    <span style="color: #ff0000;">&quot;.----&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 1</span>
    <span style="color: #ff0000;">&quot;..---&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 2</span>
    <span style="color: #ff0000;">&quot;...--&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 3</span>
    <span style="color: #ff0000;">&quot;....-&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 4</span>
    <span style="color: #ff0000;">&quot;.....&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 5</span>
    <span style="color: #ff0000;">&quot;-....&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 6 </span>
    <span style="color: #ff0000;">&quot;--...&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 7</span>
    <span style="color: #ff0000;">&quot;---..&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 8</span>
    <span style="color: #ff0000;">&quot;----.&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// 9</span>
    <span style="color: #ff0000;">&quot;---...&quot;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// :</span>
    <span style="color: #ff0000;">&quot;-.-.-.&quot;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// ;</span>
    <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">,</span>       <span style="color: #666666; font-style: italic;">// &lt; (there's no morse for this simbol)</span>
    <span style="color: #ff0000;">&quot;-...-&quot;</span><span style="color: #339933;">,</span>  <span style="color: #666666; font-style: italic;">// =</span>
    <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">,</span>       <span style="color: #666666; font-style: italic;">// &gt; (there's no morse for this simbol)</span>
    <span style="color: #ff0000;">&quot;..--..&quot;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// ?</span>
    <span style="color: #ff0000;">&quot;.--._.&quot;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// @</span>
    <span style="color: #ff0000;">&quot;.-&quot;</span><span style="color: #339933;">,</span>     <span style="color: #666666; font-style: italic;">// A</span>
    <span style="color: #ff0000;">&quot;-...&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// B</span>
    <span style="color: #ff0000;">&quot;-.-.&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// C</span>
    <span style="color: #ff0000;">&quot;-..&quot;</span><span style="color: #339933;">,</span>    <span style="color: #666666; font-style: italic;">// D</span>
    <span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #339933;">,</span>      <span style="color: #666666; font-style: italic;">// E</span>
    <span style="color: #ff0000;">&quot;..-.&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// F</span>
    <span style="color: #ff0000;">&quot;--.&quot;</span><span style="color: #339933;">,</span>    <span style="color: #666666; font-style: italic;">// G</span>
    <span style="color: #ff0000;">&quot;....&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// H</span>
    <span style="color: #ff0000;">&quot;..&quot;</span><span style="color: #339933;">,</span>     <span style="color: #666666; font-style: italic;">// I</span>
    <span style="color: #ff0000;">&quot;.---&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// J</span>
    <span style="color: #ff0000;">&quot;-.-&quot;</span><span style="color: #339933;">,</span>    <span style="color: #666666; font-style: italic;">// K</span>
    <span style="color: #ff0000;">&quot;.-..&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// L</span>
    <span style="color: #ff0000;">&quot;--&quot;</span><span style="color: #339933;">,</span>     <span style="color: #666666; font-style: italic;">// M</span>
    <span style="color: #ff0000;">&quot;-.&quot;</span><span style="color: #339933;">,</span>     <span style="color: #666666; font-style: italic;">// N</span>
    <span style="color: #ff0000;">&quot;---&quot;</span><span style="color: #339933;">,</span>    <span style="color: #666666; font-style: italic;">// O</span>
    <span style="color: #ff0000;">&quot;.--.&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// P</span>
    <span style="color: #ff0000;">&quot;--.-&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// Q</span>
    <span style="color: #ff0000;">&quot;.-.&quot;</span><span style="color: #339933;">,</span>    <span style="color: #666666; font-style: italic;">// R</span>
    <span style="color: #ff0000;">&quot;...&quot;</span><span style="color: #339933;">,</span>    <span style="color: #666666; font-style: italic;">// S</span>
    <span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #339933;">,</span>      <span style="color: #666666; font-style: italic;">// T</span>
    <span style="color: #ff0000;">&quot;..-&quot;</span><span style="color: #339933;">,</span>    <span style="color: #666666; font-style: italic;">// U</span>
    <span style="color: #ff0000;">&quot;...-&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// V</span>
    <span style="color: #ff0000;">&quot;.--&quot;</span><span style="color: #339933;">,</span>    <span style="color: #666666; font-style: italic;">// W</span>
    <span style="color: #ff0000;">&quot;-..-&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// X</span>
    <span style="color: #ff0000;">&quot;-.--&quot;</span><span style="color: #339933;">,</span>   <span style="color: #666666; font-style: italic;">// Y</span>
    <span style="color: #ff0000;">&quot;--..&quot;</span>    <span style="color: #666666; font-style: italic;">// Z</span>
<span style="color: #009900;">&#125;</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>
  pinMode<span style="color: #009900;">&#40;</span>led<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>buzzer<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</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: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> say_morse_word<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span> msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> index <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">!=</span><span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\0</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// say a dash</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      dash<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// say a dot</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      dot<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// gap beetween simbols</span>
    intragap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    index++;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// beep</span>
<span style="color: #993333;">void</span> beep<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> time<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> i;
  <span style="color: #993333;">int</span> t <span style="color: #339933;">=</span> <span style="color: #0000dd;">100</span>; <span style="color: #666666; font-style: italic;">// period of the wav. bigger means lower pitch.</span>
  <span style="color: #993333;">int</span> beepduration <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span>time<span style="color: #339933;">/</span>t<span style="color: #339933;">*</span><span style="color: #0000dd;">1800</span><span style="color: #009900;">&#41;</span>;
  digitalWrite<span style="color: #009900;">&#40;</span>led<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span>;
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color:#800080;">0</span>;i<span style="color: #339933;">&lt;</span>beepduration;i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>buzzer<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span>;
    delayMicroseconds<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span>;
    digitalWrite<span style="color: #009900;">&#40;</span>buzzer<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span>;
    delayMicroseconds<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
  delay<span style="color: #009900;">&#40;</span>time<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// silence</span>
<span style="color: #993333;">void</span> silence<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> time<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>led<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span>;
  delay<span style="color: #009900;">&#40;</span>time<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// general procedure for .</span>
<span style="color: #993333;">void</span> dot<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  beep<span style="color: #009900;">&#40;</span>unit<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// general procedure for -</span>
<span style="color: #993333;">void</span> dash<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  beep<span style="color: #009900;">&#40;</span>unit<span style="color: #339933;">*</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// gap between dots and dashes</span>
<span style="color: #993333;">void</span> intragap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  silence<span style="color: #009900;">&#40;</span>unit<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// gap between letters</span>
<span style="color: #993333;">void</span> shortgap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  silence<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #339933;">*</span>unit<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// gap be  tween words</span>
<span style="color: #993333;">void</span> mediumgap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  silence<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">7</span><span style="color: #339933;">*</span>unit<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> say_char<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> letter<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>letter<span style="color: #339933;">&gt;=</span><span style="color: #ff0000;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>letter<span style="color: #339933;">&lt;=</span><span style="color: #ff0000;">'Z'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>letter<span style="color: #339933;">!=</span><span style="color: #ff0000;">'&lt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>letter<span style="color: #339933;">!=</span><span style="color: #ff0000;">'&gt;'</span><span style="color: #009900;">&#41;</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>morsecode<span style="color: #009900;">&#91;</span>letter<span style="color: #339933;">-</span><span style="color: #ff0000;">'0'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">' '</span><span style="color: #009900;">&#41;</span>;
    say_morse_word<span style="color: #009900;">&#40;</span>morsecode<span style="color: #009900;">&#91;</span>letter<span style="color: #339933;">-</span><span style="color: #ff0000;">'0'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
    shortgap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>letter<span style="color: #339933;">==</span><span style="color: #ff0000;">' '</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; <span style="color: #000099; font-weight: bold;">\\</span> &quot;</span><span style="color: #009900;">&#41;</span>;
      mediumgap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</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;X&quot;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</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>Serial.<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>
    say_char<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>Additionally you can put another function to say entire strings, like say_string("HELLO WORLD")</p>
<div class="wp_syntax">
<div class="code">
<pre class="c c" style="font-family:monospace;"><span style="color: #993333;">void</span> say_string<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span> asciimsg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> index <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
  <span style="color: #993333;">char</span> charac;
  charac <span style="color: #339933;">=</span> asciimsg<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span>;
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>charac<span style="color: #339933;">!=</span><span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\0</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    say_char<span style="color: #009900;">&#40;</span>morsecode<span style="color: #009900;">&#91;</span>charac<span style="color: #339933;">-</span><span style="color: #ff0000;">'0'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>morsecode<span style="color: #009900;">&#91;</span>charac<span style="color: #339933;">-</span><span style="color: #ff0000;">'0'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
    charac <span style="color: #339933;">=</span> asciimsg<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>index<span style="color: #009900;">&#93;</span>;
    shortgap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>You can use the Arduino IDE itself or any other program that talks with the serial port USB.</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2009/02/arduino_interface.png"><img src="http://silveiraneto.net/wp-content/uploads/2009/02/arduino_interface.png" alt="arduino interface" title="arduino interface" width="545" height="585" class="alignnone size-full wp-image-2342" /></a></pre>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/02/28/morse-code-translator-with-arduino/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Arduino on Ubuntu</title>
		<link>http://silveiraneto.net/2009/02/28/arduino-on-ubuntu/</link>
		<comments>http://silveiraneto.net/2009/02/28/arduino-on-ubuntu/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 15:47:10 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Robótica Livre]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2322</guid>
		<description><![CDATA[My Arduinos arrived yesterday. It&#8217;s a programmable open source and hardware device. To install its software on my Ubuntu 8.10 I need Java installed and some tools that I could get by: sudo apt-get install avrdude avrdude-doc avrp avrprog binutils-avr gcc-avr]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" src="http://farm4.static.flickr.com/3046/3316603870_1ff6620246.jpg" alt="Arduinos" /></p>
<p>My Arduinos arrived yesterday. It&#8217;s a programmable open source and hardware device.</p>
<p>To install <a title="Arduino Software Download" href="http://arduino.cc/en/Main/Software">its software</a> on my Ubuntu 8.10 I need Java installed and some tools that I could get by:</p>
<blockquote><p>sudo apt-get install avrdude avrdude-doc avrp avrprog binutils-avr gcc-avr</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/02/28/arduino-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

