<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://labs.echoditto.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>EchoDitto Labs - making a FON router speak serial to Arduino - Comments</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2</link>
 <description>Comments for &quot;making a FON router speak serial to Arduino&quot;</description>
 <language>en</language>
<item>
 <title>@jinx
I am looking for an</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2#comment-3969</link>
 <description>&lt;p&gt;@jinx&lt;/p&gt;
&lt;p&gt;I am looking for an answer to that same question. I found this thread, with the same problem but no solution yet: &lt;a href=&quot;http://www.dd-wrt.com/phpBB2/viewtopic.php?p=152365&amp;amp;sid=dbe9ad84aa25097fac532dfce8f1db66&quot; title=&quot;http://www.dd-wrt.com/phpBB2/viewtopic.php?p=152365&amp;amp;sid=dbe9ad84aa25097fac532dfce8f1db66&quot;&gt;http://www.dd-wrt.com/phpBB2/viewtopic.php?p=152365&amp;amp;sid=dbe9ad84aa25097f...&lt;/a&gt;&lt;/p&gt;
</description>
 <pubDate>Tue, 10 Jun 2008 19:18:38 -0700</pubDate>
 <dc:creator>Dylan V</dc:creator>
 <guid isPermaLink="false">comment 3969 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>Hello. I&#039;ve got one</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2#comment-3968</link>
 <description>&lt;p&gt;Hello. I&#039;ve got one question, how did you turn off the BusyBox shell on serial (console) on fonera with dd-wrt? I have also linksys wrt54gl with openwrt, where i can simply comment out one line in /etc/inittab which solves the problem, but on DD-WRT (fonera) i can&#039;t find this file. Is there any other way? &lt;/p&gt;
&lt;p&gt;greetings&lt;br /&gt;
jinx&lt;/p&gt;
</description>
 <pubDate>Tue, 10 Jun 2008 14:38:23 -0700</pubDate>
 <dc:creator>jinx</dc:creator>
 <guid isPermaLink="false">comment 3968 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>OK, I installed the exact</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2#comment-3967</link>
 <description>&lt;p&gt;OK, I installed the exact version of DD-WRT that you have, and stty is indeed there and working for me. I wonder why they took it out... I will have to find the latest version that still has it in order to be as current as possible with bugfixes, etc. Thanks again!&lt;/p&gt;
</description>
 <pubDate>Fri, 06 Jun 2008 11:45:49 -0700</pubDate>
 <dc:creator>Dylan V</dc:creator>
 <guid isPermaLink="false">comment 3967 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>No sight of stty in those</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2#comment-3965</link>
 <description>&lt;p&gt;No sight of stty in those locations. I think the problem is that BusyBox (the shell) was compiles w/o stty.&lt;/p&gt;
&lt;p&gt;I will download the exact version of firmware you have and try it out. Thanks for the advice, and wish me luck!&lt;/p&gt;
&lt;p&gt;PS There is now an active forum thread on the topic, but so far we&#039;ve gotten pretty much nowhere.&lt;/p&gt;
</description>
 <pubDate>Tue, 03 Jun 2008 23:17:57 -0700</pubDate>
 <dc:creator>Dylan V</dc:creator>
 <guid isPermaLink="false">comment 3965 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>Tcid: I didn&#039;t actually send</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2#comment-3963</link>
 <description>&lt;p&gt;Tcid: I didn&#039;t actually send any commands to the Fonera (except through SSH, and by setting up startup scripts in DD-WRT on the Fonera).  In this configuration it simply sends commands to the Arduino.&lt;/p&gt;
&lt;p&gt;It should be possible to have Arduino speak to the Fonera via a serial connection, but I&#039;m afraid that&#039;s beyond the scope of this post.&lt;/p&gt;
</description>
 <pubDate>Tue, 03 Jun 2008 12:30:27 -0700</pubDate>
 <dc:creator>Tom</dc:creator>
 <guid isPermaLink="false">comment 3963 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>Hmm -- that&#039;s curious.  I am</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2#comment-3962</link>
 <description>&lt;p&gt;Hmm -- that&#039;s curious.  I am running &lt;a href=&quot;http://www.dd-wrt.com/dd-wrtv2/down.php?path=downloads%2Fbeta%2FFONERA%2F2007+-+0803/&quot;&gt;this firmware&lt;/a&gt;.  Have you checked the /bin, /sbin and /usr/sbin directories?&lt;/p&gt;
&lt;p&gt;I&#039;m afraid I haven&#039;t got a Fonera handy to check where the executable lives.  You may have luck asking on the DD-WRT forums, though -- those folks know much more about the firmware than I do.&lt;/p&gt;
</description>
 <pubDate>Tue, 03 Jun 2008 12:28:56 -0700</pubDate>
 <dc:creator>Tom</dc:creator>
 <guid isPermaLink="false">comment 3962 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>Hello,
