<?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; Software</title>
	<atom:link href="http://jeelabs.org/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeelabs.org</link>
	<description>Computing stuff tied to the physical world</description>
	<lastBuildDate>Wed, 01 Feb 2012 23:01:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Putting the JNµ to sleep</title>
		<link>http://jeelabs.org/2012/01/18/putting-the-jnu-to-sleep/</link>
		<comments>http://jeelabs.org/2012/01/18/putting-the-jnu-to-sleep/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 23:01:41 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[LowPower]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17520</guid>
		<description><![CDATA[The Sleepy::loseSomeTime() code in the Ports library was never tested on a JeeNode Micro. Turns out that only a minor library difference kept it from working (the arduino-tiny library has its own version of millis(), etc): So now, the JNµ can be put to sleep as well. Here&#8217;s the jouleTest sketch I used, tweaked to [...]]]></description>
			<content:encoded><![CDATA[<p>The <em>Sleepy::loseSomeTime()</em> code in the Ports library was never tested on a <a href="/jm1">JeeNode Micro</a>. Turns out that only a minor library difference kept it from working (the <a href="http://code.google.com/p/arduino-tiny/">arduino-tiny</a> library has its own version of <em>millis()</em>, etc):</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/Screen-Shot-2012-01-14-at-23.55.34.png" alt="Screen Shot 2012 01 14 at 23 55 34" border="0" width="432" height="337" /></p>

<p>So now, the JNµ can be put to sleep as well. Here&#8217;s the <a href="https://github.com/jcw/jeelib/blob/master/examples/RF12/jouleTest/jouleTest.ino">jouleTest</a> sketch I used, tweaked to run on the JNµ as well:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/Screen-Shot-2012-01-14-at-23.55.09.png" alt="Screen Shot 2012 01 14 at 23 55 09" border="0" width="376" height="450" /></p>

<p>And sure enough, about once every 10 seconds it shows that familiar packet-transmit current consumption:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/SCR88.png" alt="SCR88" border="0" width="604" height="476" /></p>

<p>The blue line is the AC-coupled supply voltage, a 3x AA Eneloop battery pack in this case. It supplies about 3.8V, but when running off a 1000 µF cap, it looks like this continues to work down to 1.8V (well below the RFM12B&#8217;s minimum 2.2V specs) &#8211; although with only about half the transmit power by then.</p>

<p>This current use <a href="http://jeelabs.org/2011/12/01/rf12-power-optimization/">fingerprint</a> is almost identical to the ATmega328 running this same code. Not surprising really, since it&#8217;s the RFM12B which determines most of the power consumption, not the ATmega vs ATtiny difference.</p>

<p><em>Onwards!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2012/01/18/putting-the-jnu-to-sleep/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Browsing the Arduino run-time code</title>
		<link>http://jeelabs.org/2012/01/10/browsing-the-arduino-run-time-code/</link>
		<comments>http://jeelabs.org/2012/01/10/browsing-the-arduino-run-time-code/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 23:01:47 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17394</guid>
		<description><![CDATA[The Arduino IDE is a thin wrapper around the avr-gcc compiler and the avr-libc run-time library. It also includes a fairly basic IDE, i.e. a text editor and conventions for managing projects, in the form of &#8220;sketches&#8221; and libraries. I prefer to use my own programmer&#8217;s editor, because it supports multiple programming languages and has [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://arduino.cc/en/Main/Software">Arduino IDE</a> is a thin wrapper around the <a href="http://gcc.gnu.org/">avr-gcc</a> compiler and the <a href="http://www.nongnu.org/avr-libc/">avr-libc</a> run-time library. It also includes a fairly basic IDE, i.e. a text editor and conventions for managing projects, in the form of &#8220;sketches&#8221; and libraries.</p>

<p>I prefer to use my own programmer&#8217;s editor, because it supports multiple programming languages and has a lot more features for software development (such as Git integration, code folding, and save-on-lose-focus). The Arduino IDE supports external editors by disabling its own one &#8211; which is an option in the preferences:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/external-edit.png" alt="External edit" title="external-edit.png" border="0" width="467" height="147" /></p>

<p>Now I can simply use my own editor and switch to the Arduino IDE for compiling and uploading.</p>

<p>One advantage of using an external editor, is that you can look at <em>other</em> source code than just your own sketches. In the rest of this post, I&#8217;m going to describe how to look at one of the most interesting parts of the Arduino IDE: its run-time library, i.e. the <a href="http://wiring.org.co/">Wiring</a> code which adds supports for everything which makes an <em>Arduino</em> different from the <em>ATmega&#8217;s</em> on which it is based.</p>

<blockquote>
  <p>Note: what follows is specific for Mac OSX, but apart from the location of these files and the editor used, you should be able to transpose all of this to your own beloved computer environment.</p>
</blockquote>

<p>The first task, is to figure out <em>where</em> the Arduino IDE&#8217;s run-time code is located. In Mac OSX, this code is located <em>inside</em> the Arduino application. To view this area, you can right-click on the Arduino app:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/Screen-Shot-2012-01-09-at-19.29.48.png" alt="Screen Shot 2012 01 09 at 19 29 48" title="Screen Shot 2012-01-09 at 19.29.48.png" border="0" width="337" height="62" /></p>

<p>This leads to the following directory structure:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/Screen-Shot-2012-01-09-at-19.28.16.png" alt="Screen Shot 2012 01 09 at 19 28 16" title="Screen Shot 2012-01-09 at 19.28.16.png" border="0" width="275" height="379" /></p>

<p>The interesting bits are inside the &#8220;hardware&#8221; folder:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/Screen-Shot-2012-01-09-at-19.48.091.png" alt="Screen Shot 2012 01 09 at 19 48 09" title="Screen Shot 2012-01-09 at 19.48.09.png" border="0" width="268" height="208" /></p>

<p>Here are the first few lines of &#8220;Arduino.h&#8221;, for example (this used to be &#8220;WProgram.h&#8221;):</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/Screen-Shot-2012-01-09-at-19.55.09.png" alt="Screen Shot 2012 01 09 at 19 55 09" title="Screen Shot 2012-01-09 at 19.55.09.png" border="0" width="220" height="312" /></p>

<p>These source files are where <em>everything</em> specific to the Arduino IDE&#8217;s runtime happens. The &#8220;Serial&#8221; object, and the &#8220;millis()&#8221; code, for example. If you want to really understand what the Arduino is about, then it&#8217;s well worth going through some of these files. As you&#8217;ll find out, there&#8217;s <a href="http://jeelabs.org/2011/12/15/the-steepness-dilemma/">no magic</a> once you start looking in the right places.</p>

<p><em>Try it!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2012/01/10/browsing-the-arduino-run-time-code/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Low-power blink test</title>
		<link>http://jeelabs.org/2012/01/08/low-power-blink-test/</link>
		<comments>http://jeelabs.org/2012/01/08/low-power-blink-test/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 23:01:59 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[LowPower]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17234</guid>
		<description><![CDATA[Here is a new snoozeBlink sketch which can run off the new experimental 12 mW Low-power Supply: It does all the right things to start off in low-power mode and puts the ATmega to sleep, even as the LED blinks! The LED is a normal red LED with a forward voltage of about 1.6V and [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a new <a href="https://github.com/jcw/jeelib/blob/master/examples/Ports/snoozeBlink/snoozeBlink.ino">snoozeBlink</a> sketch which can run off the new experimental 12 mW <a href="http://jeelabs.org/2011/12/28/finished-low-power-supply/">Low-power Supply</a>:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-28-at-14.48.03.png" alt="Screen Shot 2011 12 28 at 14 48 03" border="0" width="419" height="365" /></p>

<p>It does all the right things to start off in low-power mode and puts the ATmega to sleep, <em>even as the LED blinks!</em></p>

<p>The LED is a normal red LED with a forward voltage of about 1.6V and with a 470 Ω series resistor. The result:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR03.png" alt="SCR03" border="0" width="604" height="442" /></p>

<p>(lots of noise because I&#8217;m using the default 1:10 probe and the scope at its most sensitive 1 mV/div setting)</p>

<p>Voltage over the 100 µF reservoir cap in blue, current consumption in yellow.
You can see the startup dip when the cap reaches about 6V, then the 2s wait, and then the LED blink at about 2 Hz with a 10% duty cycle. There&#8217;s not much energy to spare &#8211; the reservoir cap doesn&#8217;t even get a chance to <em>fully</em> re-charge between blinks.</p>

<p>After about 4 seconds, I turned off the power to find out what would happen. Yet there&#8217;s <em>still</em> enough energy left to get two more full blinks, and then an aborted blink as the reservoir cap voltage drops below 3V.</p>

<p>Note how the power consumption is just 3 mA while the LED is turned on. The ATmega itself is hardly ever running (the very brief 10 mA peaks got filtered out in this scope capture).</p>

<p>It can even be made to flash with a 26 mA LED current (omitting the resistor) for 16 ms @ 2 Hz. In this case the reservoir cap voltage varied from 9.4 to 4.4 V, again leaving very little energy to spare. Maybe one day this can be refined to drive a TRIAC, which needs very frequent but brief pulses (a BT137, BTA312, or L6004L3?).</p>

<p><em>But there&#8217;s actually something extra-ordinary going on with that power-up sequence &#8211; let&#8217;s investigate:</em></p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR04.png" alt="SCR04" border="0" width="604" height="442" /></p>

<p>The BIG surprise? This is running on a <em>standard</em> JeeNode with <em>standard</em> bootstrap &#8211; no power-up troubles at all!</p>

<p>Let me try and interpret everything happening in that last image:</p>

<ul>
<li>the initial very high blip (over 25 mA) is the JeeNode&#8217;s on-board 10 µF capacitor charging up</li>
<li>the 65 ms @ 3.2 mA is the clock startup delay, as defined by the default fuse setting</li>
<li>up to this point, the reservoir cap has lost some 2V of its charge</li>
<li>the next blip is the boot loader passing control <em>immediately</em> to the sketch (!)</li>
<li>then there&#8217;s the 32 ms <em>loseSomeTime()</em> call in <em>setup()</em>, with the ATmega finally powered down</li>
<li>the last blip at the right-end side of the screen puts the RFM12B into low-power sleep mode</li>
</ul>

<p>So what&#8217;s going on, and above all why is the <a href="http://jeelabs.org/2011/11/30/all-power-up-puzzles-solved/">boot loader problem</a> gone, after all that trouble it gave me before?</p>

<p>The only explanation I can think of lies in the one change I made since then: I&#8217;m now using OptiBoot v4.4 &#8230; and it probably does the right thing, in that it <em>skips</em> the boot loader on power-up and only goes through a boot-loader sequence on reset. This is the well known <a href="http://www.ladyada.net/library/arduino/bootloader.html">ladyada fix</a>. I guess my previous boot loader setup wasn&#8217;t using that.</p>

<p>This is <em>really</em> good news. It means you just need a recently-flashed ATmega and you can continue to use the normal FTDI upload mechanism while fooling around with this ultra low-power stuff. Even the 10 µF cap and regulator on the JeeNode can be left in when powering it from the new Low-power supply.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2012/01/08/low-power-blink-test/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Getting ready for OptiBoot 4.4</title>
		<link>http://jeelabs.org/2012/01/07/getting-ready-for-optiboot-4-4/</link>
		<comments>http://jeelabs.org/2012/01/07/getting-ready-for-optiboot-4-4/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 23:01:49 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[ISP]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17344</guid>
		<description><![CDATA[Ok, it&#8217;s official &#8211; starting this week, all new ATmega&#8217;s here will be flashed with the OptiBoot 4.4 boot loader. It&#8217;s going to take a while for all current inventory units to &#8220;flush through the system&#8221; so to speak (both DIPs and SMDs), but at some point this month all ATmega&#8217;s will be running the [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, it&#8217;s official &#8211; starting this week, all <em>new</em> ATmega&#8217;s here will be flashed with the <a href="http://code.google.com/p/optiboot/">OptiBoot 4.4</a> boot loader.</p>

<p>It&#8217;s going to take a while for all current inventory units to &#8220;flush through the system&#8221; so to speak (both DIPs and SMDs), but at some point this month all ATmega&#8217;s will be running the same boot loader as the Arduino Uno. Faster, smaller, and &#8211; <em>hopefully</em> &#8211; no more troubles with Windows being unable to upload sketches through FTDI.</p>

<p>One of the things I&#8217;ve done is to turn one of the new <a href="/jb1">JeeNode Blocks</a> into a dedicated Portable ISP Programmer for DIP-28&#8242;s. It&#8217;s the same <em>isp&#95;repair2</em> sketch as before (modified for the  Block&#8217;s minor pin allocation diff&#8217;s):</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/DSC_2847.jpg" alt="DSC 2847" border="0" width="604" height="464" /></p>

<p>Note the 16 MHz resonator behind the ZIF socket. Here&#8217;s the wiring:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/DSC_2848.jpg" alt="DSC 2848" border="0" width="604" height="420" /></p>

<p>There&#8217;s no 10 kΩ pull-up resistor for RESET, because ATmega&#8217;s have a (weak) built-in pull-up.</p>

<p>To avoid the delay-on-hardware-reset, I&#8217;ve added a push-button which <em>briefly</em> shorts +3V and GND together through a 10 µF electrolytic cap. Enough to force the JeeNode Block into a hardware reset. There&#8217;s a 10 kΩ resistor across the cap to discharge it afterwards. This is really quick because the reset occurs on button <em>press</em> i.s.o. <em>release</em>.</p>

<p>The savings are minimal &#8211; <em>just 1..2 seconds more for the standard bootstrap</em> &#8211; but for production, it matters. Total flash time, including boot loader, RF12demo sketch, and setting all the fuses is now just a few seconds:</p>

<ul>
<li>insert DIP chip</li>
<li>close ZIF socket</li>
<li>press button</li>
<li>wait for two LED blinks</li>
<li>open ZIP socket</li>
<li>remove programmed chip</li>
<li>rinse and repeat&#8230;</li>
</ul>

<p>When a serial port is connected via FTDI, you can see the progress of it all:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2012/01/Screen-Shot-2012-01-04-at-20.01.421.png" alt="Screen Shot 2012 01 04 at 20 01 42" border="0" width="559" height="213" /></p>

<p>Now let&#8217;s just hope that this version of OptiBoot doesn&#8217;t lead to the same mess as the previous one.</p>

<p>If you have older JeeNodes or other ATmega328 boards running previous bootstrap loaders, I suggest looking at the recent <a href="http://jeelabs.org/2012/01/04/isp-programmers/">ISP programmer</a> post and the older <a href="http://jeelabs.org/2011/05/29/summary-of-isp-options/">summary</a>. You might consider bringing all units up to date, because with a mix of boot loaders you end up <em>constantly</em> using the wrong one in the IDE and having to adjust board types each time.</p>

<p>Just be careful when messing with boot loaders. If the process goes wrong <em>and</em> you pick the wrong fuse settings, then you can end up with a &#8220;bricked&#8221; unit (only a high-voltage programmer can recover from such a state).</p>

<p><em>But apart from that: enjoy the doubled 115.2 Kbaud upload speed and the 1.5 Kb extra space for sketches!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2012/01/07/getting-ready-for-optiboot-4-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pin-change interrupts for RF12</title>
		<link>http://jeelabs.org/2012/01/06/pin-change-interrupts-for-rf12/</link>
		<comments>http://jeelabs.org/2012/01/06/pin-change-interrupts-for-rf12/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 23:01:39 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17338</guid>
		<description><![CDATA[The recently released (limited-edition) JeeNode Block has a couple of changes w.r.t. pin allocation, most notably the RFM12B&#8217;s &#8220;nIRQ&#8221; interrupt pin. This was moved from PD2 to PB1 (Arduino digital pin 2 to pin 9). The main reason for this change was to free the entire set op pins on PORTD, i.e. PD0..PD7 &#8211; in [...]]]></description>
			<content:encoded><![CDATA[<p>The recently released (limited-edition) <a href="/jb1">JeeNode Block</a> has a couple of changes w.r.t. pin allocation, most notably the RFM12B&#8217;s &#8220;nIRQ&#8221; interrupt pin. This was moved from PD2 to PB1 (Arduino digital pin 2 to pin 9). The main reason for this change was to free the entire set op pins on PORTD, i.e. PD0..PD7 &#8211; in Arduino-speak: digital pin 0 through 7.</p>

<p>That means interrupts are no longer coming in over the INT0 line, and can no longer use the <em>attachInterrupt()</em> and <em>detachInterrupt()</em> functions in the Arduino run-time library. Instead, the RF12 driver needs to switch to pin-change interrupts, which I&#8217;ve now added to the <a href="https://github.com/jcw/jeelib/commit/f616eb2731b34f57be60c27c96130e35753946fa">code on GitHub</a>.</p>

<p>To use the RF12 driver with the JeeNode Block, you need to make the following changes:</p>

<ol>
<li><p>Get the latest version of JeeLib from <a href="https://github.com/jcw/jeelib">GitHub</a></p></li>
<li><p>Enable pin-change interrupts by removing the comment so it defines <code>PINCHG_IRQ</code>:</p>

<pre><code>    #define PINCHG_IRQ 1
</code></pre></li>
<li><p>Change the <code>RFM_IRQ</code> define (make sure you pick the ATmega328 case):</p>

<pre><code>    // ATmega168, ATmega328, etc.
    #define RFM_IRQ 9
</code></pre></li>
<li><p>If you plan to use <code>RF12demo.ino</code> &#8211; don&#8217;t forget to change the LED pin to match the JeeNode Block:</p>

<pre><code>    #define LED_PIN 8
</code></pre></li>
<li><p>Compile and upload, and things should work as on any other JeeNode.</p></li>
</ol>

<p>Note that pin-change interrupts are a bit tricky. First of all, <em>changes</em> are not the same as responding to a <em>level</em> interrupt, but the new code should take care of that. More importantly, the RF12 driver assumes it&#8217;s the only one using pin changes on the corresponding &#8220;port&#8221; (in Atmel datasheet terminology). If you use more pins for port interrupts, you may have to adjust the RF12.cpp file.</p>

<p>These changes are not on by default, the latest RF12 driver comes configured for the original JeeNodes.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2012/01/06/pin-change-interrupts-for-rf12/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bit-banged I2C timing</title>
		<link>http://jeelabs.org/2012/01/03/bit-banged-i2c-timing/</link>
		<comments>http://jeelabs.org/2012/01/03/bit-banged-i2c-timing/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 23:01:00 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17160</guid>
		<description><![CDATA[The JeeNode Ports library has supported software-based I2C right from the start. There are some limitations to this approach, but it&#8217;s been very useful to allow connecting lots of I2C-based plugs on any of the 4 JeeNode &#8220;ports&#8221;. I&#8217;ve always suspected that the timing of this software &#8220;bit-banging&#8221; was off. Well&#8230; it&#8217;s waaaaay too slow [...]]]></description>
			<content:encoded><![CDATA[<p>The JeeNode <a href="http://jeelabs.net/projects/cafe/wiki/Ports">Ports</a> library has supported <em>software-based</em> <a href="http://en.wikipedia.org/wiki/I²C">I2C</a> right from the start. There are some limitations to this approach, but it&#8217;s been very useful to allow connecting <a href="http://jeelabs.net/projects/hardware/wiki/">lots</a> of I2C-based plugs on any of the 4 JeeNode &#8220;ports&#8221;.</p>

<p>I&#8217;ve always suspected that the timing of this software &#8220;bit-banging&#8221; was off. Well&#8230; it&#8217;s <em>waaaaay</em> too slow in fact:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR651.png" alt="SCR65" border="0" width="604" height="468" /></p>

<p>That&#8217;s a JeeNode talking to an <a href="http://jeelabs.net/projects/hardware/wiki/RTC_Plug">RTC Plug</a> over I2C, set to 400 KHz. <em>Except that it&#8217;s talking at a mere 40 KHz!</em></p>

<p>The code works, of course. It&#8217;s just far from optimal and wasting time. The main reason for this is that the Arduino&#8217;s <em>digitalWrite()</em>, <em>digitalRead()</em>, and <em>pinMode()</em> calls take a <a href="http://jeelabs.org/2010/01/06/pin-io-performance/">huge</a> amount of time &#8211; due to their generality. A second problem is that the <em>delayMicroSeconds()</em> call actually has a granularity of 4 µs.</p>

<p>As a quick test, I hard-coded the calls in the <a href="https://github.com/jcw/jeelib/blob/master/Ports.h#L136">Ports.h</a> header to use much more efficient code:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-24-at-16.25.56.png" alt="Screen Shot 2011 12 24 at 16 25 56" border="0" width="401" height="323" /></p>

<p>The result is that I2C can now run at over 300 KHz, and it still works as expected:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR661.png" alt="SCR66" border="0" width="604" height="342" /></p>

<p>It can even run at over 600 KHz, which is beyond the official I2C specs, but it works fine with many I2C chips:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR67.png" alt="SCR67" border="0" width="604" height="342" /></p>

<p>Except that this now <em>requires</em> a pull-up resistor on SDA (i.e. the AIO pin). The rise-time of the data pulses is now too low to work reliably off the internal ATmega pull-up resistors. I used a 1 kΩ resistor, as pull-up to 3.3V:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR68.png" alt="SCR68" border="0" width="604" height="175" /></p>

<p>Note the glitch at the end &#8211; it&#8217;s probably from emulating open-collector logic with the ATmega&#8217;s three-state pins.</p>

<p>Pull-ups are also a very good idea with shorter bus lines, because they also lower the impedance of the wire, reducing noise. These tests were all done with the RTC Plug stuck directly into the Port 1 header, BTW.</p>

<p>Here&#8217;s the SDA signal on a 5 µs/div scale &#8211; via 4 <a href="http://jeelabs.net/projects/hardware/wiki/Extension_Cables">Extension Cables</a> back to back, i.e. 65 cm &#8211; <strong>with</strong> 1 kΩ pull-up:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR701.png" alt="SCR70" border="0" width="604" height="78" /></p>

<p>And <strong>without</strong> &#8211; showing <em>abysmal</em> rise times and lots of <a href="http://en.wikipedia.org/wiki/Crosstalk_%28electronics%29">crosstalk</a>, making I2C on this hookup totally useless:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR691.png" alt="SCR69" border="0" width="604" height="78" /></p>

<p>I&#8217;ll need to figure out how to properly implement these software optimizations one day, since that means we can&#8217;t just use the generic I/O pin calls anymore. There are several cases: different speeds as well as different ports (including &#8220;port 0&#8243; which uses A5 and A6, the official I2C pins &#8211; but still in bit-banged mode).</p>

<p>All in all, this software-based I2C works fine, with the advantage of supporting it on any two I/O pins &#8211; but it could be optimized further. The other thing to keep in mind is that the SCL clock line is <em>not</em> open-collector, but driven by a normal <a href="http://en.wikipedia.org/wiki/Totem_pole_output">totem pole</a> output pin, so this doesn&#8217;t support I2C <a href="http://www.i2c-bus.org/clock-stretching/">clock stretching</a> for slow (or busy) slaves.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2012/01/03/bit-banged-i2c-timing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scheduler power optimization</title>
		<link>http://jeelabs.org/2012/01/02/scheduler-power-optimization/</link>
		<comments>http://jeelabs.org/2012/01/02/scheduler-power-optimization/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 23:01:35 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[LowPower]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17082</guid>
		<description><![CDATA[Last year&#8217;s post showed how a packet transmission w/ ACK reception works out in terms of power consumption. It also uncovered a fairly large &#8220;power consumption bug&#8221;, with the scheduler idling only 0.1s at a time, causing the ATmega to exit power-down mode through its watchdog far more often than necessary. Here&#8217;s the relevant code [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jeelabs.org/2011/12/30/anatomy-of-a-room-node-transmission/">Last year&#8217;s post</a> showed how a packet transmission w/ ACK reception works out in terms of power consumption. It also uncovered a fairly large &#8220;power consumption bug&#8221;, with the scheduler idling only 0.1s at a time, causing the ATmega to exit power-down mode through its watchdog far more often than necessary.</p>

<p>Here&#8217;s the relevant code in the general-purpose Scheduler class in <a href="https://github.com/jcw/jeelib/blob/master/Ports.cpp#L863">Ports.cpp</a>:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-21-at-19.00.38.png" alt="Screen Shot 2011 12 21 at 19 00 38" border="0" width="474" height="211" /></p>

<p>And here&#8217;s what I &#8216;m going to change it to, to optimize and stay powered-down much longer:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/Screen-Shot-2011-12-21-at-19.00.10.png" alt="Screen Shot 2011 12 21 at 19 00 10" border="0" width="472" height="226" /></p>

<p>This changes the wake-up period from 30 times per second, to roughly once every 8s, with blips like this:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR582.png" alt="SCR58" border="0" width="604" height="478" /></p>

<p>My interpretation of this picture, is that the ATmega on this JeeNode needs a <em>whopping</em> 10 mA of power for 50 µs once every eight seconds to keep going. That 1 ms &#8220;lead-in&#8221; at &lt; 1 mA is probably clock startup, or something.</p>

<p>This current draw is the same as before (this capture was with PIR installed). But instead of 1800 wake-ups per minute, there will now be 10 or so. This will reduce the power consumption from 2,000 µC to roughly 10 µC!</p>

<p>Does that mean the Room Node will now last 200 times longer on a single battery? Unfortunately, no. With these low-power games, the weakest link determines total battery life. In this case, there&#8217;s a PIR sensor which has to be constantly on, drawing about 50 µA. That&#8217;s 3,000 microcoulombs per minute.</p>

<p>But still, this little optimization should add quite a bit to the lifetime of a battery:</p>

<ul>
<li>old: 3000 (PIR) + 130 (radio) + 600 (estimated) ATmega/regulator + 2,000 (scheduler) = 5730 µC/min</li>
<li>new situation, again per minute: 3,000 + 130 + 600 + 10 = 3740 µC/min</li>
</ul>

<p>If you&#8217;re wondering what &#8220;microcoulombs/minute&#8221; means: that&#8217;s just current, so rescaling it to µC/s (i.e. µA&#8217;s), we get: old ≈ 96 µA, new = 63 µA. With a 2000 mAh 3x AA battery pack, that&#8217;s 2.5 vs 3.6 <em>years</em> of run time.</p>

<p>Note that these values are fairly optimistic. With motion in the room, there will be more than one packet transmission per minute. I have yet to see the real-life battery life of these room nodes, although right now it&#8217;s looking quite good: the nodes I have around here have been working for many months &#8211; <em>2012 will tell!</em></p>

<p><em>But either way, that change of just a few lines of C code should add about 50% to the battery life. Crazy, eh?</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2012/01/02/scheduler-power-optimization/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tempus fugit &#8230;</title>
		<link>http://jeelabs.org/2011/12/31/tempus-fugit/</link>
		<comments>http://jeelabs.org/2011/12/31/tempus-fugit/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 23:01:51 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17137</guid>
		<description><![CDATA[Another year is about to end, and the next one is already anxiously waiting to carry us along into the future&#8230; A fitting moment to get that Dutchtronix clock working (a lot easier than this geek version): I bought this little kit long ago, not realizing that a low-end USB scope front-end can&#8217;t deal with [...]]]></description>
			<content:encoded><![CDATA[<p><em>Another year is about to end, and the next one is already anxiously waiting to carry us along into the future&#8230;</em></p>

<p>A fitting moment to get that <a href="http://www.dutchtronix.com/ScopeClockH3-1-Enhancedfaq.htm">Dutchtronix clock</a> working (a lot easier than this <a href="http://www.dutchtronix.com/CRTClocks.htm">geek</a> version):</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/DSC_2832.jpg" alt="DSC 2832" border="0" width="604" height="453" /></p>

<p>I bought this little kit long ago, not realizing that a low-end USB scope front-end can&#8217;t deal with it. Besides, it turns out that it didn&#8217;t work back then because of some bad solder joints (ground planes and 15W soldering irons don&#8217;t go well together &#8211; even my <a href="http://jeelabs.org/2010/06/08/smd-hand-soldering-tools/">current</a> soldering iron has trouble heating up some of those pads!).</p>

<p>Anyway, this is as far as the Hameg HMO2024 will go:</p>

<p><img src="http://jeelabs.org/wp-content/uploads/2011/12/SCR602.png" alt="SCR60" border="0" width="594" height="448" /></p>

<p>Recognizable, but a <a href="http://www.knutsel.org/2010/09/19/dutchtronix-avr-oscilloscope-clock/">far cry</a> from what analog scopes can do. That&#8217;s what you get when digital sampling, waveform refresh rates, and vector drawing clash (bumping up the sampling rate causes a fuller, but flickering, image).</p>

<p>This design was from 2007, I think &#8211; which goes to show that fun stuff (especially clocks) can be time-less!</p>

<p><em>I wish you a healthy, safe, and happy 2012 &#8211; with lots of opportunities to tinker, learn, and create.</em></p>

<p><strong>Update</strong> &#8211; for another example of how such X-Y displays differ between analog and high-end vs low-end DSO&#8217;s, see <a href="http://www.eevblog.com/2011/03/08/eevblog-153-youscope-demo-on-a-digital-scope/">this video</a> on Dave Jones&#8217; EEVblog.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2011/12/31/tempus-fugit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Out with the old &#8211; in with the new!</title>
		<link>http://jeelabs.org/2011/12/29/out-with-the-old-in-with-the-new/</link>
		<comments>http://jeelabs.org/2011/12/29/out-with-the-old-in-with-the-new/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 23:01:32 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[AVR]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17098</guid>
		<description><![CDATA[Le roi est mort &#8230; It&#8217;s time to move on. I&#8217;m dropping all support and maintenance of the Ports and RF12 libs, as well as some others. Well, as far as subversion is concerned. All files are kept read-only at svn.jeelabs.org &#8211; for reference. &#8230; vive le roi! But the good news is that all [...]]]></description>
			<content:encoded><![CDATA[<p><em>Le roi est mort &#8230;</em></p>

<p>It&#8217;s time to move on. I&#8217;m dropping all support and maintenance of the <a href="http://jeelabs.net/projects/cafe/wiki/Ports">Ports</a> and <a href="http://jeelabs.net/projects/cafe/wiki/RF12">RF12</a> libs, as well as <a href="http://jeelabs.net/projects/cafe/wiki/Libraries">some others</a>. Well, as far as subversion is concerned. All files are kept read-only at <em>svn.jeelabs.org</em> &#8211; for reference.</p>

<p><em>&#8230; vive le roi!</em></p>

<p>But the good news is that all this software has now been moved and updated on <a href="https://github.com/">GitHub</a> &#8230; and is <em>fully</em> supported.</p>

<p>All libraries on GitHub have been adjusted to work with Arduino IDE 1.0 (they may or may not still work on 0022 or 0023, but that will be supported only to the point of accepting patches to increase backward compatibility).</p>

<p>There is one change which I&#8217;ve been meaning to get to for a long time: the Ports and RF12 libraries have been combined into a new library called <a href="https://github.com/jcw/jeelib">JeeLib</a>. This means that you no longer have to include &#8220;Ports.h&#8221; <em>and</em> &#8220;RF12.h&#8221; at the start of your sketches (although those still continue to work). Instead, insert this one line instead:</p>

<pre><code>    #include &lt;JeeLib.h&gt;
</code></pre>

<p>All the examples from both libraries have been retained, but make sure that the old Ports and RF12 are gone.</p>

<p>There are three other libraries for the JeeNodes which you may be using: <a href="https://github.com/jcw/ethercardhttps://github.com/jcw/ethercard">EtherCard</a>, <a href="https://github.com/jcw/glcdlib">GLCDlib</a>, and <a href="https://github.com/jcw/rtclib">RTClib</a>. These too are now on GitHib and have all been adapted for use with Arduino IDE 1.0.</p>

<p>So how does one start <em>using</em> any of these libraries? Ah, glad you asked :)</p>

<ul>
<li>go to <a href="https://github.com/jcw">GitHub</a>, and pick the library you&#8217;re interested in to get to its home page</li>
<li>at the bottom of each home page is a README section with the latest info &#8211; always worth a check</li>
<li>one of the links at the top is marked &#8220;ZIP&#8221; &#8211; you <em>could</em> click it to download everything as ZIP archive</li>
<li><em>&#8230; but you shouldn&#8217;t !</em></li>
</ul>

<p>The reason for this is <a href="http://jeelabs.org/2011/12/27/the-convenience-of-git/">Git</a>. If you download a ZIP archive, unpack it, and install it in the right place (which is in the &#8220;libraries&#8221; folder where all your sketches are), then you&#8217;ll get a <em>copy</em> of the code your after, but no way to stay up to date. That might sound like a minor detail, but with open source, there are usually <em>many</em> changes over time. Bug fixes as well as new features. If you grabbed a ZIP file, then you&#8217;ll be forced to re-install the next version over the previous one every time there is an update. This quickly gets very boring, and can lead to all sorts of awful mistakes, such as overwriting a file you had <em>fixed</em> in some way (after a lengthy debug session, long ago).</p>

<p>I can&#8217;t stress it enough: don&#8217;t grab open source software and install it on your disk by just downloading and unpacking it. Not just the stuff from JeeLabs &#8211; any open source software distributed in source code form. It&#8217;s a nuisance, a ticking time bomb, a mine field, a disaster waiting to happen &#8211; <em>get the message?</em></p>

<p>There is only one <a href="http://jeelabs.org/2011/12/27/the-convenience-of-git/">sane / long-term approach</a> to working with source code, and that&#8217;s through a <a href="http://en.wikipedia.org/wiki/Revision_control">Version Control System</a>. In this case Git &#8211; in combination with <a href="https://github.com/jcw">GitHub</a>, which is the web site where all source code is stored.</p>

<p>So instead of downloading a ZIP or TAR archive, you need to create a &#8220;clone&#8221; of the original code on GitHub. The difference with the ZIP archive is that a clone knows where it came from, and gives you the ability to find out what changed, to instantly update your clone, or to revert to <em>any</em> older version, since GitHub keeps track of <em>all</em> versions of the code &#8211; past, present, and future.</p>

<p>The trick is to get started with Git and GitHub without drowning in the capabilities they offer. <em>How</em> depends on the environment you&#8217;re in:</p>

<ul>
<li><p>On <em>Windows</em>, you can install <a href="http://code.google.com/p/tortoisegit/">TortoiseGit</a> &#8211; then you need to get that clone onto your machine. For JeeLib, you&#8217;ll probably need to enter this path to it somewhere: <code>git://github.com/jcw/jeelib.git</code></p></li>
<li><p>On <em>Mac OSX</em>, you need to install the Xcode developer tools, which includes Git (it&#8217;s a free install from the App Store). If you have an account at GitHub (or don&#8217;t mind getting one, it&#8217;s free), then I highly recommend getting the <a href="http://mac.github.com/">GitHub for Mac</a> application. If not, you can always use the command line, like so:</p>

<pre><code>    cd ~/Documents/Arduino/libraries
    git clone git://github.com/jcw/jeelib.git
</code></pre></li>
<li><p>On <em>Linux</em>, you need to install git through whatever package manager you&#8217;re using. On Debian / Ubuntu, this command line will probably do it:</p>

<pre><code>    sudo apt-get install git-core
</code></pre>

<p>After that, it&#8217;s the same as the Mac OSX command-line version, i.e. &#8220;cd &#8230;&#8221; and &#8220;git clone &#8230;&#8221; (see above).</p></li>
</ul>

<p>So far, this is only a little more involved than grabbing that ZIP file. The gains start when you want to update your copy to the latest version. In git-speak, this is called &#8220;pulling&#8221; the latest changes (to your local disk). I encourage you to search around on the web, it&#8217;s usually as simple as doing &#8220;git pull&#8221; from inside the cloned area (from the command-line, some GUI, whatever). The difference with re-installing is absolute security &#8211; &#8220;git pull&#8221; will <em>never</em> overwrite or lose any changes you made, if they conflict with the original.</p>

<p>If all you do is track changes from time to time, then this is all you need to benefit from Git and GitHub.</p>

<p>If you actually make changes, then you&#8217;ll need to dig a little deeper when a &#8220;conflict&#8221; occurs, meaning you&#8217;ve made a change which interferes with changes made in the original on GitHub. But on the plus side, you&#8217;ll also be able to <em>easily</em> submit your changes (GitHub calls this &#8220;making a pull request&#8221;, i.e. pulling your changes back <em>into</em> the original).
Why bother? <em>Because contributions, no matter how small, are what make open source software fly!</em></p>

<p><em>Welcome to the world of open source software collaboration &#8211; where code lives, evolves, and grows.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2011/12/29/out-with-the-old-in-with-the-new/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The convenience of &#8220;Git&#8221;</title>
		<link>http://jeelabs.org/2011/12/27/the-convenience-of-git/</link>
		<comments>http://jeelabs.org/2011/12/27/the-convenience-of-git/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 23:01:24 +0000</pubDate>
		<dc:creator>jcw</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jeelabs.org/?p=17093</guid>
		<description><![CDATA[I&#8217;ve written before about source code respositories and Subversion / Git &#8211; about a year ago, in fact. Suprisingly, lots of people working on software are still not using any &#8220;Version Control System&#8221; (VCS) ! So let me try a new angle today, and show you how you need only use 5% of those systems [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written before about <a href="http://jeelabs.org/2010/12/14/source-code/">source code respositories</a> and <a href="http://subversion.apache.org/">Subversion</a> / <a href="http://www.google.nl/url?sa=t&amp;rct=j&amp;q=git&amp;source=web&amp;cd=1&amp;ved=0CC0QFjAA&amp;url=http%3A%2F%2Fgit-scm.com%2F&amp;ei=22_yTuDXFdGh-Qai8qG0AQ&amp;usg=AFQjCNHBOAWIJWLQ6wmj_GErAgGzWCkTbA">Git</a> &#8211; about <a href="http://jeelabs.org/2010/12/15/subversion/">a year ago</a>, in fact.</p>

<p><em>Suprisingly, lots of people working on software are still not using any &#8220;Version Control System&#8221; (<a href="http://en.wikipedia.org/wiki/Revision_control">VCS</a>) !</em></p>

<p>So let me try a new angle today, and show you how you need only use 5% of those systems to get a huge benefit out of them when dealing with the Arduino sketches and libraries from JeeLabs. Since all the code from JeeLabs is now located at <a href="https://github.com/jcw">GitHub</a>, the rest of this post will be about Git (and GitHub, a truly phenomenal free web resource).</p>

<p>Why bother with a VCS? Well&#8230; I once heard of a little anecdote about a sign at the dentist, which said:</p>

<blockquote>
  <p>&#8220;You don&#8217;t have to floss all your teeth, just the ones you want to keep.&#8221;</p>
</blockquote>

<p>It&#8217;s a bit like that with source code. If you don&#8217;t write code, or don&#8217;t ever change it, then you don&#8217;t need to manage it. But if you do, then you know how much effort goes into a working sketch, library, script, program, etc. Things change &#8211; either your own code, libraries from others, tools like the Arduino IDE (1.0 broke lots of stuff), even core computer software or hardware. Things always change, and if you want to be able to deal with it, you need VCS.</p>

<p>Not everyone aspires to be a full-time software developer (what an odd world that would be!), but even in the simplest situations you can benefit from version control. Here&#8217;s a possible scenario, close to <del>home</del> JeeLabs:</p>

<ul>
<li>Suppose you want to use the <a href="https://github.com/jcw/ethercard">EtherCard</a> library, but not necessarily with the JeeLabs <a href="http://jeelabs.net/projects/hardware/wiki/Ether_Card">Ether Card</a> hardware.</li>
<li>The GitHub page includes a README at the bottom, with a link to the ZIP archive with all the code.</li>
<li>So you download the ZIP, unpack it, and <a href="http://www.arduino.cc/en/Reference/Libraries">figure out</a> where to put it so the Arduino IDE can find it.</li>
<li>Say you want to try out the &#8220;backSoon&#8221; example, as demo of a tiny web server. You compile and upload.</li>
<li><em>It doesn&#8217;t work</em> &#8211; now what? After a lot of digging and searching, you figure out that the code was written for the SPI select signal tied to Arduino&#8217;s digital pin 8 (PB0) whereas your hardware uses pin 10 (PB2).</li>
<li>After that it&#8217;s easy: change &#8220;<code>#define SELECT_BIT 0</code>&#8221; to &#8220;<code>#define SELECT_BIT 2</code>&#8221; in <a href="https://github.com/jcw/ethercard/blob/master/enc28j60.cpp#L243">enc28j60.cpp</a>.</li>
<li>Fantastic, you&#8217;ve cut through the problem and made the EtherCard library work for you. Congratulations!</li>
</ul>

<p>This is a typical case: code was written for a specific purpose, but a small change makes it more widely usable.</p>

<p>I picked this example, because it is likely that we&#8217;ll update the EtherCard library soon to support different pins at runtime. That&#8217;ll allow you to leave the EtherCard library alone and set things up in your sketch, i.e. at run time. Note that it&#8217;s always a trade-off &#8211; some things usually become more general, but only if there&#8217;s a need. You can&#8217;t write code to cover <em>all</em> the cases. Well, you could, but then you end up with a nightmare (I won&#8217;t give examples).</p>

<p>So sometime in the near future, there will be an update to the EtherCard library. <em>That&#8217;s when trouble starts&#8230;</em></p>

<p>Because there are now <em>three</em> different versions of the EtherCard library, and you&#8217;re about to create a fourth:</p>

<ul>
<li>the original EtherCard library on GitHub</li>
<li>your copy of that library, on your disk, with a tiny change made to it</li>
<li>the updated! improved! whiter-than-white! new EtherCard library on GitHub</li>
<li>your copy of the new library, which you&#8217;re now forced to update and adjust again</li>
</ul>

<p>There&#8217;s more going on: in this particular case, that update made your small change superfluous. But now the API of the EtherCard library has changed, so you need to change each of your sketches <em>using</em> the EtherCard library.</p>

<p>It&#8217;s not hard to see how these little details can turn into a nightmare. You build something, and you end up having to keep track of all sorts of dependencies and changes on your disk. Worse: everyone is wasting their time on this!</p>

<p>Version control systems such as Git can do a lot more, but the <em>key</em> benefit they offer can be summarized as:</p>

<blockquote>
  <p>You can easily manage THREE different versions of all the source files: the OLD, the NEW, and YOURS.</p>
</blockquote>

<p>So if all you want is to use open source code and stay up to date, then Git lets you do that &#8211; even if you make changes yourself in any of those files. And it gets even better: if your changes have nothing to do with the changes made to the original code, then all you need to do is to issue the &#8220;git pull&#8221; command, and the remote changes will be <em>folded</em> into your local copy of the source file &#8211; chances are that you can simply re-compile, upload, and keep on running <em>with the latest updates!</em></p>

<p>If your local changes do interfere or overlap with the changes made to the original code, then &#8220;git pull&#8221; will detect this and avoid making the changes to prevent it from altering yours (which always take precedence). This is called a &#8220;conflict&#8221; &#8211; and Git offers several (maybe too many) ways to deal with it.</p>

<p>For JeeLabs, all the code is now maintained on a free and public web site called <a href="https://github.com/">GitHub</a>. You don&#8217;t have to have an account there to browse or download any source code. You can not only see all the latest code, you can also look at any previous changes, including the <em>complete</em> history from the moment the first version was placed on GitHub.</p>

<p>Here&#8217;s an example: <a href="https://github.com/jcw/jeelib/commit/6f8415607ff6eef3966363751975c8f807ef9814">https://github.com/jcw/jeelib/commit/6f8415607ff6eef3966363751975c8f807ef9814</a></p>

<p>You&#8217;ll see a comment about the change, the list of files affected, and for each file an <em>exact</em> summary of the changes and some nearby lines for context. This change has been recorded forever. If logged in, you could even discuss it.</p>

<p>Even if you never intend to share your own changes and code, you can see how this resource lets you examine the code I&#8217;m providing, the changes I&#8217;m making to it over time, and the affected files. You can view a source file as it was at any point in time (wouldn&#8217;t it be great if this also included the future?).</p>

<p>Here&#8217;s one more gem: say you are looking at the <code>enc28j60.cpp</code> file, and wondering when what change was made. There&#8217;s a way to see where each change came from (and the look at that specific change in a larger context, for example). This annotated source file is generated by &#8220;git blame&#8221; &#8211; follow <a href="https://github.com/jcw/ethercard/blame/master/enc28j60.cpp">this link</a> as example.</p>

<p>So what VCS, Git, and GitHub offer is really no less than a <em>Time Machine</em>. But even if you don&#8217;t ever use that, Git gives you the ability to keep your code in sync with the changes happening in the original source code repository. And if something gets messed up, you can revert to an older version of the code &#8211; without having copies on your disk, which need to be given meaningful names so you can find them back. The &#8220;git diff&#8221; feature alone is worth it.</p>

<p>Wanna get started? Terrific. Cast your doubts aside, and keep in mind that you need a little time to get used to it.</p>

<p>How to start using <a href="http://git-scm.com/">Git</a> (and <a href="https://github.com/">GitHub</a>) depends a bit on your operating system: on Windows, best option might be to install <a href="http://code.google.com/p/tortoisegit/">TortoiseGit</a> (see also <a href="http://creatingcode.com/2010/02/getting-started-with-git-and-tortoisegit-on-windows/">this intro</a>, which goes a bit deeper). On the Mac, it&#8217;s included with the Xcode developer tools, but there&#8217;s actually a great app for it called <a href="http://mac.github.com/">GitHub for Mac</a>, and on Linux it&#8217;s probably one of the best supported packages out there, since it came from the same guy who made Linux possible in the first place&#8230;</p>

<p>With Git, you can stay up to date, you&#8217;ll never lose changes, and you never have to guess who changed what, when, where, why, or how. Is there a new update? Try it! Doesn&#8217;t work as expected? Back out! <em>It&#8217;s that simple.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jeelabs.org/2011/12/27/the-convenience-of-git/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.630 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-09 21:26:44 -->
<!-- Compression = gzip -->
