<?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>JeeLabs &#187; Arduino</title>
	<atom:link href="http://jeelabs.org/tag/arduino/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeelabs.org</link>
	<description>Computing stuff tied to the physical world</description>
	<lastBuildDate>Tue, 22 May 2012 22:18:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Summary of ISP options</title>
		<link>http://jeelabs.org/2011/05/29/summary-of-isp-options/</link>
		<comments>http://jeelabs.org/2011/05/29/summary-of-isp-options/#comments</comments>
		<pubDate>Sat, 28 May 2011 22:01:38 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[ISP]]></category>
		<category><![CDATA[JeeNode]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=13651</guid>
		<description><![CDATA[First of all, see this weblog post for an overview of what ISP is, why you&#8217;d want to know, and when you need it. There have been quite a few posts about ISP on this weblog over time &#8211; all tagged, so they can be reached via this link: http://jeelabs.org/tag/isp/. I&#8217;ll summarize here, since particularly [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, see this <a href="/2010/07/04/uploading-isp-ftdi-huh/">weblog post</a> for an overview of what ISP is, why you&#8217;d want to know, and when you need it.</p>

<p>There have been quite a few posts about ISP on this weblog over time &#8211; all tagged, so they can be reached via this link: <a href="http://jeelabs.org/tag/isp/">http://jeelabs.org/tag/isp/</a>.</p>

<p>I&#8217;ll summarize here, since particularly the different sketches floating around by now might be a bit confusing.</p>

<p>The <strong>ZIF socket</strong> is a way to connect to chips before they have been soldered into a circuit. There&#8217;s one for through-hole <a href="http://jeelabs.org/2008/11/23/zif-icsp/">DIP chips</a>, and one for <a href="http://jeelabs.org/2009/07/11/programming-a-32-tqfp-chip/">32-TQFP SMD chips</a>:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2009/07/DSC_0401.JPG" alt="" /></p>

<p>Once soldered into a circuit, you can use an I(C)SP programmer, which not everyone has. So I created a couple of different options based on a JeeNode (can also be an RBBB or Arduino) to perform the same function.</p>

<p>My first trial was a <a href="http://jeelabs.org/2010/04/24/isp-plug/">hack</a> with the <a href="http://jeelabs.net/projects/cafe/repository/entry/Ports/examples/isp_flash/isp_flash.pde">isp&#95;flash.pde</a> sketch, which then led to the <strong>Flash Board</strong> (<a href="/fb1">info</a>). The nice thing about this board is that it has 128 Kbyte of EEPROM on board &#8211; enough to hold the complete programming instructions for an ATmega168 or ATmega328.</p>

<p>One way to use the Flash Board is as <a href="http://jeelabs.org/2010/05/05/a-capturing-isp-programmer/">capturing ISP programmer</a>: you send a sketch to it as if it were an ISP programmer, and then you can disconnect it and use it repeatedly to upload that sketch to other boards via ISP:</p>

<p><img src="http://files.jeelabs.org/2010/04/dsc_1381.jpg" alt="" /></p>

<p>I used this to build a 4-fold <a href="http://jeelabs.org/2010/05/18/multi-isp-programmer/">Multi-ISP programmer</a> to program all those gazillion ATmega&#8217;s needed for JeeNodes:</p>

<p><img src="http://files.jeelabs.org/2010/05/dsc_1432.jpg" alt="" /></p>

<p>Took a few attempts to get all the bugs worked out, but now it works <a href="http://jeelabs.org/2010/06/10/a-happy-ending/">perfectly</a>.</p>

<p>But there&#8217;s a much simpler way to do this, if all you want is to <a href="http://jeelabs.org/2010/06/09/repairing-a-faulty-atmega/">fix a JeeNode</a>, occasionally:</p>

<p><img src="http://files.jeelabs.org/2010/05/screen_shot_2010_05_29_at_025758.png" alt="" /></p>

<p>&#8230; or <a href="http://jeelabs.org/2010/07/02/fixing-a-faulty-atmega-arduino/">use an Arduino</a>:</p>

<p><img src="http://files.jeelabs.org/2010/06/screen_shot_2010_06_28_at_165911.png" alt="" /></p>

<p>These two ISP setups use an <a href="http://jeelabs.net/projects/cafe/repository/show/Ports/examples/isp_repair">isp&#95;repair.pde</a> sketch, which has as novelty that it includes the sketch and bootstrap its needs for programming &#8211; as <em>data array</em> in flash memory. So all that&#8217;s needed is: connect the two boards and power up the master. <em>No need to use the Arduino IDE&#8217;s &#8220;Burn Bootloader&#8221; command or anything.</em></p>

<p>Then came <a href="http://code.google.com/p/optiboot/">OptiBoot</a>, which is compatible with the Arduino Uno, and smaller/faster. This is a relatively new boot loader so you might want to update your current JeeNodes &#8211; even though an ISP programmer isn&#8217;t normally needed for development.</p>

<p>I <a href="http://jeelabs.org/2011/05/17/switching-to-optiboot/">updated</a> the <em>isp&#95;repair.pde</em> sketch, and then <a href="http://jeelabs.org/2011/05/26/fixing-the-isp_repair-sketch/">fixed</a> a few remaining problems with it:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/05/dsc_2518.jpg" alt="" /></p>

<p>And finally, I <a href="http://jeelabs.org/2011/05/18/self-powered-opti-rebooter/">added</a> a LiPo battery, and 4 <a href="http://jeelabs.org/2011/05/27/funky-plug/">config switches</a>, to end up with <a href="http://jeelabs.org/2011/05/28/more-bootstraps/">this tool</a>:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/05/dsc_2536.jpg" alt="" /></p>

<p>On the software side, the most recent design is called <a href="http://jeelabs.net/projects/cafe/repository/show/Ports/examples/isp_repair2">isp&#95;repair2.pde</a>. It supports two different sketches, up to four different bootstrap loaders, and setting the fuses either as 16 MHz crystal or optimized specifically for ceramic resonators.</p>

<p>The include files with the bootstraps included with these sketches are generated from HEX files created by the Arduino IDE. This is done with a small Tcl script called <a href="http://jeelabs.net/projects/cafe/repository/entry/Ports/examples/isp_prepare/hex2c.tcl">hex2c.tcl</a>, which is located in a slightly older <a href="http://jeelabs.net/projects/cafe/repository/show/Ports/examples/isp_prepare">isp&#95;prepare</a> example sketch folder. It&#8217;s not needed for normal use, only when one of the boot loaders changes.</p>

<p><em>Phew. Still there?</em></p>

<p>In a nutshell: if you need to re-flash your ATmega, pick one of the above options to hook things up, and use the <strong>isp&#95;repair2</strong> sketch in the <a href="http://jeelabs.net/projects/cafe/wiki/Ports">Ports library</a>. By default, it&#8217;ll upload a blink demo sketch and the OptiBoot loader.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2011/05/29/summary-of-isp-options/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fixing the isp_repair sketch</title>
		<link>http://jeelabs.org/2011/05/26/fixing-the-isp_repair-sketch/</link>
		<comments>http://jeelabs.org/2011/05/26/fixing-the-isp_repair-sketch/#comments</comments>
		<pubDate>Wed, 25 May 2011 22:01:11 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[ISP]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=13609</guid>
		<description><![CDATA[A few days ago I posted a new sketch to reprogram an ATmega with the OptiBoot loader when you don&#8217;t have an ISP programmer. Worked for me, so I thought&#8230; kick it into the world! Whoops&#8230; First of all, there should have been a warning that if it didn&#8217;t work, this would leave you with [...]]]></description>
			<content:encoded><![CDATA[<p>A <a href="/2011/05/17/switching-to-optiboot/">few days ago</a> I posted a new sketch to reprogram an ATmega with the <a href="http://code.google.com/p/optiboot/">OptiBoot</a> loader when you don&#8217;t have an ISP programmer. Worked for me, so I thought&#8230; <em>kick it into the world!</em></p>

<p>Whoops&#8230;</p>

<p>First of all, there should have been a warning that if it didn&#8217;t work, this would leave you with an unusable ATmega. Never occurred to me, since I have an ISP programmer within reach to recover from such mistakes.</p>

<p>Fortunately, someone on the forum <a href="http://forum.jeelabs.net/comment/1041#comment-1041">reported</a> that the ATmega can be brought back to life with an old version of <em>isp&#95;repair.pde</em> (which can be found <a href="http://jeelabs.net/projects/cafe/repository/revisions/5759/entry/Ports/examples/isp_repair/isp_repair.pde">here</a>, BTW).</p>

<p>That&#8217;s odd&#8230; can&#8217;t program with the sketch, but <em>can</em> recover with the same sketch and different data bytes?</p>

<p>Time to dig in. First, I wanted to make sure that the timing was slow enough to work in all cases. Time to fire that logic analyzer up again:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/05/screen_shot_2011_05_25_at_113322.png" alt="Screen Shot 2011 05 25 at 11.33.22" /></p>

<p>Looks good &#8211; since I&#8217;m using standard <em>digitalWrite()</em> calls, the pins aren&#8217;t toggling very fast at all:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/05/screen_shot_2011_05_25_at_113429.png" alt="Screen Shot 2011 05 25 at 11.34.29" /></p>

<p>Then it dawned on me:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/05/screen_shot_2011_05_16_at_170848.png" alt="" /></p>

<p>The lock bits don&#8217;t look right: 0xFF &#8211; should have been 0xCF (top 2 bits are always 1, i.e. same as 0x0F).</p>

<p>Maybe everything was working, <em>except</em> the setting of the fuse bits? That would explain everything: a new boot loader gets loaded in the top 512 bytes, overwriting parts of the old boot loader, but the fuse bits perhaps wouldn&#8217;t get adjusted to just to the <em>new</em> boot address!</p>

<p>I changed a couple of things:</p>

<ul>
<li>do the full chip erase <em>before</em> setting the fuse bits</li>
<li>set the lock bits to 0x0F at the end, i.s.o. 0x3F</li>
<li>included both bootstraps in the updated sketch</li>
<li>tri-state the ISP programming pins when done</li>
</ul>

<p>The erase is needed to recover from a locked fuse state. The programming always took place after the erase, so it went well, but the fuse bits <em>themselves</em> would still be locked while trying to adjust them.</p>

<p>The second step should have been there all along, the way I was doing it the boot section was not protected from overwriting itself. This might explain the occasional report I got of people damaging boot loaders during use.</p>

<p>You can now also adjust the <em>#define OPTIBOOT</em> at the top of the sketch to 0 to revert to the original bootstrap code and fuse settings. So if OptiBoot is not what you want, recompile and restore as needed.</p>

<p>And lastly, the SPI programming pins are now reset to high-impedance after programming, so that the programming connections can be left in place without interfering with the target board.</p>

<p>Here&#8217;s the serial output from the updated sketch:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/05/screen_shot_2011_05_25_at_114131.png" alt="Screen Shot 2011 05 25 at 11.41.31" /></p>

<p>And here&#8217;s why it would <em>sometimes</em> have worked: if your ATmega had the lock bits unset (0x3F i.s.o. 0x0F), then the fuse settings would work as intended even with the chip erase in the wrong order. But with a locked setup, not everything would get set to the proper state.</p>

<p><em>Which goes to show: bugs can bite at any time!</em></p>

<p><strong>Update</strong> &#8211; still some issues to iron out (see <a href="http://forum.jeelabs.net/node/212">forum</a>), but it looks like these are more related to <a href="http://code.google.com/p/optiboot/">OptiBoot</a> than to this bootstrap replacement sketch.</p>

<p><strong>Update #2</strong> &#8211; OptiBoot issue <a href="http://forum.jeelabs.net/comment/1188#comment-1188">solved</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2011/05/26/fixing-the-isp_repair-sketch/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Self-powered Opti-rebooter</title>
		<link>http://jeelabs.org/2011/05/18/self-powered-opti-rebooter/</link>
		<comments>http://jeelabs.org/2011/05/18/self-powered-opti-rebooter/#comments</comments>
		<pubDate>Tue, 17 May 2011 22:01:58 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[ISP]]></category>
		<category><![CDATA[JeeLink]]></category>
		<category><![CDATA[JeeNode]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=13483</guid>
		<description><![CDATA[After yesterday&#8217;s post about switching to OptiBoot, I decided to go one step further and go for a self-powered solution, a bit like this unit which has been serving me well for many months now. So here&#8217;s the &#8220;Opti-rebooter&#8221; with a 400 mAh LiPo backpack: Hookup is trivial, given that the JeeNode USB has an [...]]]></description>
			<content:encoded><![CDATA[<p>After yesterday&#8217;s post about <a href="/2011/05/17/switching-to-optiboot/">switching to OptiBoot</a>, I decided to go one step further and go for a self-powered solution, a bit like <a href="/2010/05/18/multi-isp-programmer/">this unit</a> which has been serving me well for many months now.</p>

<p>So here&#8217;s the &#8220;Opti-rebooter&#8221; with a 400 mAh LiPo backpack:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/05/dsc_2521.jpg" alt="Dsc 2521" /></p>

<p>Hookup is trivial, given that the <a href="/ju3">JeeNode USB</a> has an on-board LiPo charger. I picked a battery which matches the width of the board and fits quite well:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/05/dsc_2522.jpg" alt="Dsc 2522" /></p>

<p>The two connectiosn of the LiPo battery are wrapped up in heat-shrink tubing to prevent accidental short circuits &#8211; the currents involved could easily cause trouble. Note that this is a &#8220;raw&#8221; LiPo cell, without any protection circuitry. That&#8217;s fine in this case, because the on-board circuitry takes care of charging.</p>

<p>To make this complete, the <a href="http://jeelabs.net/projects/cafe/repository/show/Ports/examples/isp_repair">isp&#95;repair.pde</a> was extended to completely power down when done. So there&#8217;s no need for an on-off switch, the idle consumption is probably lower than the battery&#8217;s own self-discharge rate. And it  blinks the on-board led twice: once on power up and once when properly programmed. <em>Very convenient!</em></p>

<p>The way to use this thing, is: connect to a target JeeNode / JeeLink / Arduino, press the RESET button, wait three seconds, disconnect, done.</p>

<p>I also made changes to the very similar but slightly more elaborate <a href="http://jeelabs.net/projects/cafe/repository/show/Ports/examples/isp_prepare">isp&#95;prepare.pde</a> sketch, which was presented in <a href="/2010/04/25/preparing-atmegas-with-isp/">this weblog post</a>.</p>

<p>The updated <em>isp&#95;prepare.pde</em> sketch supports a number of variations. These can be configured by adjusting a few values at the start of the sketch:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/05/screen_shot_2011_05_16_at_150032.png" alt="Screen Shot 2011 05 16 at 15.00.32" /></p>

<p>You can choose which type of boot loader to install, which sketch to load initially (just to start off, this can be overwritten later), and there&#8217;s a third option to adjust some &#8220;fuse bits&#8221; in the ATmega to select how fast the ATmega can start up after resuming from a power down.</p>

<p>That third option is particularly useful with battery-powered JeeNodes using the RF12 driver. With USE&#95;FAST&#95;WAKEUP set to 1, the power-up sequence is fast enough for an ATmega to wake up when the first data byte is received. This means you can completely power down the ATmega (while leaving the receiver running), and it&#8217;ll still be able to pick up incoming packets and respond to them. There is one gotcha: USE&#95;FAST&#95;WAKEUP can only be set to 1 on units running with a resonator &#8211; JeeLinks and Arduino&#8217;s running with a crystal must be not use the fast wakeup mechanism, as the clock may not start up properly in this case.</p>

<p>Haven&#8217;t tried it though &#8211; for now, that LiPo powered unit shown above is really the most convenient way for me to upgrade all the JeeNodes, JeeLinks, and Arduino&#8217;s floating around the house at JeeLabs.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2011/05/18/self-powered-opti-rebooter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Meet the RFM12B Board</title>
		<link>http://jeelabs.org/2011/02/02/meet-the-rfm12b-board/</link>
		<comments>http://jeelabs.org/2011/02/02/meet-the-rfm12b-board/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 23:01:50 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Network]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=13064</guid>
		<description><![CDATA[With the RFM12B becoming a nice low-cost option for low-volume wireless communication, and the RF12 library proving to be a solid software driver for it, it&#8217;s time to generalize a bit further&#8230; Say hello to the new RFM12B Board: This board adds a voltage regulator and 3.3V/5V level conversions, to be able to use the [...]]]></description>
			<content:encoded><![CDATA[<p>With the RFM12B becoming a nice low-cost option for low-volume wireless communication, and the RF12 library proving to be a solid software driver for it, it&#8217;s time to generalize a bit further&#8230;</p>

<p>Say hello to the new <strong>RFM12B Board</strong>:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/02/dsc_2448.jpg" alt="Dsc 2448" /></p>

<p>This board adds a voltage regulator and 3.3V/5V level conversions, to be able to use the RFM12B on 5V systems such as the various Arduino&#8217;s out there, the RBBB, &#8230; anything you want, really.</p>

<p>There are 8 pins on this board, of which the 8th is a regulated 3.3V supply which can be used in other parts of the circuit &#8211; the voltage regulator will be able to supply at least 100 mA extra on that supply pin.</p>

<p>The other 7 pins are:</p>

<ul>
<li>+5V</li>
<li>Ground</li>
<li>SPI clock (SCK) &#8211; <em>Arduino digital 13</em></li>
<li>SPI data out (SDO) &#8211; <em>Arduino digital 12</em></li>
<li>SPI data in (SDI) &#8211; <em>Arduino digital 11</em></li>
<li>SPI select (SEL) &#8211; <em>Arduino digital 10</em></li>
<li>IRQ &#8211; <em>Arduino digital 2</em></li>
</ul>

<p>Just hook each of those up to an Arduino, and you can use the <a href="http://jeelabs.net/projects/cafe/wiki/RF12">RF12 library</a> <em>as is!</em></p>

<p>Sample output:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/02/screen_shot_2011_02_01_at_220814.png" alt="Screen Shot 2011 02 01 at 22.08.14" /></p>

<p><em>Look ma, just like a <a href="/jn5">JeeNode</a> or <a href="jl2">JeeLink</a>!</em></p>

<p>With an 8-pin stacking header and a bit of bending, cutting, and soldering two wires (I used a jumper wire, cut in half), you can even stick this thing right onto an Arduino:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/02/dsc_2449.jpg" alt="Dsc 2449" /></p>

<p>But of course using a normal solderless breadboard and some wire jumpers will work just as well.</p>

<p>Note that this board can also be tied to 3.3V systems &#8211; just use the bare PCB (and short out three solder jumpers), which then becomes a breakout board for the RFM12B. No need to mess with the 2.0 mm pin/pad distance on the RFM12B module itself.</p>

<p>Docs can be found in the <a href="http://jeelabs.net/projects/hardware/wiki/RFM12B_Board">Café</a>, and the kit/pcb is now available in the <a href="http://jeelabs.com/products/rfm12b-board">shop</a>, as usual.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2011/02/02/meet-the-rfm12b-board/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Uploading? ISP? FTDI? Huh?</title>
		<link>http://jeelabs.org/2010/07/04/uploading-isp-ftdi-huh/</link>
		<comments>http://jeelabs.org/2010/07/04/uploading-isp-ftdi-huh/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 22:01:08 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[ISP]]></category>
		<category><![CDATA[JeeNode]]></category>

		<guid isPermaLink="false">http://news.jeelabs.org/?p=8686</guid>
		<description><![CDATA[There seems to be a fair bit of confusion in- and outside the Arduino world, and it&#8217;s spilling over to JeeNodes &#8230; I&#8217;d like to go through some terms and buzzwords to try and clarify how to get your Arduino or JeeNode to do the thing you want it to do. I&#8217;m going to assume [...]]]></description>
			<content:encoded><![CDATA[<p><em>There seems to be a fair bit of confusion in- and outside the Arduino world, and it&#8217;s spilling over to JeeNodes &#8230;</em></p>

<p>I&#8217;d like to go through some terms and buzzwords to try and clarify how to get <em>your</em> Arduino or JeeNode to do the thing <em>you</em> want it to do. I&#8217;m going to assume that you are familiar with the process of writing software (&#8220;code&#8221;), compiling it, and running it &#8211; at least on a Windows, Mac, or Linux computer (let&#8217;s call them all PC&#8217;s for now). With software for the ATmega, there are two approaches, depending on whether you use the Arduino IDE or not:</p>

<p><img src="http://files.jeelabs.org/2010/06/screen_shot_2010_06_28_at_235022.png" alt="Screen Shot 2010 06 28 at 23.50.22" /></p>

<p>Both lead to the same result: a &#8220;hex&#8221; file with code that needs to be transferred from the PC to the ATmega.</p>

<p>The step which can be puzzling when starting out with physical computing and embedded hardware is how to get things across from your PC to that little Arduino or Arduino-like system you&#8217;re holding in your hand. And vice versa, since we often want to get results back or see some confirmation that things are working properly.</p>

<p>The confusion comes from the different conceptual levels involved, and things like:</p>

<ul>
<li>do you mean how to connnect? &#8211; <em>plug in a USB cable</em></li>
<li>do you mean how does the ATmega change its own code? &#8211; <em>through a boot loader</em></li>
<li>do you mean via ISP (In System Programming)? &#8211; <em>no, that&#8217;s normally not needed</em></li>
<li>do you mean via FTDI? &#8211; <em>yes, that&#8217;s the name of the chip which is hooked up to USB</em></li>
<li>isn&#8217;t FTDI a connector? &#8211; <em>yeah, that too, sort of&#8230; i.e. a 6-pin convention</em></li>
<li>isn&#8217;t a power + serial cable enough? &#8211; <em>no, resets also play a key role</em></li>
<li>do I have to use the Arduino IDE? &#8211; <em>no, you can also use a program called &#8220;avrdude&#8221;</em></li>
<li>what&#8217;s avrdude? &#8211; <em>a program which can upload to a boot loader or an ISP programmer</em></li>
<li>do I need an ISP progranmmer? &#8211; <em>nope, the boot loader does essentially the same thing</em></li>
<li>so why not just get rid of ISP? &#8211; <em>because you need ISP to install the boot loader</em></li>
</ul>

<p><em>Confused? Welcome to the club&#8230;</em></p>

<p>In case you&#8217;re wondering&#8230; the process is called &#8220;uploading&#8221; because the PC initiates this as <em>outbound</em> transfer:</p>

<p><img src="http://files.jeelabs.org/2010/06/screen_shot_2010_06_29_at_015150.png" alt="Screen Shot 2010 06 29 at 01.51.50" /></p>

<p>To get your code (&#8220;sketch&#8221; in Arduino-speak) into an ATmega, you need three things, working together to make uploading happen under all possible conditions:</p>

<ol>
<li><p><strong>An electrical connection</strong> &#8211; to power the ATmega, to communicate with it, and to restart the ATmega when it is stuck or busy doing something else.</p></li>
<li><p><strong>A common language / protocol</strong> &#8211; the communication must be understood by both sides, i.e. PC and ATmega.</p></li>
<li><p><strong>Software on both sides of the connection</strong> &#8211; Sending something when the other side isn&#8217;t listening, or listening while no-one is sending will not have the desired outcome.</p></li>
</ol>

<p>Let&#8217;s go through each of these separately.</p>

<h2>1. An electrical connection</h2>

<p>There are several ways to make the connection. With an Arduino, or any similar board which has a USB connector, you can simply plug in the USB cable:</p>

<p><img src="http://files.jeelabs.org/2010/06/screen_shot_2010_06_28_at_235241.png" alt="Screen Shot 2010 06 28 at 23.52.41" /></p>

<p>Some boards use a separate USB interface (&#8220;FTDI adapter&#8221;), allowing reuse of that interface for multiple boards:</p>

<p><img src="http://files.jeelabs.org/2010/06/screen_shot_2010_06_28_at_235408.png" alt="Screen Shot 2010 06 28 at 23.54.08" /></p>

<p>The end effect is the same: a connection which powers the ATmega and allows communicating with it using a simple serial protocol. There&#8217;s also a trick in this hookup to let the PC reset the ATmega whenever it wants.</p>

<h2>2. A common language / protocol</h2>

<p>Ah, now it gets interesting. First thing to note is that <em>there is no single common language / protocol!</em></p>

<p>That&#8217;s right. It all depends on what you want to do. Here we want to upload code from the PC to the ATmega. That requires exchanging &#8220;ISP commands&#8221; over the connection. But once uploading is done, we really want to <em>reuse</em> the connection as a regular two-way serial link.</p>

<p>The way it works is that the PC will reset the ATmega just before uploading new code. This activates a &#8220;boot loader&#8221; on the ATmega. Now both sides will be in sync (briefly) so they can exchange the necessary information to make an upload happen. IOW, right after reset the protocol is &#8220;ISP commands&#8221;. Once the upload is done, the connection can be reused for any protocol you like &#8211; as determined by the code that was uploaded.</p>

<h2>3. Software on both sides of the connection</h2>

<p>Back to the software now. We need to send ISP commands over the connection.</p>

<p>As you may have guessed, that&#8217;s exactly what the Arduino boot loader on the ATmega
understands. When reset, the boot loader in the ATmega gets control. It waits and listens for incoming STK500 ISP commands. If none come in within a second or so, it relinquishes control to whatever was previously uploaded to the ATmega.</p>

<p>On the PC side, we need software which resets the ATmega and then immediately sends all the ISP commands needed to transfer and program the contents of a hex file.</p>

<p>This is what &#8220;avrdude&#8221; does. You can either use it implicitly from the Arduino IDE by starting an &#8220;Upload&#8221; from the menu, or you can launch it manually from the command line &#8211; avrdude needs a few options to tell it where the USB port is, what baudrate to use, the type of ATmega, the protocol to use (i.e. STK500), etc.</p>

<h2>There&#8217;s more&#8230;</h2>

<p>The above describes the different pieces and concepts involved in getting code into an ATmega. The beauty of it is that once it works, it really works well. Supplying power, uploading, communication, control, debugging &#8230; <em>all with one simple USB cable.</em> You only need to go back a few years to appreciate just how much this approach simplifies embedded development.</p>

<p>But there&#8217;s one important detail: the ATmega has to have a functioning boot loader. Placing a boot loader into an ATmega is a bit more complicated (and involves other things such as &#8220;fuses&#8221;). It&#8217;s a chicken-and-egg problem.</p>

<p>This is where the ISP programmer comes in. An ISP programmer is a fairly simple piece of hardware. In fact, you can make your own, as I&#8217;ve described in <a href="http://news.jeelabs.org/tag/isp/">several posts</a> on this weblog. See <a href="http://news.jeelabs.org/2010/07/02/fixing-a-faulty-atmega-arduino/">this</a> and <a href="http://news.jeelabs.org/2010/06/09/repairing-a-faulty-atmega/">this</a> post for some quick solutions which require nothing more than a working Arduino or JeeNode.</p>

<p>The good news, is that you usually don&#8217;t have to worry about installing the boot loader &#8211; it&#8217;s all done for you. Once. For the mechanism described above, you&#8217;ll never need an ISP programmer.</p>

<p>Some people actually prefer to use the ISP technique for uploading their sketches. In fact, sometimes you have no choice, i.e. when you need the serial port at all times, or when you can&#8217;t spare the 1..4 Kb required by the boot loader code, or when working with ATtiny chips which don&#8217;t support bootloaders.</p>

<p>In thoses cases, you&#8217;ll need a setup with an ISP programmer. But for most people doodling around with ATmega&#8217;s and the Arduino IDE, the above boot loader mechanism is usually very convenient and the easiest to get going.</p>

<p><em>Either way, it helps to understand the process. I hope the above was helpful in that direction.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2010/07/04/uploading-isp-ftdi-huh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing a faulty ATmega (Arduino)</title>
		<link>http://jeelabs.org/2010/07/02/fixing-a-faulty-atmega-arduino/</link>
		<comments>http://jeelabs.org/2010/07/02/fixing-a-faulty-atmega-arduino/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 22:01:24 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[ISP]]></category>
		<category><![CDATA[JeeNode]]></category>

		<guid isPermaLink="false">http://news.jeelabs.org/?p=8673</guid>
		<description><![CDATA[After a recent post on how to repair an ATmega with a faulty (or even missing) bootloader and helping someone out with it, it occurred to me that this mechanism will work for any Arduino &#8211; not just JeeNodes. Any 3.3V or 5V Arduino&#8217;ish system which lets you upload the isp_repair.pde sketch can be used [...]]]></description>
			<content:encoded><![CDATA[<p>After a <a href="http://news.jeelabs.org/2010/06/09/repairing-a-faulty-atmega/">recent post</a> on how to repair an ATmega with a faulty (or even missing) bootloader and helping someone out with it, it occurred to me that this mechanism will work for any Arduino &#8211; not just JeeNodes.</p>

<p>Any 3.3V or 5V Arduino&#8217;ish system which lets you upload the <a href="http://jeelabs.net/projects/cafe/repository/show/Ports/examples/isp_repair">isp_repair.pde</a> sketch can be used to program any board with an ISP connector on it. The code is for ATmega328&#8242;s, because that&#8217;s all I use around here these days.</p>

<p>The trick is to hook up a few power and I/O lines in a specific way:</p>

<p><img src="http://files.jeelabs.org/2010/06/screen_shot_2010_06_28_at_165911.png" alt="Screen Shot 2010 06 28 at 16.59.11" /></p>

<p>I&#8217;m using an Arduino Pro as example, but that&#8217;s just one of many you could use. Now connect these six wires:</p>

<ul>
<li>ISP pin 1 = BLUE = Digital pin 4</li>
<li>ISP pin 2 = RED = VCC (+5V)</li>
<li>ISP pin 3 = GREEN = Analog pin 0</li>
<li>ISP pin 4 = PURPLE = Analog pin 3</li>
<li>ISP pin 5 = ORANGE = Digital pin 7</li>
<li>ISP pin 6 = BLACK = GND</li>
</ul>

<p>Note: if your working board operates at 3.3V, then you should connect the RED wire to +3.3V, not +5V (that way signal levels and power supply will match). Also: the target board should not be connected to anything, since it will be powered through the ISP connector.</p>

<p>The only thing left to do is to upload the <a href="http://code.jeelabs.org/viewvc/svn/jeelabs/trunk/libraries/Ports/examples/isp_repair/isp_repair.pde">isp_repair.pde</a> sketch to your working board, and open up a console window. You should see something like this:</p>

<p><img src="http://files.jeelabs.org/2010/05/screen_shot_2010_05_29_at_022405.png" alt="" /></p>

<p>That&#8217;s it &#8211; disconnect all the wires. The ATmega on the target board now has a boot loader and the standard pin 13 blink sketch. <em>Ready again to accept whatever sketch you upload to it!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2010/07/02/fixing-a-faulty-atmega-arduino/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>EtheRBBBreadboard</title>
		<link>http://jeelabs.org/2010/06/07/etherbbbreadboard/</link>
		<comments>http://jeelabs.org/2010/06/07/etherbbbreadboard/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 22:01:10 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Network]]></category>

		<guid isPermaLink="false">http://news.jeelabs.org/?p=8112</guid>
		<description><![CDATA[Please excuse the crazy title. This picture probably tells you more: You&#8217;re looking at an RBBB from Modern Device, hooked up to the Ether Card from Jee Labs. The hookup is trivial, it need 6 wires: 2 for power and 4 for SPI: And that&#8217;s all you need to create a webserver! Here&#8217;s a sample [...]]]></description>
			<content:encoded><![CDATA[<p>Please excuse the crazy title. This picture probably tells you more:</p>

<p><img src="http://files.jeelabs.org/2010/05/dsc_1509.jpg" alt="Dsc 1509" /></p>

<p>You&#8217;re looking at an <a href="http://www.moderndevice.com/products/rbbb-kit">RBBB</a> from Modern Device, hooked up to the <a href="http://cafe.jeelabs.net/hw/ether_card/">Ether Card</a> from Jee Labs. The hookup is trivial, it need 6 wires: 2 for power and 4 for SPI:</p>

<p><img src="http://files.jeelabs.org/2010/05/screen_shot_2010_05_29_at_041826.png" alt="Screen Shot 2010 05 29 at 04.18.26" /></p>

<p><em>And that&#8217;s all you need to create a webserver!</em></p>

<p>Here&#8217;s a sample screen (yep, it&#8217;s been running for <em>almost</em> 12 hours):</p>

<p><img src="http://files.jeelabs.org/2010/05/screen_shot_2010_05_29_at_000348.png" alt="Screen Shot 2010 05 29 at 00.03.48" /></p>

<p>And here&#8217;s the code for it:</p>

<p><img src="http://files.jeelabs.org/2010/05/screen_shot_2010_05_28_at_120503.png" alt="Screen Shot 2010 05 28 at 12.05.03" /></p>

<p>It presents a self-refreshing page with the &#8220;uptime&#8221;, i.e. how long the server has been running since power-up.</p>

<p>The code is available as &#8220;rbbb_server.pde&#8221; example sketch in the <a href="http://cafe.jeelabs.net/software/">EtherCard library</a> and is a simplified adaptation of the <a href="http://news.jeelabs.org/2010/05/31/jeenode-as-web-server/">etherNode</a> sketch, omitting the RF12 driver and calls, of course. It compiles to 6 Kb of code.</p>

<p>As with the etherNode sketch, the MAC address and IP address have to be set to suitable values in the source code before uploading it to the RBBB.</p>

<p><em>BTW&#8230; did you notice anything?</em></p>

<p>The RBBB is running at 5V. And it works. Because <em>the Ether Card is compatible with 3.3V and 5V signals!</em></p>

<p>Which also means that the Ether Card can be used with any Arduino board. It&#8217;s not specific to JeeNodes and it&#8217;s not limited to being used with the <a href="http://cafe.jeelabs.net/hw/carrier_board/">Carrier Board</a>, either.</p>

<p>The generic software for the Ether Card is contained in the &#8220;EtherCard&#8221; library, listed on the <a href="http://cafe.jeelabs.net/software/">software</a> page in the Café. It doesn&#8217;t depend on Ports or RF12 libraries, so this thing really is a completely independent product.</p>

<p>It just &#8220;happens&#8221; to fit gorgeously into a box alongside a JeeNode :)</p>

<p><img src="http://files.jeelabs.org/2010/05/dsc_1467.jpg" alt="" /></p>

<p>So there you have it &#8211; the Ether Card can be used with just about any microcontroller setup. All it needs is a power supply of 3.6V or more, 4 SPI I/O pins, and the proper software to make it sing of course&#8230;</p>

<p><em>Onwards!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2010/06/07/etherbbbreadboard/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Setting up the thermocouple node</title>
		<link>http://jeelabs.org/2010/05/10/setting-up-the-thermocouple-node/</link>
		<comments>http://jeelabs.org/2010/05/10/setting-up-the-thermocouple-node/#comments</comments>
		<pubDate>Sun, 09 May 2010 22:01:14 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Reflow]]></category>

		<guid isPermaLink="false">http://news.jeelabs.org/?p=7532</guid>
		<description><![CDATA[This is part 2 of my reflow controller series. Unlike what was announced yesterday, I&#8217;m going to first describe how to set up the temperature sensing wireless node. JeeMon hookup to follow soon. Our very first step could be to connect the thermocouple via a JeeNode and USB to the PC, but I&#8217;m going to [...]]]></description>
			<content:encoded><![CDATA[<p>This is part 2 of my <a href="http://cafe.jeelabs.net/pof/04_-_reflow_controller/">reflow controller</a> series. Unlike what was announced <a href="http://news.jeelabs.org/2010/05/09/reflow-revisited/">yesterday</a>, I&#8217;m going to first describe how to set up the temperature sensing wireless node. JeeMon hookup to follow soon.</p>

<p>Our very first step could be to connect the thermocouple via a JeeNode and USB to the PC, but I&#8217;m going to do something more interesting and go straight for a wireless hookup. One reason for this is due to a <a href="/2010/05/08/thermocouple-enigma/">problem</a> with direct connections, but since this is going to be used in un-tethered mode anyway, it&#8217;s a good excuse to use a wireless configuration right from the start.</p>

<p>Here is the &#8220;thermoSend.pde&#8221; sketch I&#8217;m going to use (code <a href="http://code.jeelabs.org/viewvc/svn/jeelabs/trunk/jeemon/sketches/thermoSend/thermoSend.pde">here</a>):</p>

<p><img src="http://files.jeelabs.org/2010/05/screen_shot_2010_05_09_at_142935.png" alt="Screen Shot 2010 05 09 at 14.29.35" /></p>

<p>This contains all the ingredients needed for a simple basic sensor node: all we do is set up wireless, and then read out the thermocouple value and send it off once a second.</p>

<p>The <a href="/2009/12/02/easy-transmissions/">easy transmissions</a> code works with broadcast packets, so we don&#8217;t need to define a destination for the wireless packets, just this sensor node&#8217;s ID (1), the choice of frequency band (868 MHz), and a group ID (6). That&#8217;s done with the <em>rf12_initialize()</em> call.</p>

<p>The readings are converted to an integer in the range 0 .. 3300, representing a temperature range of 0 .. 330.0°C. Then we send that 2-byte integer in <em>binary</em> mode over wireless. That&#8217;s what the code inside <em>loop()</em> does. The <a href="http://arduino.cc/en/Reference/Map">map</a> function is part of the Arduino library code.</p>

<p>The easy transmit system will take care of re-transmission if a packet is lost. All the transmission details are handled by <em>rf12_easyPoll()</em>, which needs to be called often.</p>

<p>One detail of the easy transmit system to keep in mind, is that only <em>changed</em> values are sent. No packets will go out if the reading is the same as the last one. In this scenario, that&#8217;s fine &#8211; there&#8217;s always some jitter in the readings, so we should see new packets at least a few times a minute, even when the sensor temperature is constant.</p>

<p>Ok, let&#8217;s get going. If you haven&#8217;t installed the Arduino IDE yet, go <a href="http://arduino.cc/en/Guide/HomePage">do it</a> now.</p>

<p>Create the above sketch named &#8220;thermoSend&#8221; in the Arduino IDE. On my Mac, it ends up as a folder named &#8220;Documents/Arduino/thermoSend/&#8221; in my home directory. Plug in the JeeNode via an FTDI adapter such as the USB-BUB (or use a JeeNode USB) and check your Arduino IDE / Tools / Serial Port settings to make sure you&#8217;re hooked up to it. With multiple nodes on USB, it&#8217;s easy to mess up the wrong one &#8211; <em>happens to me all the time&#8230;</em></p>

<p>Now the node is ready. Unplug, hook it up to a battery, and power it up.</p>

<p>You&#8217;re sending packets into the ether now. Quick, let&#8217;s try and collect those packets before they falll on the floor!</p>

<p>To do that, hook up a JeeLink or a second JeeNode. It needs to be running the RF12demo sketch, which is what it does out of the box if you got it from Jee Labs or Modern Device.</p>

<p>We need to connect to the JeeLink. Easiest way is to use the Arduino IDE. Make sure you are connected to the proper USB port. So again, check the Arduino IDE / Tools / Serial Port menu and select the JeeLink serial port.</p>

<p>Now open the Arduino IDE&#8217;s serial console. You should see something like this:</p>

<pre><code>[RF12demo] A i1 g212 @ 433 MHz
Available commands:
[etc]
</code></pre>

<p>You are now in direct communication with the JeeLink. We need to set it up to listen to the proper transmissions. Sort of like tuning to the proper radio station. So type the following line and press &#8220;Send&#8221;:</p>

<pre><code>2i 8b 6g
</code></pre>

<p>This sets node ID = 2, frequency band = 868 MHz, and net group= 6.</p>

<p>If all is well, and the wireless node is powered up, you should start to see packets come in, something like this:</p>

<pre><code>OK 33 212 0
 -&gt; ack
OK 33 209 0
 -&gt; ack
OK 33 212 0
 -&gt; ack
OK 33 209 0
 -&gt; ack
OK 33 212 0
 -&gt; ack
</code></pre>

<p>That&#8217;s a header byte (i.e. 33, associated with node ID 1) and 2 data bytes.</p>

<p>There won&#8217;t be packets every second, because only changed readings are sent. But there will be packets, and if you touch the thermocouple end, you should <em>immediately</em> see the rise in temperature:</p>

<pre><code>OK 33 212 0
 -&gt; ack
OK 33 226 0
 -&gt; ack
OK 33 24 1
 -&gt; ack
OK 33 44 1
 -&gt; ack
</code></pre>

<p>No, I&#8217;m not suffering from sudden hypthermia: that&#8217;s not 4.4°C :) &#8211; what you&#8217;re seeing is binary overflow of the first data byte. A byte can only hold values 0..255. Anything higher and it will wrap around. That&#8217;s why two bytes are sent. The second byte contains the reading divided by 256, i.e. the number of wraparounds. You&#8217;re looking at the binary representation of an &#8220;int&#8221; on Atmel AVR chips.</p>

<p>So the above readings are: 21.2°C, 22.6°C, 28.0°C, and 30.0°C.</p>

<p>IOW, the actual temperature is: (byte1 + 256 * byte2) * 0.1°C</p>

<p>The next episode will be about hooking up JeeMon to the Jeelink and using it to read out the data and do something more meaningful with it. Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2010/05/10/setting-up-the-thermocouple-node/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Plug shield on Arduino Mega</title>
		<link>http://jeelabs.org/2010/02/07/plug-shield-on-arduino-mega/</link>
		<comments>http://jeelabs.org/2010/02/07/plug-shield-on-arduino-mega/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 23:01:38 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[JeePlug]]></category>

		<guid isPermaLink="false">http://news.jeelabs.org/?p=5545</guid>
		<description><![CDATA[The Plug Shield can also be used on an Arduino Mega: Note the two extra wire jumpers, since the I2C interface is on pins 20 and 21 on the Mega board. The above has an RTC plug and an LCD plug hooked up, so let&#8217;s to set up a simple clock with this &#8211; and [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://jeelabs.net/projects/hardware/wiki/ps1">Plug Shield</a> can also be used on an <a href="http://arduino.cc/en/Main/ArduinoBoardMega">Arduino Mega</a>:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2010/02/DSC_1175.jpg" border="0" alt="DSC_1175.jpg" width="604" height="282" /></p>

<p>Note the two extra wire jumpers, since the I2C interface is on pins 20 and 21 on the Mega board.</p>

<p>The above has an <a href="http://jeelabs.net/projects/hardware/wiki/rp1">RTC plug</a> and an <a href="http://jeelabs.net/projects/hardware/wiki/lp1">LCD plug</a> hooked up, so let&#8217;s to set up a simple clock with this &#8211; and use it to demonstrate the brand-new <a href="http://jeelabs.org/2010/02/05/new-date-time-rtc-library/">RTClib</a> along the way:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2010/02/Screen-shot-2010-02-05-at-17.22.01.png" border="0" alt="Screen shot 2010-02-05 at 17.22.01.png" width="430" height="841" /></p>

<p>I&#8217;ve omitted the details of the Wire coding, but you can get the full sketch <a href="http://jeelabs.net/projects/cafe/wiki">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2010/02/07/plug-shield-on-arduino-mega/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fascinating concurrency</title>
		<link>http://jeelabs.org/2010/02/04/fascinating-concurrency/</link>
		<comments>http://jeelabs.org/2010/02/04/fascinating-concurrency/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 23:01:43 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[JeeNode]]></category>

		<guid isPermaLink="false">http://news.jeelabs.org/?p=5469</guid>
		<description><![CDATA[There is a new language for the Arduino / JeeNode / ATmega328, called Occam-π. I found out about it yesterday, at http://concurrency.cc/ &#8211; it&#8217;s high level, and it supports parallel programming. The current development environment release is for Mac OS X, with Windows and Linux coming soon. Here is a complete program with 4 blinking [...]]]></description>
			<content:encoded><![CDATA[<p><em>There is a new language for the Arduino / JeeNode / ATmega328, called <strong>Occam-π</strong>.</em></p>

<p>I found out about it yesterday, at <a href="http://concurrency.cc/">http://concurrency.cc/</a> &#8211; it&#8217;s high level, and it supports parallel programming. The current development environment release is for Mac OS X, with Windows and Linux coming soon.</p>

<p>Here is a complete program with 4 blinking LED&#8217;s, one on each DIO pin of the JeeNode ports:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2010/02/Screen-shot-2010-02-03-at-01.13.19.png" border="0" alt="Screen shot 2010-02-03 at 01.13.19.png" width="196" height="112" /></p>

<p>That&#8217;s it. Compiles to roughly 2 Kb. Each extra blink adds just 20 bytes, btw.</p>

<p><em>And yes, it really makes four LEDs blink at an independent rate:</em></p>

<p><img src="http://jeelabs.org/wp-content/uploads/2010/02/DSC_11671.jpg" border="0" alt="DSC_1167.jpg" width="604" height="201" /></p>

<p>There is slightly more to it than that, but this is mind-blowing stuff. The &#8220;parallelism&#8221; is simulated, of course. Looks like the ATmega can do around <a href="http://www.transterpreter.org/blog/2009/06/day-twenty">6000 context switches</a> per second (i.e. parallel task switches).</p>

<p>There is a roughly 20 Kb interpreter part that needs to be uploaded <em>once</em> (which is why this requires at least an ATmega328). After that, the IDE will upload <a href="http://www.transterpreter.org/blog/2009/06/day-nineteen">just the bytecode</a> for your program, i.e. 2 Kb in the above case.</p>

<p><strong>B R I L L I A N T .</strong></p>

<p>Imagine hooking up the RF12 driver to this &#8211; there&#8217;s plenty of room for the extra 3 Kb or so. And for doing all sorts of things&#8230; <em>in parallel!</em> My earlier <span style="text-decoration: line-through;">complaint</span> <a href="http://jeelabs.org/2010/01/02/wasting-time/">post</a> about how awful it is to do several things at once on an ATmega board might just have been wiped off the table.</p>

<p><em>Looks like I&#8217;ve got some very serious learning ahead of me to try and get to grips with all this.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2010/02/04/fascinating-concurrency/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.583 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-23 10:30:01 -->

