<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" version="2.0">

<channel>
	<title>Ruben's blog</title>
	
	<link>http://rubenlaguna.com/wp</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Mon, 24 Nov 2008 13:58:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<geo:lat>40.382644</geo:lat><geo:long>-3.77655</geo:long><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/RubensBlog" type="application/rss+xml" /><item>
		<title>Got my new Apple Lanyard Headphones</title>
		<link>http://rubenlaguna.com/wp/2008/11/20/got-my-new-apple-lanyard-headphones/</link>
		<comments>http://rubenlaguna.com/wp/2008/11/20/got-my-new-apple-lanyard-headphones/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 19:05:32 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[apple]]></category>

		<category><![CDATA[earbud]]></category>

		<category><![CDATA[ebay]]></category>

		<category><![CDATA[headphones]]></category>

		<category><![CDATA[lanyard]]></category>

		<category><![CDATA[store]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/?p=310</guid>
		<description><![CDATA[Amazing, the swedish apple store dont sell the old Apple Lanyard Headphones, the ones that fits in both Apple 1st generation and 3rd generation.

And I cannot buy it from the US Apple store either, they just don&#8217;t let you to do so. So at the end I reverted to EBay and I found a nice [...]]]></description>
			<content:encoded><![CDATA[<p>Amazing, the swedish apple store dont sell the <a href="http://store.apple.com/us/product/MA093G/B?mco=MTIxODk3Mw">old Apple Lanyard Headphones</a>, the ones that fits in both Apple 1st generation and 3rd generation.</p>

<p><div id="attachment_311" class="wp-caption aligncenter" style="width: 207px"><a href="http://www.flickr.com/photos/hucker/89026331/"><img src="http://rubenlaguna.com/wp/wp-content/uploads/2008/11/89026331_dcd5386f7f_m.jpg" alt="by Stephen Hucker" title="Apple Lanyard Headphones" width="197" height="240" class="size-full wp-image-311" /></a><p class="wp-caption-text">by Stephen Hucker</p></div></p>

<p>And I cannot buy it from the US Apple store either, they just don&#8217;t let you to do so. So at the end I reverted to EBay and I found a <a href="http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&#038;ssPageName=STRK:MEWNX:IT&#038;item=350121876326">nice offer</a> from <a href="http://www.buyitloveit.com">buyitloveit.com</a>($12  + $6.5 shipping). That&#8217;s halft the price listed on the Apple Store ($39.00) and they are new not used. The ebay description said that the packaging was damaged but the only thing I could find was a sticky mark  on the top of package. And it only took one week to deliver from UK to Sweden. Nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/11/20/got-my-new-apple-lanyard-headphones/feed/</wfw:commentRss>
		</item>
		<item>
		<title>“Reload in target plaform” is not working in Netbeans 6.1/6.5 RC2 in Mac OS X 10.5 Leopard</title>
		<link>http://rubenlaguna.com/wp/2008/11/19/reload-in-target-plaform-is-not-working-in-netbeans-6165-rc2-in-mac-os-x-105-leopard/</link>
		<comments>http://rubenlaguna.com/wp/2008/11/19/reload-in-target-plaform-is-not-working-in-netbeans-6165-rc2-in-mac-os-x-105-leopard/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 10:42:28 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[mac]]></category>

		<category><![CDATA[netbeans]]></category>

		<category><![CDATA[osx]]></category>

		<category><![CDATA[platform]]></category>

		<category><![CDATA[reload]]></category>

		<category><![CDATA[target]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/?p=306</guid>
		<description><![CDATA[I filed a bug report

http://www.netbeans.org/issues/show_bug.cgi?id=153354

It seems that it cannot find the inner class ResolvableHelper inside the TopComponent. (throws a NoClassDefFoundException, see the messages.log for details ). It&#8217;s funny though, because it works perfectly in Windows XP and Vista, I thought this stuff was platform independent.
]]></description>
			<content:encoded><![CDATA[<p>I filed a bug report</p>

<p><a href="http://www.netbeans.org/issues/show_bug.cgi?id=153354">http://www.netbeans.org/issues/show_bug.cgi?id=153354</a></p>

<p>It seems that it cannot find the inner class ResolvableHelper inside the TopComponent. (throws a NoClassDefFoundException, see the <a href="http://www.netbeans.org/nonav/issues/showattachment.cgi/73847/messages.log">messages.log</a> for details ). It&#8217;s funny though, because it works perfectly in Windows XP and Vista, I thought this stuff was platform independent.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/11/19/reload-in-target-plaform-is-not-working-in-netbeans-6165-rc2-in-mac-os-x-105-leopard/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Disable splash screen on your Netbeans Application</title>
		<link>http://rubenlaguna.com/wp/2008/11/19/disable-splash-screen-on-your-netbeans-application/</link>
		<comments>http://rubenlaguna.com/wp/2008/11/19/disable-splash-screen-on-your-netbeans-application/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 07:38:03 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[netbeans]]></category>

		<category><![CDATA[application]]></category>

		<category><![CDATA[disable]]></category>

		<category><![CDATA[rcp]]></category>

		<category><![CDATA[splash]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/?p=304</guid>
		<description><![CDATA[Just add

run.args.extra=&#8211;nosplash

to the project.properties file
]]></description>
			<content:encoded><![CDATA[<p>Just add</p>

<p>run.args.extra=&#8211;nosplash</p>

<p>to the project.properties file</p>
]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/11/19/disable-splash-screen-on-your-netbeans-application/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Arduino tilt sensor using MMA7260Q</title>
		<link>http://rubenlaguna.com/wp/2008/11/03/arduino-tilt-sensor-using-mma7260q/</link>
		<comments>http://rubenlaguna.com/wp/2008/11/03/arduino-tilt-sensor-using-mma7260q/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 21:27:16 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[electronics]]></category>

		<category><![CDATA[accelerometer]]></category>

		<category><![CDATA[arduino]]></category>

		<category><![CDATA[mma7260q]]></category>

		<category><![CDATA[sensor]]></category>

		<category><![CDATA[tilt]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/?p=291</guid>
		<description><![CDATA[I&#8217;ve playing with the MMA7260Q accelerometer. Following the indications in


    &#8220;Measuring Tilt with Low-g accelerometers&#8220;. 

    &#8220;Implementing Auto-zero calibration technique for accelerometers&#8220;
    &#8220;AN3461 Tilt Sensing Using Linear Accelerometers&#8221;   



I connected X,Y and Z of the MMA7260Q breakout to A0, A1 and A2 of the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve playing with the <a href="http://www.sparkfun.com/datasheets/Accelerometers/MMA7260Q-Rev1.pdf">MMA7260Q</a> accelerometer. Following the indications in</p>

<ul>
    <li>&#8220;<a href="http://www.freescale.com/files/sensors/doc/app_note/AN3107.pdf">Measuring Tilt with Low-g accelerometers</a>&#8220;. </li>

    <li>&#8220;<a href="http://www.freescale.com/files/sensors/doc/app_note/AN3447.pdf">Implementing Auto-zero calibration technique for accelerometers</a>&#8220;</li>
    <li>&#8220;<a href="http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf">AN3461 Tilt Sensing Using Linear Accelerometers</a>&#8221;   </li>

</ul>

<p>I connected X,Y and Z of the <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=252">MMA7260Q breakout</a> to A0, A1 and A2 of the Arduino. Then, GS1 and GS2 connected to ground to set the range to 1.5g. Ah, and of course, I connected ^SLEEP to VCC.</p>

<p>I managed to put together this piece of code that ouputs the tilt angles  &rho;(rho) , &phi;(phi); and &Theta;(heta) in degrees. I does automatic autozero calibration so before getting sensible results you should tilt the sensor around +/-90 degrees in every axis.</p>


<div class="wp_syntax"><div class="code"><pre class="c c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;math.h&gt;</span>
<span style="color: #339933;">#include &lt;float.h&gt;</span>
<span style="color: #339933;">#include &lt;limits.h&gt;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">int</span> valx <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">int</span> valy <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">int</span> valz <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
&nbsp;
<span style="color: #993333;">int</span> xaxis <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">int</span> yaxis <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span>;   
<span style="color: #993333;">int</span> zaxis <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span>;   
&nbsp;
<span style="color: #993333;">float</span> xa<span style="color: #339933;">=</span><span style="color:#800080;">0</span>;
<span style="color: #993333;">float</span> ya<span style="color: #339933;">=</span><span style="color:#800080;">0</span>;
<span style="color: #993333;">float</span> za<span style="color: #339933;">=</span><span style="color:#800080;">0</span>;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #993333;">int</span> minx <span style="color: #339933;">=</span> INT_MAX;
<span style="color: #993333;">int</span> maxx <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">int</span> miny <span style="color: #339933;">=</span> INT_MAX;
<span style="color: #993333;">int</span> maxy <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">int</span> minz <span style="color: #339933;">=</span> INT_MAX;
<span style="color: #993333;">int</span> maxz <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
&nbsp;
<span style="color: #993333;">int</span> g0x <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">int</span> g0y <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">int</span> g0z <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
&nbsp;
<span style="color: #993333;">long</span> time1 <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">long</span> time2 <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
&nbsp;
<span style="color: #993333;">float</span> rho <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">float</span> phi <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
<span style="color: #993333;">float</span> theta <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
&nbsp;
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span>;
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;RST<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>xaxis<span style="color: #339933;">,</span>INPUT<span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>yaxis<span style="color: #339933;">,</span>INPUT<span style="color: #009900;">&#41;</span>;
  pinMode<span style="color: #009900;">&#40;</span>zaxis<span style="color: #339933;">,</span>INPUT<span style="color: #009900;">&#41;</span>;
  time1<span style="color: #339933;">=</span>millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  time2<span style="color: #339933;">=</span>millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
  valx <span style="color: #339933;">=</span> analogRead<span style="color: #009900;">&#40;</span>xaxis<span style="color: #009900;">&#41;</span>;    <span style="color: #666666; font-style: italic;">// read the value from the sensor</span>
  valy <span style="color: #339933;">=</span> analogRead<span style="color: #009900;">&#40;</span>yaxis<span style="color: #009900;">&#41;</span>;    <span style="color: #666666; font-style: italic;">// read the value from the sensor</span>
  valz <span style="color: #339933;">=</span> analogRead<span style="color: #009900;">&#40;</span>zaxis<span style="color: #009900;">&#41;</span>;    <span style="color: #666666; font-style: italic;">// read the value from the sensor</span>
&nbsp;
  <span style="color: #993333;">int</span> pfx <span style="color: #339933;">=</span> valx;
  <span style="color: #993333;">int</span> pfy <span style="color: #339933;">=</span> valy;
  <span style="color: #993333;">int</span> pfz <span style="color: #339933;">=</span> valz;
&nbsp;
  autoZeroCalibration<span style="color: #009900;">&#40;</span>pfx<span style="color: #339933;">,</span>pfy<span style="color: #339933;">,</span>pfz<span style="color: #009900;">&#41;</span>;
&nbsp;
  <span style="color: #993333;">int</span> fx <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>pfx <span style="color: #339933;">-</span> g0x<span style="color: #009900;">&#41;</span>;
  <span style="color: #993333;">int</span> fy <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>pfy <span style="color: #339933;">-</span> g0y<span style="color: #009900;">&#41;</span>;
  <span style="color: #993333;">int</span> fz <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>pfz <span style="color: #339933;">-</span> g0z<span style="color: #009900;">&#41;</span>;
&nbsp;
  <span style="color: #993333;">float</span> ax <span style="color: #339933;">=</span> fx<span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">3.3</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">1024.0</span><span style="color: #339933;">*</span><span style="color:#800080;">0.800</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #993333;">float</span> ay <span style="color: #339933;">=</span> fy<span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">3.3</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">1024.0</span><span style="color: #339933;">*</span><span style="color:#800080;">0.800</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #993333;">float</span> az <span style="color: #339933;">=</span> fz<span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">3.3</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">1024.0</span><span style="color: #339933;">*</span><span style="color:#800080;">0.800</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
  <span style="color: #666666; font-style: italic;">//</span>
  rho <span style="color: #339933;">=</span>   atan<span style="color: #009900;">&#40;</span>ax<span style="color: #339933;">/</span>sqrt<span style="color: #009900;">&#40;</span>pow<span style="color: #009900;">&#40;</span>ay<span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>pow<span style="color: #009900;">&#40;</span>az<span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">360</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span><span style="color:#800080;">3.1592</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;  
  phi <span style="color: #339933;">=</span>   atan<span style="color: #009900;">&#40;</span>ay<span style="color: #339933;">/</span>sqrt<span style="color: #009900;">&#40;</span>pow<span style="color: #009900;">&#40;</span>ax<span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>pow<span style="color: #009900;">&#40;</span>az<span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">360</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span><span style="color:#800080;">3.1592</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;  
  theta <span style="color: #339933;">=</span> atan<span style="color: #009900;">&#40;</span>sqrt<span style="color: #009900;">&#40;</span>pow<span style="color: #009900;">&#40;</span>ay<span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>pow<span style="color: #009900;">&#40;</span>ax<span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>az<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">360</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span><span style="color:#800080;">3.1592</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;  
&nbsp;
  printAngles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> autoZeroCalibration<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> pfx<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> pfy<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> pfz<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>pfx <span style="color: #339933;">&lt;</span> minx<span style="color: #009900;">&#41;</span>||<span style="color: #009900;">&#40;</span>pfy <span style="color: #339933;">&lt;</span> miny<span style="color: #009900;">&#41;</span>||<span style="color: #009900;">&#40;</span>pfz <span style="color: #339933;">&lt;</span> minz<span style="color: #009900;">&#41;</span>||<span style="color: #009900;">&#40;</span>pfx <span style="color: #339933;">&gt;</span> maxx<span style="color: #009900;">&#41;</span>||<span style="color: #009900;">&#40;</span>pfy <span style="color: #339933;">&gt;</span> maxy<span style="color: #009900;">&#41;</span>||<span style="color: #009900;">&#40;</span>pfz <span style="color: #339933;">&gt;</span> maxz<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// autozero calibration</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pfx <span style="color: #339933;">&lt;</span> minx<span style="color: #009900;">&#41;</span> minx <span style="color: #339933;">=</span> pfx;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pfy <span style="color: #339933;">&lt;</span> miny<span style="color: #009900;">&#41;</span> miny <span style="color: #339933;">=</span> pfy;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pfz <span style="color: #339933;">&lt;</span> minz<span style="color: #009900;">&#41;</span> minz <span style="color: #339933;">=</span> pfz;
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pfx <span style="color: #339933;">&gt;</span> maxx<span style="color: #009900;">&#41;</span> maxx <span style="color: #339933;">=</span> pfx;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pfy <span style="color: #339933;">&gt;</span> maxy<span style="color: #009900;">&#41;</span> maxy <span style="color: #339933;">=</span> pfy;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pfz <span style="color: #339933;">&gt;</span> maxz<span style="color: #009900;">&#41;</span> maxz <span style="color: #339933;">=</span> pfz;
&nbsp;
     g0x <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>maxx <span style="color: #339933;">-</span> minx<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>minx;
     g0y <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>maxy <span style="color: #339933;">-</span> miny<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>miny;
     g0z <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>maxz <span style="color: #339933;">-</span> minz<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>minz;
&nbsp;
     printValues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> printFloat<span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span> value<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> places<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">// this is used to cast digits</span>
   <span style="color: #993333;">int</span> digit;
   <span style="color: #993333;">float</span> tens <span style="color: #339933;">=</span> <span style="color:#800080;">0.1</span>;
   <span style="color: #993333;">int</span> tenscount <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
   <span style="color: #993333;">int</span> i;
   <span style="color: #993333;">float</span> tempfloat <span style="color: #339933;">=</span> value;
&nbsp;
   <span style="color: #666666; font-style: italic;">// if value is negative, set tempfloat to the abs value</span>
   <span style="color: #666666; font-style: italic;">// make sure we round properly. this could use pow from  </span>
   <span style="color: #666666; font-style: italic;">//&lt;math.h&gt;, but doesn't seem worth the import</span>
   <span style="color: #666666; font-style: italic;">// if this rounding step isn't here, the value  54.321 prints as  </span>
   <span style="color: #666666; font-style: italic;">//54.3209</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// calculate rounding term d:   0.5/pow(10,places)</span>
   <span style="color: #993333;">float</span> d <span style="color: #339933;">=</span> <span style="color:#800080;">0.5</span>;
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">&lt;</span> <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>
     d <span style="color: #339933;">*=</span> <span style="color: #339933;">-</span><span style="color:#800080;">1.0</span>;
   <span style="color: #666666; font-style: italic;">// divide by ten for each decimal place</span>
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>; i <span style="color: #339933;">&lt;</span> places; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
     d<span style="color: #339933;">/=</span> <span style="color:#800080;">10.0</span>;
   <span style="color: #666666; font-style: italic;">// this small addition, combined with truncation will round our  </span>
   <span style="color: #666666; font-style: italic;">// values properly</span>
   tempfloat <span style="color: #339933;">+=</span>  d;
&nbsp;
   <span style="color: #666666; font-style: italic;">// first get value tens to be the large power of ten less than value</span>
   <span style="color: #666666; font-style: italic;">// tenscount isn't necessary but it would be useful if you wanted  </span>
   <span style="color: #666666; font-style: italic;">// to know after this how many chars the number will take</span>
&nbsp;
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">&lt;</span> <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>
     tempfloat <span style="color: #339933;">*=</span> <span style="color: #339933;">-</span><span style="color:#800080;">1.0</span>;
   <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>tens <span style="color: #339933;">*</span> <span style="color:#800080;">10.0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> tempfloat<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     tens <span style="color: #339933;">*=</span> <span style="color:#800080;">10.0</span>;
     tenscount <span style="color: #339933;">+=</span> <span style="color: #0000dd;">1</span>;
   <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
   <span style="color: #666666; font-style: italic;">// write out the negative if needed</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">&lt;</span> <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>
     Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'-'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>tenscount <span style="color: #339933;">==</span> <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>
     Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span> DEC<span style="color: #009900;">&#41;</span>;
&nbsp;
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color:#800080;">0</span>; i<span style="color: #339933;">&lt;</span> tenscount; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     digit <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>tempfloat<span style="color: #339933;">/</span>tens<span style="color: #009900;">&#41;</span>;
     Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>digit<span style="color: #339933;">,</span> DEC<span style="color: #009900;">&#41;</span>;
     tempfloat <span style="color: #339933;">=</span> tempfloat <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span>digit <span style="color: #339933;">*</span> tens<span style="color: #009900;">&#41;</span>;
     tens <span style="color: #339933;">/=</span> <span style="color:#800080;">10.0</span>;
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// if no places after decimal, stop now and return</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>places <span style="color: #339933;">&lt;=</span> <span style="color:#800080;">0</span><span style="color: #009900;">&#41;</span>
     <span style="color: #b1b100;">return</span>;
&nbsp;
   <span style="color: #666666; font-style: italic;">// otherwise, write the point and continue on</span>
   Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'.'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
   <span style="color: #666666; font-style: italic;">// now write out each decimal place by shifting digits one by one  </span>
   <span style="color: #666666; font-style: italic;">// into the ones place and writing the truncated value</span>
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>; i <span style="color: #339933;">&lt;</span> places; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     tempfloat <span style="color: #339933;">*=</span> <span style="color:#800080;">10.0</span>;
     digit <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> tempfloat;
     Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>digit<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
     <span style="color: #666666; font-style: italic;">// once written, subtract off that digit</span>
     tempfloat <span style="color: #339933;">=</span> tempfloat <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span> digit;
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> printAngles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>time1 <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    time1 <span style="color: #339933;">=</span> millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;rho: &quot;</span><span style="color: #009900;">&#41;</span>;
    printFloat<span style="color: #009900;">&#40;</span>rho<span style="color: #339933;">,</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; phi: &quot;</span><span style="color: #009900;">&#41;</span>;
    printFloat<span style="color: #009900;">&#40;</span>phi<span style="color: #339933;">,</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; theta: &quot;</span><span style="color: #009900;">&#41;</span>;
    printFloat<span style="color: #009900;">&#40;</span>theta<span style="color: #339933;">,</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> printValues<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> time2<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">800</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    time2<span style="color: #339933;">=</span>millis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;minx: &quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>minx<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>minx<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>minx<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; miny: &quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>miny<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>miny<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>miny<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; minz: &quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>minz<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>minz<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>minz<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;maxx: &quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>maxx<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>maxx<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>maxx<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; maxy: &quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>maxy<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>maxy<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>maxy<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; maxz: &quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>maxz<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>maxz<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>maxz<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span>;
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/11/03/arduino-tilt-sensor-using-mma7260q/feed/</wfw:commentRss>
		</item>
		<item>
		<title>dropbox not syncing files</title>
		<link>http://rubenlaguna.com/wp/2008/10/20/dropbox-not-syncing-files/</link>
		<comments>http://rubenlaguna.com/wp/2008/10/20/dropbox-not-syncing-files/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 22:18:42 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[dropbox]]></category>

		<category><![CDATA[failure]]></category>

		<category><![CDATA[syncing]]></category>

		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/?p=289</guid>
		<description><![CDATA[Today I fixed my dropbox installation on mac os x . It was not updating (sending) files from the Mac to the Dropbox servers. In fact it was sending new files to dropbox servers but some old files that were supposed to be on dropbox account were not synchonized and I couldn&#8217;t get Dropbox to [...]]]></description>
			<content:encoded><![CDATA[<p>Today I fixed my <a href="http://getdropbox.com">dropbox</a> installation on mac os x . It was not updating (sending) files from the Mac to the Dropbox servers. In fact it was sending new files to dropbox servers but some old files that were supposed to be on dropbox account were not synchonized and I couldn&#8217;t get Dropbox to notice that, until today. I found <a href="http://forums.getdropbox.com/topic.php?id=1200&#038;replies=109#post-6438">this post</a> and it seems that if you close dropbox, delete the ~/.dropbox directory and restart dropbox you&#8217;ll get the account linking screen again and dropbox will index everything and make sure that your local Dropbox directory match the online one. It took a while but all the files are safely transferred to Dropbox now.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/10/20/dropbox-not-syncing-files/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Arduino sleep mode - Waking up when receiving data on the USART</title>
		<link>http://rubenlaguna.com/wp/2008/10/15/arduino-sleep-mode-waking-up-when-receiving-data-on-the-usart/</link>
		<comments>http://rubenlaguna.com/wp/2008/10/15/arduino-sleep-mode-waking-up-when-receiving-data-on-the-usart/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 21:14:30 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[electronics]]></category>

		<category><![CDATA[arduino]]></category>

		<category><![CDATA[atmega168]]></category>

		<category><![CDATA[serial]]></category>

		<category><![CDATA[sleep]]></category>

		<category><![CDATA[usart]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/?p=286</guid>
		<description><![CDATA[I&#8217;ve been playing with the Arduino sleep modes and i wanted to be able to wake up from the sleep when receiving data on the serial port. Mainly, because in my project I&#8217;m using the XBee in the API mode and the tricks exposed in http://www.arduino.cc/playground/Learning/ArduinoSleepCode and http://www.libelium.com/squidbee/index.php?title=Save_power_in_SquidBee_-_sleep_mode involve putting Arduino in SLEEP_MODE_PWR_DOWN and using [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing with the Arduino sleep modes and i wanted to be able to wake up from the sleep when receiving data on the serial port. Mainly, because in my project I&#8217;m using the XBee in the API mode and the tricks exposed in <a href="http://www.arduino.cc/playground/Learning/ArduinoSleepCode">http://www.arduino.cc/playground/Learning/ArduinoSleepCode</a> and <a href="http://www.libelium.com/squidbee/index.php?title=Save_power_in_SquidBee_-_sleep_mode">http://www.libelium.com/squidbee/index.php?title=Save_power_in_SquidBee_-_sleep_mode</a> involve putting Arduino in SLEEP_MODE_PWR_DOWN and using an extra pin on the arduino to monitor the RX pin and detecting LOW.</p>

<p>I didn&#8217;t like that much that solution so I started to look into other ways of doing it without using an extra pin and without risk of losing data in the serial interface. Because as I understood it using SLEEP_MODE_PWR_DOWN requires to send first a burst of data to the serial interface in order to wake up the arduino.  And it takes a while for the Arduino to become fully functional so that means that you will lose/miss data in the serial interface. That was something that didn&#8217;t fit my project.</p>

<p>In order to be able to sleep but without missing serial data  I used POWER_MODE_IDLE,  a power saving mode that leaves the USART on and then using the functions defined in power.h (you have to use arduino-12 to get power.h)  I disabled all other modules that I don&#8217;t need to cut down the power consumption. When any data is received in the USART the Arduino will be brought back to normal power mode (USART uses interrupts and any interrupt makes the ATmega168 to exit the power saving mode).</p>

<p>See the actual code in this</p>


<div class="wp_syntax"><div class="code"><pre class="c c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Sleep Demo Serial
 * -----------------
 * Example code to demonstrate the sleep functions in a Arduino. Arduino will wake up
 * when new data is received in the serial port USART
 * Based on Sleep Demo Serial from http://www.arduino.cc/playground/Learning/ArduinoSleepCode 
 *
 * Copyright (C) 2006 MacSimski 2006-12-30 
 * Copyright (C) 2007 D. Cuartielles 2007-07-08 - Mexico DF
 * 
 *  With modifications from Ruben Laguna  2008-10-15
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 * 
 */</span>
&nbsp;
<span style="color: #339933;">#include &lt;avr/power.h&gt;</span>
<span style="color: #339933;">#include &lt;avr/sleep.h&gt;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #993333;">int</span> sleepStatus <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;             <span style="color: #666666; font-style: italic;">// variable to store a request for sleep</span>
<span style="color: #993333;">int</span> count <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;                   <span style="color: #666666; font-style: italic;">// counter</span>
&nbsp;
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> sleepNow<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* Now is the time to set the sleep mode. In the Atmega8 datasheet
     * http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
     * there is a list of sleep modes which explains which clocks and 
     * wake up sources are available in which sleep modus.
     *
     * In the avr/sleep.h file, the call names of these sleep modus are to be found:
     *
     * The 5 different modes are:
     *     SLEEP_MODE_IDLE         -the least power savings 
     *     SLEEP_MODE_ADC
     *     SLEEP_MODE_PWR_SAVE
     *     SLEEP_MODE_STANDBY
     *     SLEEP_MODE_PWR_DOWN     -the most power savings
     *
     *  the power reduction management &lt;avr/power.h&gt;  is described in 
     *  http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
     */</span>  
&nbsp;
  set_sleep_mode<span style="color: #009900;">&#40;</span>SLEEP_MODE_IDLE<span style="color: #009900;">&#41;</span>;   <span style="color: #666666; font-style: italic;">// sleep mode is set here</span>
&nbsp;
  sleep_enable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;          <span style="color: #666666; font-style: italic;">// enables the sleep bit in the mcucr register</span>
                             <span style="color: #666666; font-style: italic;">// so sleep is possible. just a safety pin </span>
&nbsp;
  power_adc_disable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  power_spi_disable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  power_timer0_disable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  power_timer1_disable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  power_timer2_disable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  power_twi_disable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
&nbsp;
  sleep_mode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;            <span style="color: #666666; font-style: italic;">// here the device is actually put to sleep!!</span>
&nbsp;
                             <span style="color: #666666; font-style: italic;">// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP</span>
  sleep_disable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;         <span style="color: #666666; font-style: italic;">// first thing after waking from sleep:</span>
                            <span style="color: #666666; font-style: italic;">// disable sleep...</span>
&nbsp;
  power_all_enable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// display information about the counter</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Awake for &quot;</span><span style="color: #009900;">&#41;</span>;
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span>;
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sec&quot;</span><span style="color: #009900;">&#41;</span>;
  count++;
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span>;                           <span style="color: #666666; font-style: italic;">// waits for a second</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// compute the serial input</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> val <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>val <span style="color: #339933;">==</span> <span style="color: #ff0000;">'S'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Serial: Entering Sleep mode&quot;</span><span style="color: #009900;">&#41;</span>;
      delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span>;     <span style="color: #666666; font-style: italic;">// this delay is needed, the sleep </span>
                      <span style="color: #666666; font-style: italic;">//function will provoke a Serial error otherwise!!</span>
      count <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
      sleepNow<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;     <span style="color: #666666; font-style: italic;">// sleep function called here</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>val <span style="color: #339933;">==</span> <span style="color: #ff0000;">'A'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hola Caracola&quot;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// classic dummy message</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// check if it should go asleep because of time</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>count <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Timer: Entering Sleep mode&quot;</span><span style="color: #009900;">&#41;</span>;
      delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span>;     <span style="color: #666666; font-style: italic;">// this delay is needed, the sleep </span>
                      <span style="color: #666666; font-style: italic;">//function will provoke a Serial error otherwise!!</span>
      count <span style="color: #339933;">=</span> <span style="color:#800080;">0</span>;
      sleepNow<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;     <span style="color: #666666; font-style: italic;">// sleep function called here</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/10/15/arduino-sleep-mode-waking-up-when-receiving-data-on-the-usart/feed/</wfw:commentRss>
		</item>
		<item>
		<title>iTunes 8: Ready for download - The Unofficial Apple Weblog (TUAW)</title>
		<link>http://rubenlaguna.com/wp/2008/09/09/itunes-8-ready-for-download-the-unofficial-apple-weblog-tuaw/</link>
		<comments>http://rubenlaguna.com/wp/2008/09/09/itunes-8-ready-for-download-the-unofficial-apple-weblog-tuaw/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 20:34:56 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[itunes]]></category>

		<category><![CDATA[download]]></category>

		<category><![CDATA[genius]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/?p=278</guid>
		<description><![CDATA[I just downloaded and installed iTunes 8 from apple website, turning on Genius. we will see what kind of recommendations does it give me.

via iTunes 8: Ready for download - The Unofficial Apple Weblog (TUAW).
]]></description>
			<content:encoded><![CDATA[<p>I just downloaded and installed iTunes 8 from <a href="http://www.apple.com/itunes/download/">apple website</a>, turning on Genius. we will see what kind of recommendations does it give me.</p>

<p>via <a href="http://www.tuaw.com/2008/09/09/itunes-8-ready-for-download/">iTunes 8: Ready for download - The Unofficial Apple Weblog (TUAW)</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/09/09/itunes-8-ready-for-download-the-unofficial-apple-weblog-tuaw/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Upgrading Xbee Series 2 (XbeeShield) to Xbee ZB with Arduino</title>
		<link>http://rubenlaguna.com/wp/2008/09/06/upgrading-xbee-series-2-xbeeshield-to-xbee-zb-with-arduino/</link>
		<comments>http://rubenlaguna.com/wp/2008/09/06/upgrading-xbee-series-2-xbeeshield-to-xbee-zb-with-arduino/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 09:59:41 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[electronics]]></category>

		<category><![CDATA[arduino]]></category>

		<category><![CDATA[firmware]]></category>

		<category><![CDATA[shield]]></category>

		<category><![CDATA[upgrade]]></category>

		<category><![CDATA[xbee]]></category>

		<category><![CDATA[zb]]></category>

		<category><![CDATA[zigbee]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/?p=273</guid>
		<description><![CDATA[As stated in this digi page is possible to upgrade/convert a Xbee Series 2.5 to a Xbee ZB (with full standard Zigbee capabilities). Xbee Series 2.5 is just another name for the forme Series 2, so the upgrade procedure is exactly the same.

The procedure if fairly straighforward


    Remove ATmega168 from Arduino board [...]]]></description>
			<content:encoded><![CDATA[<p>As stated in this <a href="http://www.digi.com/support/kbase/kbaseresultdetl.jsp?id=3025">digi page</a> is possible to upgrade/convert a Xbee Series 2.5 to a Xbee ZB (with full standard Zigbee capabilities). Xbee Series 2.5 is just another name for the forme Series 2, so the upgrade procedure is exactly the same.</p>

<p>The procedure if fairly straighforward</p>

<ol>
    <li>Remove ATmega168 from Arduino board </li>
    <li>Insert <a href="http://www.arduino.cc/playground/Shields/Xbee01">XbeeShield </a>into <a href="http://www.arduino.cc">Arduino </a></li>
    <li>Change <strong>both </strong>jumpers in XbeeShield to USB</li>
    <li>Connect Arduino to the computer using the USB cabke</li>
        <li>Download the <a href="ftp://ftp1.digi.com/support/images/ZNet%202.5%20to%20ZB%20Conversion%20Kit.zip">ZNet 2.5 to ZB Conversion Kit here</a></li>
    <li>Start the <a href="http://www.digi.com/support/productdetl.jsp?pid=3352&#038;osvid=57&#038;tp=4&#038;s=316">X-CTU 5.1.4.1 software</a></li>
        <a href="http://www.flickr.com/photos/rlaguna/2831767248/" title="xbee01 by Ruben Laguna, on Flickr"><img src="http://farm4.static.flickr.com/3066/2831767248_fb096dbb00_o.png" width="455" height="594" alt="xbee01" /></a>
    <li>Select the proper COM port (should be Usb serial port (COMX))</li>
    <li>Click on Test Query. The following dialog should appear indicating that X-CTU found the Xbee in that COM port and giving you some information about the Xbee module version, etc. In my case it was a ZB24-B with 1220 firmware</li>
<a href="http://www.flickr.com/photos/rlaguna/2830933503/" title="xbee02 by Ruben Laguna, on Flickr"><img src="http://farm4.static.flickr.com/3239/2830933503_aa0f415f73_o.png" width="350" height="184" alt="xbee02" /></a>

    <li>Go to the Modem Configuration tab</li>
        <li>Download the <a href="ftp://ftp1.digi.com/support/images/ZNet%202.5%20to%20ZB%20Conversion%20Kit.zip">ZNet 2.5 to ZB Conversion Kit here</a> if you didn&#8217;t do it earlier</li>
    <li>Uncompress the ZIP</li>
<a href="http://www.flickr.com/photos/rlaguna/2832902956/" title="xbee11 by Ruben Laguna, on Flickr"><img src="http://farm4.static.flickr.com/3184/2832902956_451fa0cd63_o.png" width="463" height="84" alt="xbee11" /></a>
    <li>Select the “Download new versions” button. </li>
<a href="http://www.flickr.com/photos/rlaguna/2832906794/" title="xbee12 by Ruben Laguna, on Flickr"><img src="http://farm4.static.flickr.com/3084/2832906794_b1d079b243_o.png" width="231" height="177" alt="xbee12" /></a>
    <li>Press the “File” source button</li>
    <li>Select the xbee_zb.zip file to add the firmware set to X-CTU</li>

    <li>Back to the Modem Configuration tab. Select &#8220;Always update firmware&#8221; checkbox and select XB24-ZB (or XB24P-ZB if you have a PRO module) and the function set that you want for the module (router, coordinator, end device, each one in two differente flavor AT or API). In my case I selected XB24-ZB and COORDINATOR API. Check the <a href="http://ftp1.digi.com/support/documentation/90000976_a.pdf">product manual</a> to find out about API and AT modes and the different firmwares for each set </li>


<a href="http://www.flickr.com/photos/rlaguna/2830933543/" title="xbee03 by Ruben Laguna, on Flickr"><img src="http://farm4.static.flickr.com/3242/2830933543_dbe8eae11f_o.png" width="455" height="594" alt="xbee03" /></a>

    <li>Press &#8220;Write&#8221; and X-CTU will start uploading the firmware to the module</li>
<a href="http://www.flickr.com/photos/rlaguna/2830933601/" title="xbee04 by Ruben Laguna, on Flickr"><img src="http://farm3.static.flickr.com/2199/2830933601_ba8f49d1ba_o.png" width="455" height="594" alt="xbee04" /></a>
<a href="http://www.flickr.com/photos/rlaguna/2830933629/" title="xbee05 by Ruben Laguna, on Flickr"><img src="http://farm4.static.flickr.com/3032/2830933629_a43d71dc34_o.png" width="455" height="594" alt="xbee05" /></a>

    <li>The firmware upgrade is complete</li>

<ins datetime="2008-09-18T20:36:08+00:00"><strong>NOTE</strong>: Make sure that the configuration for DIO7 is DISABLED as this XBee pin is connected to the RST in the Arduino. If you leave the default option (1 - CTS) random resets after a couple of seconds may occur</ins>



</ol>
]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/09/06/upgrading-xbee-series-2-xbeeshield-to-xbee-zb-with-arduino/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Chrome : The application failed to initialize properly (0xc0000005) « me &amp; PHP</title>
		<link>http://rubenlaguna.com/wp/2008/09/04/google-chrome-the-application-failed-to-initialize-properly-0xc0000005-%c2%ab-me-php/</link>
		<comments>http://rubenlaguna.com/wp/2008/09/04/google-chrome-the-application-failed-to-initialize-properly-0xc0000005-%c2%ab-me-php/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 10:25:50 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[windows]]></category>

		<category><![CDATA[chrome]]></category>

		<category><![CDATA[failed]]></category>

		<category><![CDATA[google]]></category>

		<category><![CDATA[sandbox]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/2008/09/04/google-chrome-the-application-failed-to-initialize-properly-0xc0000005-%c2%ab-me-php/</guid>
		<description><![CDATA[If you are getting (like me) the &#8220;The application failed to initialize properly (0xc0000005)&#8221; error when trying to start Google chrome try to use -no-sandbox option as pointed out in Google Chrome : The application failed to initialize properly (0xc0000005) « me &#38; PHP.
]]></description>
			<content:encoded><![CDATA[<p>If you are getting (like me) the &#8220;The application failed to initialize properly (0xc0000005)&#8221; error when trying to start Google chrome try to use -no-sandbox option as pointed out in <a href="http://palaniraja.wordpress.com/2008/09/03/google-chrome-the-application-failed-to-initialize-properly-0xc0000005/">Google Chrome : The application failed to initialize properly (0xc0000005) « me &amp; PHP</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/09/04/google-chrome-the-application-failed-to-initialize-properly-0xc0000005-%c2%ab-me-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Microsoft Visio has stopped working after exiting Visio</title>
		<link>http://rubenlaguna.com/wp/2008/09/04/microsoft-visio-has-stopped-working-after-exiting-visio/</link>
		<comments>http://rubenlaguna.com/wp/2008/09/04/microsoft-visio-has-stopped-working-after-exiting-visio/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 06:19:40 +0000</pubDate>
		<dc:creator>ruben.laguna</dc:creator>
		
		<category><![CDATA[windows]]></category>

		<category><![CDATA[bluetooth]]></category>

		<category><![CDATA[closing]]></category>

		<category><![CDATA[driver]]></category>

		<category><![CDATA[incompatibility]]></category>

		<category><![CDATA[microsoft]]></category>

		<category><![CDATA[stopped]]></category>

		<category><![CDATA[visio]]></category>

		<category><![CDATA[word]]></category>

		<category><![CDATA[working]]></category>

		<guid isPermaLink="false">http://rubenlaguna.com/wp/?p=267</guid>
		<description><![CDATA[It seems that Visio has some kind of incompability with Bluetooth drivers. 
http://www.tech-archive.net/Archive/Visio/microsoft.public.visio.general/2008-06/msg00239.html.

I notice this problem when editing Visio objects embedded into Microsoft Word documents. In my case after I enabled  Bluetooth  (via my Compaq nw8440 special keyboard button)  this problem went away.
]]></description>
			<content:encoded><![CDATA[<p>It seems that Visio has some kind of incompability with Bluetooth drivers. 
http://www.tech-archive.net/Archive/Visio/microsoft.public.visio.general/2008-06/msg00239.html.</p>

<p>I notice this problem when editing Visio objects embedded into Microsoft Word documents. In my case after I <strong>enabled </strong> Bluetooth  (via my Compaq nw8440 special keyboard button)  this problem went away.</p>
]]></content:encoded>
			<wfw:commentRss>http://rubenlaguna.com/wp/2008/09/04/microsoft-visio-has-stopped-working-after-exiting-visio/feed/</wfw:commentRss>
		</item>
	<feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetFeedData?uri=RubensBlog</feedburner:awareness></channel>
</rss>