I have successfully</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2#comment-3961</link>
 <description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I have successfully installed DD-WRT on my Fonera, but there is one problem: there is no stty command! What version of DD-WRT are you using?&lt;/p&gt;
</description>
 <pubDate>Mon, 02 Jun 2008 16:28:48 -0700</pubDate>
 <dc:creator>Dylan V</dc:creator>
 <guid isPermaLink="false">comment 3961 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>Outstanding! I have several</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2#comment-3956</link>
 <description>&lt;p&gt;Outstanding! I have several foneras around all running dd-wrt and just got my first arduino the other day. I started looking into the Botanicalls system and wondered if anyone had tried connecting the fonera - and here it is!&lt;/p&gt;
&lt;p&gt;Please post updates to this project as you can. I know I will be trying this out very soon.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description>
 <pubDate>Mon, 26 May 2008 06:32:40 -0700</pubDate>
 <dc:creator>youevolve</dc:creator>
 <guid isPermaLink="false">comment 3956 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>Hi Tom,
thanks for this nice</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2#comment-3908</link>
 <description>&lt;p&gt;Hi Tom,&lt;br /&gt;
thanks for this nice post!&lt;/p&gt;
&lt;p&gt;I don&#039;t understand how you managed to send commands to La Fonera through Arduino.&lt;br /&gt;
I tried several connections but they all failed!&lt;/p&gt;
&lt;p&gt;Thank you,&lt;/p&gt;
</description>
 <pubDate>Sun, 23 Mar 2008 17:51:03 -0700</pubDate>
 <dc:creator>Tcid</dc:creator>
 <guid isPermaLink="false">comment 3908 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>making a FON router speak serial to Arduino</title>
 <link>http://labs.echoditto.com/hacking-la-fonera-2</link>
 <description>&lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/sbma44/2118599307/&quot; title=&quot;my arduino and my fonera, doin&#039; it by sbma44, on Flickr&quot;&gt;&lt;img style=&quot;float:right; margin: 5px;&quot; src=&quot;http://farm3.static.flickr.com/2267/2118599307_1058415818_m.jpg&quot; width=&quot;180&quot; height=&quot;240&quot; alt=&quot;my arduino and my fonera, doin&#039; it&quot; class=&quot;right&quot; /&gt;&lt;/a&gt;Wow.  For the first time in my life I&#039;ve undertaken an electronics project and had it immediately work.  I&#039;m still a little shaken by the experience.&lt;/p&gt;

&lt;p&gt;As you might recall, in my &lt;a href=&quot;http://labs.echoditto.com/hacking-la-fonera&quot;&gt;last post&lt;/a&gt; I discussed loading the custom, Linux-based DD-WRT firmware onto the Fonera router.  I left off with some thoughts about using that environment to achieve serial communication with an Arduino.&lt;/p&gt;

