<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Arduino-serial: C code to talk to Arduino</title>
	<atom:link href="http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/feed/" rel="self" type="application/rss+xml" />
	<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/</link>
	<description>Random experiments, circuits, code, rapid prototyping, sometimes things to buy, and the odd tune by Tod E. Kurt.</description>
	<lastBuildDate>Tue, 07 Feb 2012 02:00:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Henry</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-8/#comment-78863</link>
		<dc:creator>Henry</dc:creator>
		<pubDate>Wed, 14 Dec 2011 21:00:35 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78863</guid>
		<description>How can i send a int to the board?

Cheers, Henry</description>
		<content:encoded><![CDATA[<p>How can i send a int to the board?</p>
<p>Cheers, Henry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CoffeeNinja</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-8/#comment-78752</link>
		<dc:creator>CoffeeNinja</dc:creator>
		<pubDate>Sat, 10 Dec 2011 22:30:25 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78752</guid>
		<description>I&#039;m trying to send a command to the arduino and get a response but I can&#039;t seem to get it to work:

command:
&lt;code&gt;./arduino-serial -b 9600 -p /dev/ttyUSB0 -d 2000 -s foo -r&lt;/code&gt;

response:
&lt;code&gt;read: foo&lt;/code&gt;

the response is whatever I tried to send the arduino, my sketch sends different output depending on the command sent.</description>
		<content:encoded><![CDATA[<p>I&#8217;m trying to send a command to the arduino and get a response but I can&#8217;t seem to get it to work:</p>
<p>command:<br />
<code>./arduino-serial -b 9600 -p /dev/ttyUSB0 -d 2000 -s foo -r</code></p>
<p>response:<br />
<code>read: foo</code></p>
<p>the response is whatever I tried to send the arduino, my sketch sends different output depending on the command sent.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fabio</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-8/#comment-78523</link>
		<dc:creator>Fabio</dc:creator>
		<pubDate>Thu, 24 Nov 2011 22:04:03 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78523</guid>
		<description>[SOLVED] I&#039;ve spent over a month trying to have a good communication between linux (Debian Squeeze) and ARDUINO using C programming. I tried every possible configuration with termios.h. My problem was that linux seems to communicate twice at the beginning of the connection with ARDUINO, confusing all the following dialogue. I don&#039;t now why it happens, but finally I&#039;ve found a solution to solve it. 

So, this is the C code to initialize serial connection with ARDUINO using termios.h. If you don&#039;t know how the following functions work, I suggest this link: http://pubs.opengroup.org/onlinepubs/7908799/xsh/termios.h.htmlSo.
---- Beginning of C code -----
&lt;pre&gt;
#include    /* File control definitions */
#include    /* Error number definitions */
#include  /*linux serial library*/
#define DEVICE_ADDR &quot;/dev/ttyACM0&quot;

int main()
{
 struct termios options;
 fd = open(DEVICE_ADDR, O_RDWR &#124; O_NOCTTY &#124; O_NDELAY);
 if (fd&lt;0) perror(&quot;open_port: Unable to open /dev/ttyACM0 - &quot;);
 
 options.c_cflag=6322; //6322 is for BOUDRATE 115200, if you want 9600 use 2237 instead
 options.c_lflag=0;
 options.c_iflag=0;
 options.c_oflag=0;

 tcsetattr(fd, TCSANOW, &amp;options);

 //the following two lines is the strange thing that makes the whole thing work
 sleep(1); //Sleep time works only from 1 to 2 (2 not included)
 tcflush(fd, TCIFLUSH);

&lt;/pre&gt;
--- end of C code ---

This is all, from now on you can add your own code to read and write with ARDUINO, using C read and write functions.
Have a good programming day.
</description>
		<content:encoded><![CDATA[<p>[SOLVED] I&#8217;ve spent over a month trying to have a good communication between linux (Debian Squeeze) and ARDUINO using C programming. I tried every possible configuration with termios.h. My problem was that linux seems to communicate twice at the beginning of the connection with ARDUINO, confusing all the following dialogue. I don&#8217;t now why it happens, but finally I&#8217;ve found a solution to solve it. </p>
<p>So, this is the C code to initialize serial connection with ARDUINO using termios.h. If you don&#8217;t know how the following functions work, I suggest this link: <a href="http://pubs.opengroup.org/onlinepubs/7908799/xsh/termios.h.htmlSo" rel="nofollow">http://pubs.opengroup.org/onlinepubs/7908799/xsh/termios.h.htmlSo</a>.<br />
&#8212;- Beginning of C code &#8212;&#8211;</p>
<pre>
#include    /* File control definitions */
#include    /* Error number definitions */
#include  /*linux serial library*/
#define DEVICE_ADDR "/dev/ttyACM0"

int main()
{
 struct termios options;
 fd = open(DEVICE_ADDR, O_RDWR | O_NOCTTY | O_NDELAY);
 if (fd&lt;0) perror(&quot;open_port: Unable to open /dev/ttyACM0 - &quot;);

 options.c_cflag=6322; //6322 is for BOUDRATE 115200, if you want 9600 use 2237 instead
 options.c_lflag=0;
 options.c_iflag=0;
 options.c_oflag=0;

 tcsetattr(fd, TCSANOW, &amp;options);

 //the following two lines is the strange thing that makes the whole thing work
 sleep(1); //Sleep time works only from 1 to 2 (2 not included)
 tcflush(fd, TCIFLUSH);
</pre>
<p>&#8212; end of C code &#8212;</p>
<p>This is all, from now on you can add your own code to read and write with ARDUINO, using C read and write functions.<br />
Have a good programming day.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-8/#comment-78509</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Tue, 22 Nov 2011 06:42:27 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78509</guid>
		<description>Finally got it resolved, with a lot of help from a friend. We&#039;re using an AppleScript to telnet to ser2sock
to the Arduino, attached to a remote machine.

Many thanks,

Carl</description>
		<content:encoded><![CDATA[<p>Finally got it resolved, with a lot of help from a friend. We&#8217;re using an AppleScript to telnet to ser2sock<br />
to the Arduino, attached to a remote machine.</p>
<p>Many thanks,</p>
<p>Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: todbot</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-8/#comment-78505</link>
		<dc:creator>todbot</dc:creator>
		<pubDate>Mon, 21 Nov 2011 20:33:23 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78505</guid>
		<description>Hi Carl,
Can you post your Arduino sketch so I can try it myself?</description>
		<content:encoded><![CDATA[<p>Hi Carl,<br />
Can you post your Arduino sketch so I can try it myself?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-8/#comment-78500</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Mon, 21 Nov 2011 04:27:59 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78500</guid>
		<description>I got the Arduino to respond to this input from Terminal:  arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -d 2000 -s b
but the Arduino LED just flashes 3 times very quickly, regardless of what I have programmed into it&#039;s sketch.

Any idea what may be going on?

Thanks,

Carl</description>
		<content:encoded><![CDATA[<p>I got the Arduino to respond to this input from Terminal:  arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -d 2000 -s b<br />
but the Arduino LED just flashes 3 times very quickly, regardless of what I have programmed into it&#8217;s sketch.</p>
<p>Any idea what may be going on?</p>
<p>Thanks,</p>
<p>Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-7/#comment-78499</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Mon, 21 Nov 2011 04:16:44 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78499</guid>
		<description>I got the Arduino to respond to this Terminal input: arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -s a
but the LED just does 3 quick flashes, not what was programmed for the LED to do in the sketch.

In fact it just flashes the LED regardless of what I send it or what is in the sketch to do.

Any ideas?

Carl</description>
		<content:encoded><![CDATA[<p>I got the Arduino to respond to this Terminal input: arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -s a<br />
but the LED just does 3 quick flashes, not what was programmed for the LED to do in the sketch.</p>
<p>In fact it just flashes the LED regardless of what I send it or what is in the sketch to do.</p>
<p>Any ideas?</p>
<p>Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: todbot</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-7/#comment-78488</link>
		<dc:creator>todbot</dc:creator>
		<pubDate>Sat, 19 Nov 2011 18:22:52 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78488</guid>
		<description>Oh! It sounds like you don&#039;t yet have the &quot;arduino-serial&quot; program compiled yet.
Did you do the steps at the top of this post? (e.g. &quot;gcc -o arduino-serial arduino-serial.c&quot;)
It is likely you do not have the Mac OS X developer tools installed (it&#039;s an optional install).
If that&#039;s the case, here&#039;s a compiled version of arduino-serial:
  http://todbot.com/arduino/host/arduino-serial/arduino-serial-macosx.zip</description>
		<content:encoded><![CDATA[<p>Oh! It sounds like you don&#8217;t yet have the &#8220;arduino-serial&#8221; program compiled yet.<br />
Did you do the steps at the top of this post? (e.g. &#8220;gcc -o arduino-serial arduino-serial.c&#8221;)<br />
It is likely you do not have the Mac OS X developer tools installed (it&#8217;s an optional install).<br />
If that&#8217;s the case, here&#8217;s a compiled version of arduino-serial:<br />
  <a href="http://todbot.com/arduino/host/arduino-serial/arduino-serial-macosx.zip" rel="nofollow">http://todbot.com/arduino/host/arduino-serial/arduino-serial-macosx.zip</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-7/#comment-78485</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Sat, 19 Nov 2011 14:54:16 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78485</guid>
		<description>Thanks, but still getting a &quot;No such file or directory&quot; error. Anything else I might try?

Carl</description>
		<content:encoded><![CDATA[<p>Thanks, but still getting a &#8220;No such file or directory&#8221; error. Anything else I might try?</p>
<p>Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: todbot</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-7/#comment-78482</link>
		<dc:creator>todbot</dc:creator>
		<pubDate>Sat, 19 Nov 2011 09:40:09 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78482</guid>
		<description>Hi Carl,

Your command looks good.  But since &quot;arduino-serial&quot; was written back before the auto-resetting Arduinos, you may want to add a slight delay before sending the &quot;a&quot; to let the Arduino come out of reset.  That is, try:

  ./arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -d 2000 -s a

This will cause arduino-serial to open the serial port (which causes the Arduino to reset), wait 2 seconds, then send an &quot;a&quot;.</description>
		<content:encoded><![CDATA[<p>Hi Carl,</p>
<p>Your command looks good.  But since &#8220;arduino-serial&#8221; was written back before the auto-resetting Arduinos, you may want to add a slight delay before sending the &#8220;a&#8221; to let the Arduino come out of reset.  That is, try:</p>
<p>  ./arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -d 2000 -s a</p>
<p>This will cause arduino-serial to open the serial port (which causes the Arduino to reset), wait 2 seconds, then send an &#8220;a&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-7/#comment-78479</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Sat, 19 Nov 2011 07:07:07 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78479</guid>
		<description>Thanks, been trying a bunch of variations of the command above that sends a single character
but no go yet. I substituted the name shown in the Arduino app for the board and tried this to send it an
&quot;a&quot; but still no joy.

./arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -s a

Any thing else I might try.
Very much appreciate your help.

Carl</description>
		<content:encoded><![CDATA[<p>Thanks, been trying a bunch of variations of the command above that sends a single character<br />
but no go yet. I substituted the name shown in the Arduino app for the board and tried this to send it an<br />
&#8220;a&#8221; but still no joy.</p>
<p>./arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -s a</p>
<p>Any thing else I might try.<br />
Very much appreciate your help.</p>
<p>Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-7/#comment-78478</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Sat, 19 Nov 2011 07:06:26 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78478</guid>
		<description>Thanks, been trying a bunch of variations of the command above that sends a single character
but no go yet. I substituted the name shown in the Arduino app for the board and tried this to send it an
&quot;a&quot; but still no joy.

./arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -s a

Any thing else I might try.
Very much appreciate your help!

Carl</description>
		<content:encoded><![CDATA[<p>Thanks, been trying a bunch of variations of the command above that sends a single character<br />
but no go yet. I substituted the name shown in the Arduino app for the board and tried this to send it an<br />
&#8220;a&#8221; but still no joy.</p>
<p>./arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -s a</p>
<p>Any thing else I might try.<br />
Very much appreciate your help!</p>
<p>Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: todbot</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-7/#comment-78474</link>
		<dc:creator>todbot</dc:creator>
		<pubDate>Fri, 18 Nov 2011 21:25:52 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78474</guid>
		<description>Hi Carl,
Yup, those commands are run from Terminal.app.  When you open Terminal up, you will see your computer name instead of &quot;laptop&quot;.</description>
		<content:encoded><![CDATA[<p>Hi Carl,<br />
Yup, those commands are run from Terminal.app.  When you open Terminal up, you will see your computer name instead of &#8220;laptop&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-7/#comment-78471</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Fri, 18 Nov 2011 20:29:35 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78471</guid>
		<description>Dumb question I&#039;m sure, but are these commands executed from the Terminal app?
Also how do I define my machine as opposed to the &quot;Laptop&quot; used in the samples?

Thanks,

Carl</description>
		<content:encoded><![CDATA[<p>Dumb question I&#8217;m sure, but are these commands executed from the Terminal app?<br />
Also how do I define my machine as opposed to the &#8220;Laptop&#8221; used in the samples?</p>
<p>Thanks,</p>
<p>Carl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Iouri Goussev</title>
		<link>http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/comment-page-7/#comment-78100</link>
		<dc:creator>Iouri Goussev</dc:creator>
		<pubDate>Fri, 12 Aug 2011 08:13:15 +0000</pubDate>
		<guid isPermaLink="false">http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/#comment-78100</guid>
		<description>It works for me on Mac Lion. Thank you for this code sample.</description>
		<content:encoded><![CDATA[<p>It works for me on Mac Lion. Thank you for this code sample.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.930 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-08 06:42:47 -->