&lt;p&gt;Getting the Fonera to talk to my Arduino turned out to be shockingly easy.  The 2200 Fonera model has a four-pin header exposed.  The pin closest to the ethernet port is ground; next is serial receive; then comes serial transmit.  I scrounged up a female pin header connector from a USB break-out bezel I had lying around (already half-cannibalized &amp;mdash; last year I&#039;d used the USB end to make the cable necessary for &lt;a href=&quot;http://ashholt.googlepages.com/xboxsoftmod&quot;&gt;softmodding the office Xbox&lt;/a&gt;).  That makes the photo to the right look a bit messier than it needs to.  In truth I simply connected ground to ground, then the Fonera transmit pin to the Arduino receive pin.&lt;/p&gt;

&lt;p&gt;The Arduino software environment&#039;s serial monitor only displays transmitted data, so I whipped up a quick program to read incoming data and echo it back out on the transmit pin (which wasn&#039;t connected to anything, but the Arduino&#039;s serial output is picked up by my macbook through the USB connection).  You can see the program in the picture below.  You can also see the result I got when booting up the Fonera:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;a href=&quot;http://www.flickr.com/photos/sbma44/2114200616/&quot; title=&quot;fonera talking to arduino -- serial monitor by sbma44, on Flickr&quot;&gt;&lt;img src=&quot;http://farm3.static.flickr.com/2097/2114200616_ae196432f4_o.jpg&quot; width=&quot;495&quot; height=&quot;609&quot; alt=&quot;fonera talking to arduino -- serial monitor&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It worked!  First you see the bootloader, then a bunch of garbage.  That&#039;s nothing to worry about, though.  The bootloader runs at 9600 baud, which is what I had the Arduino serial link configured to expect.  Once the bootloader is done, the DD-WRT environment takes over, and it ramps the serial port&#039;s speed up to 115200 baud, producing the cloud of gibberish that follows the bootloader.&lt;/p&gt;

&lt;p&gt;Fortunately, that&#039;s easy to fix with the stty command:&lt;/p&gt;

&lt;!--break--&gt;

&lt;blockquote&gt;&lt;pre&gt;stty -F /dev/tts/0 9600&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;This sets the serial port&#039;s speed back to 9600.  As you might have inferred, the serial port in the DD-WRT environment sits at /dev/tts/0.  You can use that address to send commands over the serial link:&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;echo &quot;it worked! w00t!&quot; &amp;gt; /dev/tts/0&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;That&#039;ll get sent into the Arduino&#039;s waiting arms, as you can see at the end of the ASCII garbage (I didn&#039;t send another command before taking the screenshot, but the echoed content ends with a newline, making subsequent commands much easier to pick out).&lt;/p&gt;

&lt;p&gt;So to complete this system all I have to do is: add the &lt;em&gt;stty&lt;/em&gt; command to the DD-WRT startup scripts; set up a DD-WRT cron job to run a script that checks a remote resource and sends the result, via the serial port, to the Arduino; and write an Arduino program that reads that data from the serial port and executes commands when it finds actionable data.&lt;/p&gt;

&lt;p&gt;But cron jobs can only run once a minute.  What if we want to poll the remote resource more frequently?  There&#039;s no Perl, Ruby or Python available on the Fonera, nor any Netcat.  Fortunately, there&#039;s wget.  Combined with some specialized PHP, I was able to get a (very) poor-man&#039;s &lt;a href=&quot;http://cometdaily.com/2007/12/11/the-future-of-comet-part-1-comet-today/&quot;&gt;Comet&lt;/a&gt; system running &amp;mdash; even on my commodity shared webhost (I could&#039;ve run a custom daemon on EchoDitto&#039;s servers, of course, but I figured I might as well try to make this as universally accessible as possible).&lt;/p&gt;

&lt;pre&gt;&lt;blockquote&gt;&amp;lt;?php
ini_set(&#039;max_execution_time&#039;,60);
for($i=0;$i&amp;lt;60;$i++)
{
        print &quot;###&quot; . $i . &quot;\n&quot;;

        ob_flush();
        flush();

        sleep(1);
}
?&amp;gt;&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;The three hash marks are there for the benefit of the Arduino &amp;mdash; I&#039;ll set it up to keep a rolling buffer of the last &lt;em&gt;n&lt;/em&gt; bytes of serial data, and check the first three bytes every time it adds a new character.  When those bytes match &quot;###&quot; it&#039;ll know to process the rest of the buffer (which will, presumably, contain something more interesting than a simple per-second counter).  The only other notable parts of the script are the first line, which tries to ensure that the server doesn&#039;t kill the request before its sixty second run is over; and the flush() lines, which tell Apache to send the Fonera the response so far rather than waiting until it&#039;s fully composed.&lt;/p&gt;

&lt;p&gt;I&#039;ll connect to this script on a remote server with an every-minute cron script that looks something like this:&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;killall wget
wget -q -O - http://my.server/script.php &amp;gt; /dev/tts/0&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;And that&#039;s it!  Admittedly, I haven&#039;t yet piped this output to the Arduino to do something useful.  But it works like a charm from the console, and, in combination with the serial echo program, constitutes proof-of-concept validation for each part of my planned application.&lt;/p&gt;

&lt;p&gt;One-second resolution seems likely to be more than adequate for any of the monitoring tasks I have in mind.  Now I just need to find some awesome-looking analog gauges and write a script to keep an eye on when the next bus is going to be rolling by my apartment.  &lt;a href=&quot;http://www.allelectronics.com&quot;&gt;All Electronics&lt;/a&gt; has some nice big VU meters for $10 or so &amp;mdash; if anyone&#039;s got a better suggestion, please let me know.&lt;/p&gt;

&lt;p&gt;The only downside to all of this is that the Arduino&#039;s being underutilized.  For the simple apps I have in mind to try first, you could probably get away with some sort of serial-speaking PWM IC.  But of course the Arduino&#039;s open, and easy, and quite flexible.  It&#039;s nice to know that I&#039;ll have more power (and GPIOs) available if I decide to do something more complex.  And now that Arduino kits are less than $20, it&#039;s not &lt;em&gt;so&lt;/em&gt; much more expensive to build them into your project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; One thing I forgot to note: don&#039;t try to program your Arduino while there&#039;s anything connected to its serial pins.  I made that mistake and was getting very frustrated at my inability to upload my sketch &amp;mdash; even when powered off the connected La Fonera was interfering.  Temporarily disconnecting the two solved the problem immediately.  I was using a relatively old Arduino NG (still ATMega8-based), so for all I know this may not happen to newer models.&lt;/p&gt;</description>
 <comments>http://labs.echoditto.com/hacking-la-fonera-2#comments</comments>
 <category domain="http://labs.echoditto.com/taxonomy/term/134">arduino</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/129">fon</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/137">fonera</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/139">hardware</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/130">lafonera</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/138">serial</category>
 <pubDate>Mon, 17 Dec 2007 17:21:43 -0800</pubDate>
 <dc:creator>Tom</dc:creator>
 <guid isPermaLink="false">57 at http://labs.echoditto.com</guid>
</item>
</channel>
</rss>
