<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><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:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Interactive Matter</title>
	
	<link>http://interactive-matter.org</link>
	<description>Tinkering with electronics &amp; ambient interaction</description>
	<lastBuildDate>Tue, 09 Mar 2010 11:19:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
			<title>Interactive Matter</title>
			<url>http://interactive-matter.org/wp-content/uploads/2009/12/interactive-matter-logo-feed.png</url>
			<link>http://interactive-matter.org</link>
			<width />
			<height />
			<description>Tinkering with electronics &amp; ambient interaction</description>
		</image>		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/interactive-matter" /><feedburner:info uri="interactive-matter" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license><item>
		<title>BMP085 Barometric Pressure Sensor Breakout Boards arrived!</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/zg79nTboNB0/</link>
		<comments>http://interactive-matter.org/2010/02/bmp085-barometric-pressure-sensor-breakout-boards-arrived/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 06:56:46 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Shop]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Barometer]]></category>
		<category><![CDATA[barometric pressure sensor]]></category>
		<category><![CDATA[BMP085]]></category>
		<category><![CDATA[Break Out Board]]></category>
		<category><![CDATA[Pressure Sensor]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=690</guid>
		<description><![CDATA[You may know that I played around a bit with the BMP085 barometric pressure sensor. Now I am proud to announce that the BMP085 barometric pressure sensor is available as breakout board in the Interactive Matter Shop.

The BMP085 Breakout Board is a limited offer. I just got some at hand and supplies last as long [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>You may know that I played around a bit with the <a href="http://interactive-matter.org/2009/12/arduino-barometric-pressure-sensor-bmp085/">BMP085 barometric pressure sensor</a>. Now I am proud to announce that the BMP085 barometric pressure sensor is available as <a href="http://interactive-matter.org/shop/breakout-boards/bmp085-barometric-pressure-sensor-breakout-board/">breakout board in the Interactive Matter Shop</a>.</p>
<p><a title="Arduino &amp; Barometric Pressure Sensor BMP085" href="http://farm3.static.flickr.com/2485/4159864537_6e11c303e3_b.jpg"><img class="slickr-post colorbox-690" src="http://farm3.static.flickr.com/2485/4159864537_6e11c303e3.jpg" alt="Arduino &amp; Barometric Pressure Sensor BMP085" width="500" height="375" /></a></p>
<p>The <a href="http://interactive-matter.org/shop/breakout-boards/bmp085-barometric-pressure-sensor-breakout-board/">BMP085 Breakout Board</a> is a limited offer. I just got some at hand and supplies last as long as supplies last and are gone after they are gone. They come completely pre-assembled and tested.</p>


<p>Related posts:<ul><li><a href='http://interactive-matter.org/2009/12/arduino-barometric-pressure-sensor-bmp085/' rel='bookmark' title='Permanent Link: Arduino &#038; Barometric Pressure Sensor BMP085'>Arduino &#038; Barometric Pressure Sensor BMP085</a></li>
<li><a href='http://interactive-matter.org/2009/07/interactive-matter-goes-kit/' rel='bookmark' title='Permanent Link: Interactive Matter goes Kit'>Interactive Matter goes Kit</a></li>
</ul></p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/zg79nTboNB0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2010/02/bmp085-barometric-pressure-sensor-breakout-boards-arrived/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2010/02/bmp085-barometric-pressure-sensor-breakout-boards-arrived/</feedburner:origLink></item>
		<item>
		<title>Blinken Button – The LED Matrix Button Kit</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/aE8JyVdOrNQ/</link>
		<comments>http://interactive-matter.org/2010/02/blinken-button-%e2%80%93-the-led-matrix-button-kit/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 11:45:06 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Shop]]></category>
		<category><![CDATA[64 Pixels]]></category>
		<category><![CDATA[8x8]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Atmega]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[fashion accessory]]></category>
		<category><![CDATA[Kits]]></category>
		<category><![CDATA[LED Matrix]]></category>
		<category><![CDATA[Space Invaders]]></category>
		<category><![CDATA[Wearable]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=542</guid>
		<description><![CDATA[Interactive Matter proudly present the first Interactive Matter SMT Kit
The Blinken Button! Head over to the shop to grab yours!

The Blinken Button is a kit for a 8&#215;8 LED Matrix button (the jacket one). It is based on the Space Invaders Button you may already know. Get all the information on the product page.

History
The Blinken [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><strong>Interactive Matter proudly present the first Interactive Matter SMT Kit</strong><br />
The Blinken Button! Head over to the <a href="http://interactive-matter.org/shop/kits/blinken-button/">shop</a> to grab yours!<br />
<a href="http://farm5.static.flickr.com/4003/4322779350_64dfe981d5_b.jpg" title=""><img src="http://farm5.static.flickr.com/4003/4322779350_64dfe981d5.jpg" alt="" width="500" height="375" class="slickr-post colorbox-542" /></a><br />
The Blinken Button is a kit for a 8&#215;8 LED Matrix button (the jacket one). It is based on the <a href="http://interactive-matter.org/2009/04/space-invaders-button/">Space Invaders Button</a> you may already know. Get all the information on the <a href="http://interactive-matter.org/shop/kits/blinken-button/">product page</a>.<br />
<span id="more-542"></span></p>
<h3>History</h3>
<p>The Blinken Button is a direct descendant of the <a href="http://interactive-matter.org/2009/04/space-invaders-button/">Space Invaders Button</a>. It is optimized to be an entry level SMT kit. It did not really work out to be total  entry level, since all the electronics is behind the display, which makes it a great gift or fashion accessory, but if you made a mistake in soldering – there is no way to fix it (easily). So very intensive testing is needed. But if this is not your first kit and you already did some mistakes, you can handle it.<br />
It is basically Arduino compatible. But it comes without the Arduino code out of the box. This is something that will be enabled quite soon.</p>
<h3>The need for a name</h3>
<p>Coming up with a name was the most complicated thing. I positively did not wanted to use the name Space Invaders Button. I do not want to fight with Atari or whoever got the name now.<br />
Using then name <em>64 Pixels Button</em> was something I tried and it really made it onto the PCB – but <a href="http://tinkerlog.com/">Alex</a> had concerns that it interferes with his <a href="http://tinkerlog.com/howto/64pixels/">64 Pixels</a> project. And he was right.<br />
So the name was <em>Blinken Button.</em> It is so for three reasons: First my girlfriend calls it like that anyway, second it is basically just some <a href="http://en.wikipedia.org/wiki/Blinkenlights">Blinkenlights</a> and third it is a homage to the <a href="http://www.blinkenlights.net/blinkenlights">CCC Blinkenlights</a>, I really enjoyed some years ago.</p>
<h3>The Future</h3>
<p>It will not stop here. </p>
<ul>
<li>First the Arduino compatibility will be explored. This will most probably work out with the current version with an software update.</li>
<li>There is an USB version planned, with much more control for users who do not have an AVR programmer.</li>
</ul>
<p>Thats all for now. So go over to the <a href="http://interactive-matter.org/shop/kits/blinken-button/">shop</a> , join Interactive Matter in the grand shop opening and grab yours.</p>


<p>Related posts:<ul><li><a href='http://interactive-matter.org/2009/04/space-invaders-button/' rel='bookmark' title='Permanent Link: Space Invaders Button'>Space Invaders Button</a></li>
<li><a href='http://interactive-matter.org/2009/05/64-pixels-roundup/' rel='bookmark' title='Permanent Link: 64 Pixels Roundup'>64 Pixels Roundup</a></li>
</ul></p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/aE8JyVdOrNQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2010/02/blinken-button-%e2%80%93-the-led-matrix-button-kit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2010/02/blinken-button-%e2%80%93-the-led-matrix-button-kit/</feedburner:origLink></item>
		<item>
		<title>Palo Altona – Hamburg Tinker Drinkup</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/ewB31wB6ZbY/</link>
		<comments>http://interactive-matter.org/2010/01/palo-altona-%e2%80%93-hamburg-tinker-drinkup/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 09:11:27 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Tinkering]]></category>
		<category><![CDATA[#palo_altona]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[drinkup]]></category>
		<category><![CDATA[Hamburg]]></category>
		<category><![CDATA[tinker]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=471</guid>
		<description><![CDATA[Die deutsche Version gibt es nach dem Klick (und dann weiter unten).
This time it is all non-technical (technically not – but that starts to get complicated). To further encourage tinkering in Hamburg, Alex and I have established a regularly tinker drinkup every Thursday (nearly) at Saal II.

Currently it is a very cosy drinkup, just a [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Die deutsche Version gibt es nach dem Klick (und dann weiter unten).</p>
<p>This time it is all non-technical (technically not – but that starts to get complicated). To further encourage tinkering in Hamburg, <a href="http://tinkerlog.com/">Alex</a> and I have established a regularly tinker drinkup every Thursday (nearly) at <a href="http://www.qype.co.uk/place/5426-Saal-II-Hamburg">Saal II</a>.</p>
<p><img class="slickr-post colorbox-471" src="http://farm3.static.flickr.com/2657/4156498852_6e28b3e04e.jpg" alt="Tinker Drinkup" width="500" height="281" /></p>
<p>Currently it is a very cosy drinkup, just a few guests. Hopefully this will change. We post announcements with very short notice <a href="http://twitter.com/#search?q=%23palo_altona">on Twitter via #palo_altona</a>. If you want to join to discuss some tinker stuff or present your Arduino or tinker projects, just tell <a href="http://twitter.com/9600baud">Alex</a> or <a href="http://twitter.com/interactmatter">me</a> and we will tell when the next <a href="http://twitter.com/#search?q=%23palo_altona">#palo_altona</a> takes place.</p>
<p>Und nun zur deutschen Version:</p>
<p><span id="more-471"></span>Um auch in Hamburg einen regelmäßige Austauch zu Arduino, Tinkern und Open Source Hardware zu etablieren haben <a href="http://tinkerlog.com/">Alex</a> und ich &#8216;Palo Altona&#8217; gegründet. Ein regelmäßiges, manchmal auch unregelmäßiges, Treffen, jeden Donnerstag, im <a href="http://www.qype.com/place/5426-Saal-II-Hamburg">Saal II</a> in der Schanze. Gäste sind gerne willkommen!</p>
<p>Die Koordination erfolgt recht kurzfristig (leider bisher meist erst am selben Tag) über <a href="http://twitter.com/#search?q=%23palo_altona">Twitter (#palo_atona)</a>. Meldet euch bei <a href="http://twitter.com/9600baud">Alex</a> oder <a href="http://twitter.com/interactmatter">mir</a> und wir geben Bescheid ob und wann das nächste Treffen ist. Wir freuen uns über jeden Gast.</p>
<p>Und falls jemand eine bessere Idee zur Koordination hat, einfach in den Kommentare melden.</p>


<p>No related posts.</p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/ewB31wB6ZbY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2010/01/palo-altona-%e2%80%93-hamburg-tinker-drinkup/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2010/01/palo-altona-%e2%80%93-hamburg-tinker-drinkup/</feedburner:origLink></item>
		<item>
		<title>Seasonal Greetings</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/Sms9GZlyZ1Q/</link>
		<comments>http://interactive-matter.org/2009/12/seasonal-greetings/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 18:37:27 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Tinkering]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=506</guid>
		<description><![CDATA[This is definitively the last post for this year. So I wish everybody Merry Christmas or whatever you want to celebrate and a pleasant &#38; successful new year!

Even I stopped tinkering and went on to hacking cookies. Have fun &#38; take care!


Related posts:Last year in electronics
]]></description>
			<content:encoded><![CDATA[<p></p><p>This is definitively the last post for this year. So I wish everybody Merry Christmas or whatever you want to celebrate and a pleasant &amp; successful new year!</p>
<p><a title="Space Invaders Cookies" href="http://farm3.static.flickr.com/2642/4197092247_b1ae89cb50_b.jpg"><img class="slickr-post colorbox-506" src="http://farm3.static.flickr.com/2642/4197092247_b1ae89cb50.jpg" alt="Space Invaders Cookies" width="500" height="375" /></a></p>
<p>Even I stopped tinkering and went on to hacking cookies. Have fun &amp; take care!</p>


<p>Related posts:<ul><li><a href='http://interactive-matter.org/2009/01/last-year-in-electronics/' rel='bookmark' title='Permanent Link: Last year in electronics'>Last year in electronics</a></li>
</ul></p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/Sms9GZlyZ1Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2009/12/seasonal-greetings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2009/12/seasonal-greetings/</feedburner:origLink></item>
		<item>
		<title>Filtering Sensor Data with a Kalman Filter</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/JmJrnZdoTBk/</link>
		<comments>http://interactive-matter.org/2009/12/filtering-sensor-data-with-a-kalman-filter/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 20:38:25 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Tinkering]]></category>
		<category><![CDATA[Accelerometer]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Filter]]></category>
		<category><![CDATA[Kalman Filter]]></category>
		<category><![CDATA[LIS302DL]]></category>
		<category><![CDATA[Noise]]></category>
		<category><![CDATA[sensor noise]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=487</guid>
		<description><![CDATA[Some days ago I wrote about noise with a LIS302DL accelerometer. There is obviously something wrong with my hardware. But before I get a new version out I need to implement some software filtering.

After some unsuccessful results with low pass filters I choose the Kalman Filter. The Kalman Filter involves an awful lot of complicated [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Some days ago I wrote about <a href="http://interactive-matter.org/2009/12/decoupling-lis302dl-%E2%80%93-there-i-fixed-it/">noise with a LIS302DL accelerometer</a>. There is obviously something wrong with my hardware. But before I get a new version out I need to implement some software filtering.</p>
<p><a title="Process Noise 4.0" href="http://farm3.static.flickr.com/2546/4195425248_99e844c507_o.png"><img src="http://farm3.static.flickr.com/2546/4195425248_d6b3083536.jpg" alt="Process Noise 0.125" width="500" height="250"  class="slickr-post colorbox-487" /></a></p>
<p>After some unsuccessful results with <a href="http://en.wikipedia.org/wiki/Low_pass_filter">low pass filters</a> I choose the <a href="http://en.wikipedia.org/wiki/Kalman_filter">Kalman Filter.</a> The Kalman Filter involves <a href="http://en.wikipedia.org/wiki/Kalman_filter#The_Kalman_filter">an awful lot of complicated mathematics.</a> But fortunately I just needed a simple one dimensional Kalman Filter without any driving information, which makes the filter much easier.<br />
<span id="more-487"></span></p>
<h3>Implementing the Kalman Filter</h3>
<p>If you check the Kalman Filter formulas, you will encounter a lot of complicated matrix and vector math. But after some research on the application domain for an LIS302DL accelerometer I found out that a simple one dimensional filter will do the job. The accelerometer puts out three dimensional acceleration data. But if you just want to get clean acceleration data from it all formulas simply deal with one dimension. So it was easier to use three different one dimensional Kalman filters. It all ended in a small set of formulas:</p>
<p><em>x = x<br />
p = p + q;</em></p>
<p><em>k = p / (p + r);<br />
x = x + k * (measurement &#8211; x);<br />
p = (1 &#8211; k) * p;</em></p>
<p>The first two formulas represent the prediction of the Kalman Filter. And since there is no information about the driving forces it is very simple. The second three formulas calculate the measurement update. The variables are <em>x</em> for the filtered value,  <em>q</em> for the process noise, <em>r</em> for the sensor noise, <em>p</em> for the estimated error and <em>k</em> for the Kalman Gain. The state of the filter is defined by the values of these variables.</p>
<p>The filter is applied with each measurement and initialized with the process noise <em>q</em>, the sensor noise <em>r</em>, the initial estimated error <em>p</em> and the initial value <em>x</em>. The initial values for <em>p</em> is not very important since it is adjusted during the process. It must be just high enough to narrow down. The initial value for the readout is also not very important, since it is updated during the process.</p>
<p>But tweaking the values for the process noise and sensor noise is essential to get clear readouts.</p>
<h3>Tweaking the Kalman Filter</h3>
<p>The first results were less than ideal. So I decided to use processing and my good old <a href="http://interactive-matter.org/2009/02/arduino-lis302dl/">LIS302DL breakout board</a> to get some insight of the optimal values of the different parameters:</p>
<p>First I looked into the importance of the process noise <em>q</em>, starting by a very high value of 128 (which is the maximum output of the accelerometer):</p>
<p><a title="Process Noise 128" href="http://farm3.static.flickr.com/2549/4194672843_0baecec073_o.png"><img class="slickr-post colorbox-487" src="http://farm3.static.flickr.com/2549/4194672843_375fde33c4.jpg" alt="Process Noise 128" width="500" height="250" /></a><br />
You see there is nearly no difference between the filtered data (white) and the original data (grey) – since you just see the white line.<br />
If you turn down the process noise, e.g. to a value of 4 things start to change:</p>
<p><a title="Process Noise 4" href="http://farm3.static.flickr.com/2624/4195428360_9bc06e5802_o.png"><img class="slickr-post colorbox-487" src="http://farm3.static.flickr.com/2624/4195428360_9bc06e5802_o.png" alt="Process Noise 4" width="500" height="250" /></a></p>
<p>If you look closely you see that the sensor data often overshoots the filtered value. The filtered value is pretty close to the real value, but is missing a lot of noise. For my application I needed a more static output, smoothing out nearly all of the noise, giving a clean an steady signal. So lets turn down the process noise value a bit more, e.g. something like 0.125:</p>
<p><a title="Process Noise 0.125" href="http://farm3.static.flickr.com/2727/4195426644_47c6ac3217_o.png"><img class="slickr-post colorbox-487" src="http://farm3.static.flickr.com/2727/4195426644_5f93a20a79.jpg" alt="Process Noise 0.125" width="500" height="250" /></a></p>
<p>Now we got a quite a clean signal from quite a noisy source. It lags a bit behind the real data, but that is not critical for my application. Compared to the amount of noise reduction it is still quite fast.<br />
After this is set let&#8217;s play a bit around with the sensor noise <em>r</em>:<br />
We start back at <em>r</em>=1:</p>
<p><a title="Sensor Noise 1.0" href="http://farm3.static.flickr.com/2541/4194668397_f0f7e55f51_o.png"><img class="slickr-post colorbox-487" src="http://farm3.static.flickr.com/2541/4194668397_fbe4e83636.jpg" alt="Sensor Noise 1.0" width="500" height="250" /></a></p>
<p>As expected if we turn down the assumed noise of the sensor the Kalman filter &#8216;relies&#8217; more on the sensor data and gives more noisy results. If we increase the noise factor of the sensor to 4 we get a more stable result again:</p>
<p><a title="Process Noise 4.0" href="http://farm3.static.flickr.com/2546/4195425248_99e844c507_o.png"><img class="slickr-post colorbox-487" src="http://farm3.static.flickr.com/2546/4195425248_d6b3083536.jpg" alt="Process Noise 0.125" width="500" height="250" /></a></p>
<p>If we go up extreme and assume a noise level of 32 we get the expected steady result:</p>
<p><a title="Process Noise 32.0" href="http://farm3.static.flickr.com/2658/4195424262_a1939bd51f_o.png"><img class="slickr-post colorbox-487" src="http://farm3.static.flickr.com/2658/4195424262_73d3e5d471.jpg" alt="Process Noise 0.125" width="500" height="250" /></a></p>
<p>As expected the filtered value lags significantly behind the real measurement. But it is a much cleaner signal. But  it is questionable if this is still useful.</p>
<h3>Implementing Kalman in C</h3>
<p>Implementing this filter in C code (e.g. for an Arduino) is quite simple. First of all we define a state for a kalman filter:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">double</span> q<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//process noise covariance</span>
  <span style="color: #993333;">double</span> r<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//measurement noise covariance</span>
  <span style="color: #993333;">double</span> x<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//value</span>
  <span style="color: #993333;">double</span> p<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//estimation error covariance</span>
  <span style="color: #993333;">double</span> k<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//kalman gain</span>
<span style="color: #009900;">&#125;</span> kalman_state<span style="color: #339933;">;</span></pre></div></div>

<p>Next we need a function to initialize the kalman filter:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">kalman_state
kalman_init<span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span> q<span style="color: #339933;">,</span> <span style="color: #993333;">double</span> r<span style="color: #339933;">,</span> <span style="color: #993333;">double</span> p<span style="color: #339933;">,</span> <span style="color: #993333;">double</span> intial_value<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  kalman_state result<span style="color: #339933;">;</span>
  result.<span style="color: #202020;">q</span> <span style="color: #339933;">=</span> q<span style="color: #339933;">;</span>
  result.<span style="color: #202020;">r</span> <span style="color: #339933;">=</span> r<span style="color: #339933;">;</span>
  result.<span style="color: #202020;">p</span> <span style="color: #339933;">=</span> p<span style="color: #339933;">;</span>
  result.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> intial_value<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And a function to update the kalman state, by calculating a prediction and verifying that against the real measurement:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span>
kalman_update<span style="color: #009900;">&#40;</span>kalman_state<span style="color: #339933;">*</span> state<span style="color: #339933;">,</span> <span style="color: #993333;">double</span> measurement<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">//prediction update</span>
  <span style="color: #666666; font-style: italic;">//omit x = x</span>
  state<span style="color: #339933;">-&gt;</span>p <span style="color: #339933;">=</span> state<span style="color: #339933;">-&gt;</span>p <span style="color: #339933;">+</span> state<span style="color: #339933;">-&gt;</span>q<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//measurement update</span>
  state<span style="color: #339933;">-&gt;</span>k <span style="color: #339933;">=</span> state<span style="color: #339933;">-&gt;</span>p <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>state<span style="color: #339933;">-&gt;</span>p <span style="color: #339933;">+</span> state<span style="color: #339933;">-&gt;</span>r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  state<span style="color: #339933;">-&gt;</span>x <span style="color: #339933;">=</span> state<span style="color: #339933;">-&gt;</span>x <span style="color: #339933;">+</span> state<span style="color: #339933;">-&gt;</span>k <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>measurement <span style="color: #339933;">-</span> state<span style="color: #339933;">-&gt;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  state<span style="color: #339933;">-&gt;</span>p <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">-</span> state<span style="color: #339933;">-&gt;</span>k<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> state<span style="color: #339933;">-&gt;</span>p<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>What did we learn from this?</h3>
<p>First of all the Kalman filter can be much easier to implement if the underlying model is simple. We had not several dimensions, nor different sensor data to combine. The results are pretty good, but it is a challenge to find the right values for the process and sensor noise. Instead of just coming up with some guesses for the values, they can of course be estimated, but than we have to live with the result of the estimation.</p>
<p>In the end it is a good, robust, simple filter (in one dimension).</p>
<p>I think that in lack of several sensors we throw out the most advantage of the filter to combine several sensor data to a combined result. I think going a bit more in this direction can lead to real interesting results.</p>
<p>Or is there a much easier filter to use for my problem, leading to better results?</p>


<p>Related posts:<ul><li><a href='http://interactive-matter.org/2009/12/arduino-barometric-pressure-sensor-bmp085/' rel='bookmark' title='Permanent Link: Arduino &#038; Barometric Pressure Sensor BMP085'>Arduino &#038; Barometric Pressure Sensor BMP085</a></li>
<li><a href='http://interactive-matter.org/2009/12/decoupling-lis302dl-%e2%80%93-there-i-fixed-it/' rel='bookmark' title='Permanent Link: Decoupling LIS302DL – There I fixed it!'>Decoupling LIS302DL – There I fixed it!</a></li>
</ul></p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/JmJrnZdoTBk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2009/12/filtering-sensor-data-with-a-kalman-filter/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2009/12/filtering-sensor-data-with-a-kalman-filter/</feedburner:origLink></item>
		<item>
		<title>Decoupling LIS302DL – There I fixed it!</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/Cgp6OvuBKl8/</link>
		<comments>http://interactive-matter.org/2009/12/decoupling-lis302dl-%e2%80%93-there-i-fixed-it/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 19:20:51 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Tinkering]]></category>
		<category><![CDATA[Accelerometer]]></category>
		<category><![CDATA[Decoupling]]></category>
		<category><![CDATA[Fail]]></category>
		<category><![CDATA[Filter]]></category>
		<category><![CDATA[LIS302DL]]></category>
		<category><![CDATA[Noise]]></category>
		<category><![CDATA[PCB]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=482</guid>
		<description><![CDATA[As you probably know, I really like I2C sensors and especially the LIS302DL. But adding this accelerometer to your circuit is not as straight forward as I thought. But in the end I got it quite right.

It all started out with a 0.1µF ceramic capacitor. For good measure I put a ferrite bead in front. [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>As you probably know, I really like <a href="http://interactive-matter.org/tag/i2c/">I2C</a> <a href="http://interactive-matter.org/category/sensors/">sensors</a> and especially the <a href="http://interactive-matter.org/2009/02/arduino-lis302dl/">LIS302DL</a>. But adding this accelerometer to your circuit is not as straight forward as I thought. But in the end I got it quite right.<br />
<a title="Decoupling LIS302DL" href="http://farm3.static.flickr.com/2649/4188400702_bed6d4677c_b.jpg"><img class="slickr-post colorbox-482" src="http://farm3.static.flickr.com/2649/4188400702_bed6d4677c.jpg" alt="Decoupling LIS302DL" width="500" height="375" /></a><br />
It all started out with a 0.1µF ceramic capacitor. For good measure I put a ferrite bead in front. But this lead to terrible readouts. So I threw in a 10µF 0805 ceramic capacitor and a 4.7µF tantalum capacitor. It does not look nice, nor does it look terribly solid, but it works fine.<br />
So read on, what my analysis of the situation is.<br />
<span id="more-482"></span>My original layout had just a small ferrite bead and a way too small capacitor. And this on a board hosting a ATmega168 and four alphanumeric displays, drawing from 0 to 300mA, from a step up voltage controller. Of course I had about 400µF decoupling capacitors on board, but the direct power supply of the LIS302DL had still about 0.1 Volts of noise on the power supply line. And the readouts were extremely noisy (&gt;10%).</p>
<p>Not good.</p>
<p>Throwing in some capacitance was a good idea and reduced the noise by something like factor 2. But still it is very noisy. The <a href="http://www.st.com/stonline/products/literature/ds/12726.pdf">LIS302DL datasheet</a> suggest using at least a 10µF and a 0.1µF capacitor of different types (e.g. ceramic and tantalum) – I think it is just some minimum requirements. Proper voltage supply with as less noise as possible is a must.</p>
<p>So my next try will be:</p>
<ul>
<li>Redoing the complete layout so that the power supply of the LEDs is uses separate VCC and ground paths than the digital circuit.</li>
<li>Redoing the same for both chips, so that I got some <a href="http://www.aikenamps.com/StarGround.html">star like grounding</a> and supply system. Or some carefully laid out power planes.</li>
<li>Adding bigger ferrite beads in the supply line of the LEDs and both chips, so that each component has its own supply line with ferrite beads and capacitors, to reduce cross talk.</li>
<li>Perhaps adding some <a href="http://en.wikipedia.org/wiki/Low_dropout_regulator">LDO regulator</a> to drive the digital circuitry from 3V instead of 3.3V to reduce the noise of the LEDs or power supply.</li>
</ul>
<p>I alwayys thought good power supply design is just for audio stuff or other high quality applications, but I learned (the hard way) that you also need it for just some basic tinkering.</p>
<p>So off to the next design.</p>


<p>Related posts:<ul><li><a href='http://interactive-matter.org/2009/12/filtering-sensor-data-with-a-kalman-filter/' rel='bookmark' title='Permanent Link: Filtering Sensor Data with a Kalman Filter'>Filtering Sensor Data with a Kalman Filter</a></li>
<li><a href='http://interactive-matter.org/2009/02/arduino-lis302dl/' rel='bookmark' title='Permanent Link: Arduino &#038; LIS302DL'>Arduino &#038; LIS302DL</a></li>
</ul></p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/Cgp6OvuBKl8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2009/12/decoupling-lis302dl-%e2%80%93-there-i-fixed-it/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2009/12/decoupling-lis302dl-%e2%80%93-there-i-fixed-it/</feedburner:origLink></item>
		<item>
		<title>Arduino &amp; Barometric Pressure Sensor BMP085</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/L9K2CZ5ZVo4/</link>
		<comments>http://interactive-matter.org/2009/12/arduino-barometric-pressure-sensor-bmp085/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 21:05:54 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Sensors]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Barometer]]></category>
		<category><![CDATA[BMP085]]></category>
		<category><![CDATA[I2C]]></category>
		<category><![CDATA[Pressure Sensor]]></category>
		<category><![CDATA[SMT]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=451</guid>
		<description><![CDATA[In lack of any new projects (which are currently all in an very intermediate state) Interactive Matter presents yet another &#8216;how to connect a cool I2C sensor to Arduino&#8217; post.
This time it is all about pressure. The BMP085 pressure sensor combines a absolute barometric pressure sensor (aka barometer) with an temperature sensor. It is build [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>In lack of any new projects (which are currently all in an very intermediate state) Interactive Matter presents yet another &#8216;how to connect a cool <a href="http://en.wikipedia.org/wiki/I2c">I2C</a> sensor to Arduino&#8217; post.</p>
<p>This time it is all about pressure. The <a href="http://www.bosch-sensortec.com/content/language1/html/3477.htm">BMP085</a> pressure sensor combines a absolute barometric pressure sensor (aka <a href="http://en.wikipedia.org/wiki/Barometer">barometer</a>) with an temperature sensor. It is build by <a href="http://www.bosch-sensortec.com/content/language1/html/index.htm">Bosch Sensortec</a> and intended to help <a href="http://en.wikipedia.org/wiki/Gps">GPS navigation units</a> to detect their height above sea level. It combines the advantage of being quite cheap (~5$) and precise.</p>
<p><a title="Arduino &amp; Barometric Pressure Sensor BMP085" href="http://farm3.static.flickr.com/2485/4159864537_6e11c303e3_b.jpg"><img class="slickr-post colorbox-451" src="http://farm3.static.flickr.com/2485/4159864537_6e11c303e3.jpg" alt="Arduino &amp; Barometric Pressure Sensor BMP085" width="500" height="375" /></a></p>
<p>But of course there are myriads of other applications as well, like using it in a digital weather station, detecting the force of slammed doors or …</p>
<p><span id="more-451"></span></p>
<p>Update: <strong>For a limited time the <a href="http://interactive-matter.org/shop/breakout-boards/bmp085-barometric-pressure-sensor-breakout-board/">BMP085 break out board is available in the Interactive Matter Shop</a>.</strong></p>
<p>The information about this sensor is very sparse and Bosch is not very keen to give any information to makers. But fortunately <a href="http://news.jeelabs.org/">Jeelabs</a> offers it as an <a href="http://shop.jeelabs.com/products/pressure-plug">extension module</a> for their <a href="http://shop.jeelabs.com/products/jeenode-usb">Jeenode</a> and <a href="http://news.jeelabs.org/2009/02/19/hooking-up-a-bmp085-sensor/">published some very helpful code</a> for it (which helped a lot – check out they are doing really amazing stuff).</p>
<h3>Hardware</h3>
<p><a title="Arduino &amp; Barometric Pressure Sensor BMP085" href="http://farm3.static.flickr.com/2619/4159862811_a851fe280c_b.jpg"><img class="slickr-post colorbox-451" src="http://farm3.static.flickr.com/2619/4159862811_a851fe280c.jpg" alt="Arduino &amp; Barometric Pressure Sensor BMP085" width="500" height="375" /></a></p>
<p>Hooking up the BMP085 to the Arduino works just like any other I2C part: Connect VCC to VCC and GND to GND, SCL goes to analogue pin 5, SDA to analogue pin4. Adding some pull up resistors (1K to 20K, most often something like 4.7K) between SDA, SCL and VCC finishes the setup (this was included in my breakout board).</p>
<p>The BMP08 accepts 1.8 to 3.6 Volts – so no chance to connect it directly to 5 Volts. The BMP085 has an additional EOC (end of conversion) pin indicating the successful data capture. This was connected to analogue pin 2 – but not used in the software implementation.</p>
<h3>Software</h3>
<p>Fortunately the code by Jeenode contained all the functionality, you need, taken directly from <a href="http://www.bosch-sensortec.com/content/language1/downloads/BST-BMP085-DS000-05.pdf">the datasheet</a>. The only thing I added was the ability to use all oversampling modes (the BMP085 offers 4 oversampling mode, each on taking longer than the other and using more energy, but delivering more precise results).</p>
<p>First we need the ability to read 16 bit values from the BMP085 registers. Nearly all registers of the BMP085 are 16 bit wide:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> r<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> msb<span style="color: #339933;">,</span> lsb<span style="color: #339933;">;</span>
  Wire.<span style="color: #202020;">beginTransmission</span><span style="color: #009900;">&#40;</span>I2C_ADDRESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Wire.<span style="color: #202020;">send</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// register to read</span>
  Wire.<span style="color: #202020;">endTransmission</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  Wire.<span style="color: #202020;">requestFrom</span><span style="color: #009900;">&#40;</span>I2C_ADDRESS<span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// read a byte</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Wire.<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: #666666; font-style: italic;">// waiting</span>
  <span style="color: #009900;">&#125;</span>
  msb <span style="color: #339933;">=</span> Wire.<span style="color: #202020;">receive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Wire.<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: #666666; font-style: italic;">// waiting</span>
  <span style="color: #009900;">&#125;</span>
  lsb <span style="color: #339933;">=</span> Wire.<span style="color: #202020;">receive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</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>msb<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</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>lsb<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Second you need a function to write a 8 bit register:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> read_register<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> r<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> v<span style="color: #339933;">;</span>
  Wire.<span style="color: #202020;">beginTransmission</span><span style="color: #009900;">&#40;</span>I2C_ADDRESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Wire.<span style="color: #202020;">send</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// register to read</span>
  Wire.<span style="color: #202020;">endTransmission</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  Wire.<span style="color: #202020;">requestFrom</span><span style="color: #009900;">&#40;</span>I2C_ADDRESS<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// read a byte</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Wire.<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: #666666; font-style: italic;">// waiting</span>
  <span style="color: #009900;">&#125;</span>
  v <span style="color: #339933;">=</span> Wire.<span style="color: #202020;">receive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> v<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we can define some global variables to read the Eeprom calibration data:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//just taken from the BMP085 datasheet</span>
<span style="color: #993333;">int</span> ac1<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> ac2<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> ac3<span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> ac4<span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> ac5<span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> ac6<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> b1<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> b2<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> mb<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> mc<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> md<span style="color: #339933;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span>  bmp085_get_cal_data<span style="color: #009900;">&#40;</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;Reading Calibration Data&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ac1 <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xAA</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;AC1: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>ac1<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ac2 <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xAC</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;AC2: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>ac2<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ac3 <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xAE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;AC3: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>ac3<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ac4 <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xB0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;AC4: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>ac4<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ac5 <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xB2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;AC5: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>ac5<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ac6 <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xB4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;AC6: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>ac6<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  b1 <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xB6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;B1: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>b1<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  b2 <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xB8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;B2: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>b1<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  mb <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xBA</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;MB: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>mb<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  mc <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xBC</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;MC: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>mc<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  md <span style="color: #339933;">=</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xBE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;MD: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>md<span style="color: #339933;">,</span>DEC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The Eeprom readout can be done more efficiently by reading all the values with just one register write. But it is more comprehensible like this and in the initialization phase we have good amount of time.<br />
The raw temperature (<code>ut</code>) and pressure (<code>up</code>) data can be readout as 16 bit and 24 bit value:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> bmp085_read_ut<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  write_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xf4</span><span style="color: #339933;">,</span><span style="color: #208080;">0x2e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//longer than 4.5 ms</span>
  <span style="color: #b1b100;">return</span> read_int_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xf6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">long</span> bmp085_read_up<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  write_register<span style="color: #009900;">&#40;</span><span style="color: #208080;">0xf4</span><span style="color: #339933;">,</span><span style="color: #208080;">0x34</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>oversampling_setting<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span>pressure_waittime<span style="color: #009900;">&#91;</span>oversampling_setting<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> msb<span style="color: #339933;">,</span> lsb<span style="color: #339933;">,</span> xlsb<span style="color: #339933;">;</span>
  Wire.<span style="color: #202020;">beginTransmission</span><span style="color: #009900;">&#40;</span>I2C_ADDRESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Wire.<span style="color: #202020;">send</span><span style="color: #009900;">&#40;</span><span style="color: #208080;">0xf6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// register to read</span>
  Wire.<span style="color: #202020;">endTransmission</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  Wire.<span style="color: #202020;">requestFrom</span><span style="color: #009900;">&#40;</span>I2C_ADDRESS<span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// read a byte</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Wire.<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: #666666; font-style: italic;">// waiting</span>
  <span style="color: #009900;">&#125;</span>
  msb <span style="color: #339933;">=</span> Wire.<span style="color: #202020;">receive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Wire.<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: #666666; font-style: italic;">// waiting</span>
  <span style="color: #009900;">&#125;</span>
  lsb <span style="color: #339933;">|=</span> Wire.<span style="color: #202020;">receive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Wire.<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: #666666; font-style: italic;">// waiting</span>
  <span style="color: #009900;">&#125;</span>
  xlsb <span style="color: #339933;">|=</span> Wire.<span style="color: #202020;">receive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span>msb<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span>lsb<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span>xlsb<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">8</span><span style="color: #339933;">-</span>oversampling_setting<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The conversion between the raw data and the real temperature data in 0.1 <a href="http://en.wikipedia.org/wiki/Degree_Celsius">°C</a> an <a href="http://en.wikipedia.org/wiki/Pascal_(unit)">Pascal</a> is taken from the <a href="http://www.bosch-sensortec.com/content/language1/downloads/BST-BMP085-DS000-05.pdf">datasheet</a> (combined with <a href="http://news.jeelabs.org/2009/02/19/hooking-up-a-bmp085-sensor/">the corrections</a> of Jeenodes):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> bmp085_read_temperature_and_pressure<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #339933;">*</span> temperature<span style="color: #339933;">,</span> <span style="color: #993333;">long</span><span style="color: #339933;">*</span> pressure<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span>  ut<span style="color: #339933;">=</span> bmp085_read_ut<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #993333;">long</span> up <span style="color: #339933;">=</span> bmp085_read_up<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #993333;">long</span> x1<span style="color: #339933;">,</span> x2<span style="color: #339933;">,</span> x3<span style="color: #339933;">,</span> b3<span style="color: #339933;">,</span> b5<span style="color: #339933;">,</span> b6<span style="color: #339933;">,</span> p<span style="color: #339933;">;</span>
  <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> b4<span style="color: #339933;">,</span> b7<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//calculate the temperature</span>
  x1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span>ut <span style="color: #339933;">-</span> ac6<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> ac5 <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">15</span><span style="color: #339933;">;</span>
  x2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span> mc <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">11</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>x1 <span style="color: #339933;">+</span> md<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  b5 <span style="color: #339933;">=</span> x1 <span style="color: #339933;">+</span> x2<span style="color: #339933;">;</span>
  <span style="color: #339933;">*</span>temperature <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>b5 <span style="color: #339933;">+</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//calculate the pressure</span>
  b6 <span style="color: #339933;">=</span> b5 <span style="color: #339933;">-</span> <span style="color: #0000dd;">4000</span><span style="color: #339933;">;</span>
  x1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>b2 <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>b6 <span style="color: #339933;">*</span> b6 <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span>
  x2 <span style="color: #339933;">=</span> ac2 <span style="color: #339933;">*</span> b6 <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span>
  x3 <span style="color: #339933;">=</span> x1 <span style="color: #339933;">+</span> x2<span style="color: #339933;">;</span>
  b3 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int32_t<span style="color: #009900;">&#41;</span> ac1 <span style="color: #339933;">*</span> <span style="color: #0000dd;">4</span> <span style="color: #339933;">+</span> x3<span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
  x1 <span style="color: #339933;">=</span> ac3 <span style="color: #339933;">*</span> b6 <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">13</span><span style="color: #339933;">;</span>
  x2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>b1 <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>b6 <span style="color: #339933;">*</span> b6 <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">;</span>
  x3 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x1 <span style="color: #339933;">+</span> x2<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;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
  b4 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ac4 <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>x3 <span style="color: #339933;">+</span> <span style="color: #0000dd;">32768</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">15</span><span style="color: #339933;">;</span>
  b7 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span> up <span style="color: #339933;">-</span> b3<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">50000</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> oversampling_setting<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  p <span style="color: #339933;">=</span> b7 <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #208080;">0x80000000</span> <span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span>b7 <span style="color: #339933;">*</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> b4 <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>b7 <span style="color: #339933;">/</span> b4<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
&nbsp;
  x1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>p <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>p <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  x1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>x1 <span style="color: #339933;">*</span> <span style="color: #0000dd;">3038</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">;</span>
  x2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">7357</span> <span style="color: #339933;">*</span> p<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">*</span>pressure <span style="color: #339933;">=</span> p <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x1 <span style="color: #339933;">+</span> x2 <span style="color: #339933;">+</span> <span style="color: #0000dd;">3791</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Unfortunately temperature and pressure had to be computed at the same time (the temperature value is used for the pressure calculation). <code>int*</code> means a pointer to an integer value, which is written like <code>*temperature = (b5 + 8 ) &gt;&gt; 4;</code>. the function is called like</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">  <span style="color: #993333;">int</span>  temperature <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  <span style="color: #993333;">long</span> pressure <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
  bmp085_read_temperature_and_pressure<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>temperature<span style="color: #339933;">,&amp;</span>amp<span style="color: #339933;">;</span>pressure<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It is very simple and gives very good results.<br />
If you want to try it yourself get the <a href="http://interactive-matter.org/wp-content/uploads/2009/12/BMP085.pde_.zip">BMP085 Arduino Sketch</a>. If there is any interest in the breakout board (assembled or unassembled) just <a href="http://interactive-matter.org/contact/">drop me a note.</a></p>
<p><em>And big thanks to <a href="http://news.jeelabs.org/">Jeelabs</a>. Their code helped me a lot they real awesome stuff!</em></p>


<p>Related posts:<ul><li><a href='http://interactive-matter.org/2010/02/bmp085-barometric-pressure-sensor-breakout-boards-arrived/' rel='bookmark' title='Permanent Link: BMP085 Barometric Pressure Sensor Breakout Boards arrived!'>BMP085 Barometric Pressure Sensor Breakout Boards arrived!</a></li>
<li><a href='http://interactive-matter.org/2009/02/arduino-lis302dl/' rel='bookmark' title='Permanent Link: Arduino &#038; LIS302DL'>Arduino &#038; LIS302DL</a></li>
<li><a href='http://interactive-matter.org/2009/07/arduino-ad7746/' rel='bookmark' title='Permanent Link: Arduino &#038; AD7746'>Arduino &#038; AD7746</a></li>
</ul></p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/L9K2CZ5ZVo4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2009/12/arduino-barometric-pressure-sensor-bmp085/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2009/12/arduino-barometric-pressure-sensor-bmp085/</feedburner:origLink></item>
		<item>
		<title>Driving Circuits from a CR2032 Lithium Coin Cell</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/hWXej0kfW1M/</link>
		<comments>http://interactive-matter.org/2009/08/driving-circuits-from-a-cr2032-lithium-coin-cell/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 15:32:26 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Tinkering]]></category>
		<category><![CDATA[cell batteries]]></category>
		<category><![CDATA[coin cell]]></category>
		<category><![CDATA[CR2032]]></category>
		<category><![CDATA[equivalent series resistance]]></category>
		<category><![CDATA[ESR]]></category>
		<category><![CDATA[internal resistance]]></category>
		<category><![CDATA[Power]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=441</guid>
		<description><![CDATA[Just another good example of &#8216;lesson learned&#8217;. I often use the very common CR2032 coin cell batteries to drive my circuits. Small, cheap, easy to get and there is a quite a range of good and cheap battery holders.

But recently I have tested an complete over the top design which pushed the poor little CR2032 [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Just another good example of &#8216;lesson learned&#8217;. I often use the very common CR2032 coin cell batteries to drive my circuits. Small, cheap, easy to get and there is a quite a range of good and cheap battery holders.</p>
<p><a title="CR2032 Battery" href="http://farm4.static.flickr.com/3517/3734750249_c980a7b27e_o.jpg"><img class="slickr-post colorbox-441" src="http://farm4.static.flickr.com/3517/3734750249_90ddeedbd4.jpg" alt="CR2032 Battery" width="500" height="375" /></a></p>
<p>But recently I have tested an complete over the top design which pushed the poor little CR2032 far beyond its limits. Time to grab a few facts from the datasheet for further reference.</p>
<p><span id="more-441"></span>To get a good example I found a quite elaborate <a href="http://data.energizer.com/PDFs/cr2032.pdf">CR2032 datasheet from Duracell</a>. I think other batteries behave quite similar to this.</p>
<h3>The Issue</h3>
<p>The general key fact of an CR2032 are obvious and quite easy to grab from the datasheet:</p>
<p><em>Voltage: 3V</em></p>
<p><em>Capacity: 240mAh (to 2.0V)</em></p>
<p>If you study the datasheet more closely you will see that the voltages drop sharply after it reaches 2.8V (after it has delivered about 170mAh).</p>
<p><em>ESR (Equivalent Series Resistor):about 18 to 20 Ohms.</em></p>
<p>The ESR (Equivalent Series Resistor) or IR (Internal Resistance) is quite flat up to 150mAh of capacitance &#8211; there it reaches about 20 Ohms. At 170mAh it reaches something like 30 Ohms. This is quite hefty. In comparison good capacitors have a series resistance from some Ohms to a fraction of an Ohm &#8211; so it is always good to put some (even electrolytic) capacitors in series with the battery. If you are concerned that switching on or of of your circuits discharges the battery to much by charging up the capacitors – there is a simple trick to prevent it: put the capacitors in front of the &#8216;on&#8217; switch so that are always charged and will not charge after your circuit is switched on. The leakage current will be so small that it will be neglectable in most cases.</p>
<p>But if you want to calculate how much constant current you can draw from these batteries you have to use <a href="http://en.wikipedia.org/wiki/Ohm%27s_law">Ohm&#8217;s law</a>:</p>
<p>V = R * I or I = V /R</p>
<p>If you take the later and say you want no voltage drop higher that 1.2 Volts &#8211; because after that your circuit reaches 1.8 Volts which makes your microcontroller most probably going brown out. Applying these with the ESR of 20 Ohms, you will get something like 60 mA you can draw by them (I = 1.2V/20Ohm). You if calculate more conservative and do not want to go below 2.8V &#8211; which gives you some 0.2 Volts head room  &#8211; you will only be able to draw 10 mA (I = 0.2V/20Ohm) &#8211; just enough for an LED. These calculations do not consider the voltage drop of the battery of its life time.</p>
<p><em>In the bottom line: If you use those batteries you have to consider the 20-30 Ohms series resistance. Especially if you draw some constant current (spikes can be easily removed using capacitors). Yo have to assume 170mAh as maximum capacitance because then the CR2032 reaches 2.8Volts and the ESR goes up to a whopping 30 Ohms – going up from there very steep. Because of the high ESR of the CR2032 you will most probably not be able to draw more than 20-30 mAh safely (as constant current).<br />
</em></p>
<p><em>Perhaps it is even better to get a boost converter to 3 or 3.3V &#8211; to suck out all the juice in the battery. This should should be good for the environment too. Or even better get rechargeable Lithium Cells.<br />
</em></p>
<p>So driving an RGB with an 5V boost op converter is impossible. At white (all three LEDs draw 20mA) it is 60mA current at 5V, considering a efficiency of 80% this will give you more than 120 mAh at 3.3V. Impossible or the CR2032. So my intended design will never work. I wish I had done those calculations before I designed it and not after I saw that the prototype does not work.</p>
<p>You live and learn!</p>
<h3>Some Closer Look</h3>
<p>As we see the higher the current is the more loss we get by the ESR of 20 Ohms. So the question is how much power we can get from an CR2032. If we want to draw the maximum amount of power over a short time we simply take the <a href="http://en.wikipedia.org/wiki/Electric_power">power</a>:</p>
<p>P=V*I</p>
<p>And we know that the voltage is</p>
<p>v=3-20*I</p>
<p>And we get</p>
<p>P=(3-20*I)*I</p>
<p>If we create a little graph from it we get</p>
<p><a title="CR2032 Wattage" href="http://farm4.static.flickr.com/3514/3906676695_f75568a3d6_o.png"><img class="slickr-post colorbox-441" src="http://farm4.static.flickr.com/3514/3906676695_4a25f2f7df.jpg" alt="CR2032 Wattage" width="500" height="282" /></a></p>
<p>So we see that the maximum is somewhere at 75mA and somwhere at 0,1125 Watts. Perhaps the real theoretical value is a bit off – but most real batteries will be a bit off too, so it is a good enough aproximation.</p>
<p>So that is somewhat consistent to our previous calculations to not exceed 80mA to avoid a too big voltage drop.</p>
<p>But how many energy can we draw from an CR2032? For this we simply calculate the watt hour of the battery:</p>
<p>e=P*t and t=0,24A/I</p>
<p>so we get</p>
<p>e=(0,24/I)*P</p>
<p>or</p>
<p><a title="CR2032 Energy" href="http://farm3.static.flickr.com/2551/3906720443_32df955d3a_b.jpg"><img class="slickr-post colorbox-441" src="http://farm3.static.flickr.com/2551/3906720443_32df955d3a.jpg" alt="CR2032 Energy" width="500" height="261" /></a></p>
<p>But this is not very astonishing. The less current you draw the less loss you got at the internal resistor. But I am unsure if there is this resistor, which burns energy to heat. But since the batteries get hot if you draw too much power you will get some loss. But I do not think that the loss is equal to a 20 Ohm resistor. But the main finding is clear – the more current you draw the more loss you have.</p>
<h3>What to do?</h3>
<p>From the comments I got the tip to put the lithium coin cells in series to get a higher coltage at the current draw. But this will enlarge the voltage swing at different current levels (from 6V at 0mA to 3V at 150mA). This can be dangerous for your circuit. A better approach would be to put the batteries in parallel to half the internal ESR – so you would still get 1.5 Volts at 150mA.</p>
<p>Of course to counter current spikes you should allways put sufficiently sized capacitors in parallel. Sufficiently sized depends on the level of current spikes and there time. Just check out how a <a href="http://en.wikipedia.org/wiki/Farad">Farad</a> is defined and you can derrive the needed value (which is the product of voltage change and time).</p>
<p>But in most of my designs space is a rare good. So no parallel batteries and no big capacitor banks.</p>
<p>Something that could work is sucking the power with a boost converter to get a steady output voltage independent of the current draw. This would of course enhance the loss but at least we get the voltage we want at an expense of the efficiency. Right now the calculations are a bit too complicated for this evening. But updates will follow</p>
<p>Lets see how that works.</p>


<p>No related posts.</p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/hWXej0kfW1M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2009/08/driving-circuits-from-a-cr2032-lithium-coin-cell/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2009/08/driving-circuits-from-a-cr2032-lithium-coin-cell/</feedburner:origLink></item>
		<item>
		<title>Interactive Matter: The first year!</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/4lt9TUb-rxs/</link>
		<comments>http://interactive-matter.org/2009/08/interactive-matter-the-first-year/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 06:00:07 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Tinkering]]></category>
		<category><![CDATA[HWYDD]]></category>
		<category><![CDATA[Space Invaders]]></category>
		<category><![CDATA[TV-B-Gone]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=416</guid>
		<description><![CDATA[Unbelievable that this is just the first year of Interactive Matter. But still there happened a lot of things.

Lets have a look on what Interactive Matter has managed to achieve.

The Beginning
It all started with the little idea of having a &#8216;time replay device&#8217;. How was your Day Darling was born. It samples the light levels [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Unbelievable that this is just the first year of Interactive Matter. But still there happened a lot of things.</p>
<p><a href="http://interactive-matter.org/2009/07/interactive-matter-goes-kit/"><img class="alignnone colorbox-416" title="Space Invaders goes Kit" src="http://farm3.static.flickr.com/2463/3734747053_e3c7ed47d7_m.jpg" alt="" width="240" height="180" /></a><a href="http://interactive-matter.org/2009/04/space-invaders-button/"><img class="alignnone colorbox-416" title="Space Invaders Button" src="http://farm4.static.flickr.com/3383/3437050307_bdcc51bcc0_m.jpg" alt="" width="240" height="180" /></a><a href="http://interactive-matter.org/2008/10/how-was-your-day-darling/"><img class="alignnone colorbox-416" title="How was your Day Darling?" src="http://farm4.static.flickr.com/3553/3349059009_d3879cdb04_m.jpg" alt="" width="240" height="180" /></a><a href="http://interactive-matter.org/2008/12/gravitron/"><img class="alignnone colorbox-416" title="Gravitron" src="http://farm4.static.flickr.com/3107/3130088565_3b054502b3_m.jpg" alt="" width="240" height="180" /></a></p>
<p>Lets have a look on what Interactive Matter has managed to achieve.</p>
<p><span id="more-416"></span></p>
<h2>The Beginning</h2>
<p>It all started with the little idea of having a &#8216;time replay device&#8217;. <a href="http://interactive-matter.org/2008/10/how-was-your-day-darling/">How was your Day Darling</a> was born. It samples the light levels during the day and if you take in your hand it plays it back.</p>
<p>The first prototype was still a bit rough but functional:</p>
<p><a title="HWYDD: Prototype internals" href="http://farm4.static.flickr.com/3115/2770813216_56d524b014_o.png"><img src="http://farm4.static.flickr.com/3115/2770813216_fe690c0559.jpg" alt="" width="500" height="357" /></a></p>
<p>But soon it evolved in perhaps the nicest PCB I have done yet:</p>
<p><a href="http://farm4.static.flickr.com/3098/2837650398_354ab12346_b.jpg"><img class="slickr-post colorbox-416" src="http://farm4.static.flickr.com/3098/2837650398_354ab12346.jpg" alt="The hwydd board" width="500" height="357" /></a></p>
<p>The final &#8216;<a href="http://interactive-matter.org/2008/10/how-was-your-day-darling/">How was your Day Darling</a>&#8216; was nice, but till a bit week. I think this is a project I have to come back to.</p>
<h2><a href="http://interactive-matter.org/2008/12/gravitron/">Gravitron</a></h2>
<p>After the first success of How was your day darling I did something very dumb. After some beers I promised to create some Cylon/KITT like device in half a ping pong ball. Of course the concept got completely out of hand. After thinking how to switch it on I realized that the &#8216;easiest&#8217; would be to include an accelerometer and detect motion. But if you have a accelerometer in it you can also play around with gravity, implement some minimalistic physics engine and implement a &#8216;air bubble&#8217; with LEDs:</p>
<p><!-- Smart Youtube --><span class="youtube"><object width="500" height="370"><param name="movie" value="http://www.youtube.com/v/m31_mkeNV3g&amp;rel=0&amp;color1=006699&amp;color2=54abd6&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="http://www.youtube.com/v/m31_mkeNV3g&amp;rel=0&amp;color1=006699&amp;color2=54abd6&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" type="application/x-shockwave-flash" allowfullscreen="true" width="500" height="370" ></embed><param name="wmode" value="transparent" /></object></span></p>
<p>The original KITT-like animation was just used to indicate that the device is going to sleep. But this design ultimately got me to SMT. First of all it was hard to solder the ADXL accelerometer. So I bought an hot air rework station. And after that I was able to solder nearly any SMT device. Which is way cool.</p>
<h2>Long Term Goal: <a href="http://interactive-matter.org/2009/04/space-invaders-button/">Space Invaders Button</a></h2>
<p>The idea for my Space Invaders Button is very old. I existed before I started with all this electronics stuff. I promised a friend of mine to get here some button for her jacket, displaying space invaders characters. I thought that it cannot be that easy. In the end it was more complicated than I thought- but at the end I was able to achieve it:</p>
<p><a href="http://farm4.static.flickr.com/3383/3437050307_bdcc51bcc0_b.jpg"><img src="http://farm4.static.flickr.com/3383/3437050307_bdcc51bcc0.jpg" alt="" width="500" height="375" /></a></p>
<p>It was a great success, I must admit. People love it so much that I am currently working on a kit. So stay tuned and see what will be coming along. This design has still a lot of potential. It should be still able to use the LEDs as inputs (e.g. to detect touch or ambient light level). And there could also be some easier way to download custom animations on it. Another design which I have to revisit if I got some time.</p>
<h2><a href="http://interactive-matter.org/2009/07/%c2%b5tvbg-tv-b-gone-clone/">µTVBG</a></h2>
<p>The µTVBG was just some kind of SMT exercise. I questioned myself how small can you go tu build an TV-B-Gone clone. Ther result was quite nice. A working TV-B-Gone on approximate 2cm²:</p>
<p><a title="µTVBG" href="http://farm4.static.flickr.com/3554/3687153902_162fe47fde_b.jpg"><img src="http://farm4.static.flickr.com/3554/3687153902_162fe47fde.jpg" alt="ÂµTVBG" width="500" height="400" /></a></p>
<p>Surely you will be able to make it smaller. Lets see how this evolves.</p>
<h2>Whats coming up?</h2>
<p>There are still a lot of projects in the pipeline. They rank from funny simple pranks to full scale product ideas. Of course all of them are in a much to early state to talk about. But stay tuned. They will be coming.</p>
<p>Another big issue right now is creating kits. Interactive Matter will offer solder-yourself SMT kits for all skill levels. But this topics needs some time too to evolve.</p>


<p>Related posts:<ul><li><a href='http://interactive-matter.org/2009/07/interactive-matter-goes-kit/' rel='bookmark' title='Permanent Link: Interactive Matter goes Kit'>Interactive Matter goes Kit</a></li>
</ul></p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/4lt9TUb-rxs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2009/08/interactive-matter-the-first-year/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2009/08/interactive-matter-the-first-year/</feedburner:origLink></item>
		<item>
		<title>Arduino &amp; AD7746</title>
		<link>http://feedproxy.google.com/~r/interactive-matter/~3/En-F070dnPE/</link>
		<comments>http://interactive-matter.org/2009/07/arduino-ad7746/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 16:14:00 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Sensors]]></category>
		<category><![CDATA[Tinkering]]></category>
		<category><![CDATA[AD7746]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Capacity Sensor]]></category>
		<category><![CDATA[I2C]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Sparkfun]]></category>
		<category><![CDATA[Touch Sensor]]></category>

		<guid isPermaLink="false">http://interactive-matter.org/?p=274</guid>
		<description><![CDATA[In my ongoing series about cool sensors Interactive Matter presents the AD7746 capacity sensor:

What is a capacity sensor good for? You can of course make a device to identify small capacitance (up to 4pF) but that&#8217;s boring. Much more interesting is how it reacts to touching.
Read on how to connect it to the Arduino and [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>In my ongoing series about cool sensors <em>Interactive Matter</em> presents the <a href="http://www.analog.com/en/analog-to-digital-converters/capacitance-to-digital-converters/AD7746/products/product.html">AD7746 capacity sensor</a>:</p>
<p><a title="Arduino &amp; AD7746" href="http://farm3.static.flickr.com/2458/3600509491_56845934a9_b.jpg"><img class="slickr-post colorbox-274" src="http://farm3.static.flickr.com/2458/3600509491_56845934a9.jpg" alt="Arduino &amp; AD7746" width="500" height="375" /></a></p>
<p>What is a capacity sensor good for? You can of course make a device to identify small capacitance (up to 4pF) but that&#8217;s boring. Much more interesting is how it reacts to touching.</p>
<p>Read on how to connect it to the Arduino and how to use it to sense touching</p>
<p><span id="more-274"></span></p>
<p>Fortunately there is a basic sketch how to use an <a href="http://www.interaccess.org/blog/?p=1886&amp;cpage=1">AD7746 with Arduino</a>. Unfortunately this sketch has one or two awkward structures and inconsistencies. Much more unfortunately it somehow works. So lets clean this thing a bit up.</p>
<h3>I2C Basics</h3>
<p>The <a href="http://www.arduino.cc/playground/Learning/I2C">I2C on Arduino</a> uses analog pin 4 as SDA and analog pin 5 as SCL . With the <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=7918">Sparkfun AD7746 breakout board</a> you need some pull up resistors for the I2C lines – So I added some 4.7k resistors to VCC (forgetting the pull up resistors is the most common source for an I2C connection not working – at least for me).</p>
<h3>Connecting AD7746 to Arduino</h3>
<p>The Sparkfun Ad7746 breakout board comes with two long lines to direct the sensing away from the logic and some &#8216;touch plate&#8217;. As you can see in the above photo you just connect the I2C pins, GND and VCC. Despite the marking &#8216;<em>3.3V</em>&#8216; on the breakout board the AD7746 accepts up to 5Volt as input voltage. So no special 3.3V voltage supply is needed.</p>
<p>The software part was a little more tricky. I used the <a href="http://www.interaccess.org/blog/?p=1886&amp;cpage=1">AD7746 Arduino sketch</a> I found and refactored it a bit. First of all I used my convenience extensions to read and write I2C registers conveniently (download the whole sketch – it is far too long to list here). Next we define our ADD7746 registers for convenience reasons:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &amp;lt;Wire.h&amp;gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//AD7746 definitions</span>
<span style="color: #339933;">#define I2C_ADDRESS  0x48 //0x90 shift one to the right</span>
&nbsp;
<span style="color: #339933;">#define REGISTER_STATUS 0x00</span>
<span style="color: #339933;">#define REGISTER_CAP_DATA 0x01</span>
<span style="color: #339933;">#define REGISTER_VT_DATA 0x04</span>
<span style="color: #339933;">#define REGISTER_CAP_SETUP 0x07</span>
<span style="color: #339933;">#define REGISTER_VT_SETUP 0x08</span>
<span style="color: #339933;">#define REGISTER_EXC_SETUP 0x09</span>
<span style="color: #339933;">#define REGISTER_CONFIGURATION 0x0A</span>
<span style="color: #339933;">#define REGISTER_CAP_DAC_A 0x0B</span>
<span style="color: #339933;">#define REGISTER_CAP_OFFSET 0x0D</span>
<span style="color: #339933;">#define REGISTER_CAP_GAIN 0x0F</span>
<span style="color: #339933;">#define REGISTER_VOLTAGE_GAIN 0x11</span>
&nbsp;
<span style="color: #339933;">#define RESET_ADDRESS 0xBF</span>
&nbsp;
<span style="color: #339933;">#define CAP_ZERO 0x800000L</span></pre></div></div>

<p>Now we can write a little startup routine to initialize the AD7746. It performs a reset (you never know), enables uses channel 1 for measuring capacitance and tries to calibrate the AD7746:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><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>
  <span style="color: #009900;">&#91;</span>…<span style="color: #009900;">&#93;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Initializing&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  Wire.<span style="color: #202020;">beginTransmission</span><span style="color: #009900;">&#40;</span>I2C_ADDRESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// start i2c cycle</span>
  Wire.<span style="color: #202020;">send</span><span style="color: #009900;">&#40;</span>RESET_ADDRESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// reset the device</span>
  Wire.<span style="color: #202020;">endTransmission</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ends i2c cycle</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//wait a tad for reboot</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  writeRegister<span style="color: #009900;">&#40;</span>REGISTER_EXC_SETUP<span style="color: #339933;">,</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// EXC source A</span>
&nbsp;
  writeRegister<span style="color: #009900;">&#40;</span>REGISTER_CAP_SETUP<span style="color: #339933;">,</span>_BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// cap setup reg - cap enabled</span>
&nbsp;
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Getting offset&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  offset <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span>readInteger<span style="color: #009900;">&#40;</span>REGISTER_CAP_OFFSET<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Factory offset: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>offset<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  writeRegister<span style="color: #009900;">&#40;</span><span style="color: #208080;">0x0A</span><span style="color: #339933;">,</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// set configuration to calib. mode, slow sample</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//wait for calibration</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  displayStatus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Calibrated offset: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  offset <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span>readInteger<span style="color: #009900;">&#40;</span>REGISTER_CAP_OFFSET<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>offset<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#91;</span>…<span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The calibration is a bit more tricky, later more on that. First we have to get an readout of the sensor:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">long</span> readValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #993333;">long</span> ret <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
 uint8_t data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #993333;">char</span> status <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">//wait until a conversion is done</span>
 <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>status <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>_BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 status<span style="color: #339933;">=</span> readRegister<span style="color: #009900;">&#40;</span>REGISTER_STATUS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> value <span style="color: #339933;">=</span>  readLong<span style="color: #009900;">&#40;</span>REGISTER_CAP_DATA<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 value <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;=</span><span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">//we have read one byte to much, now we have to get rid of it</span>
 ret <span style="color: #339933;">=</span>  value<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It waits until an measurement has finished an reads the data value from the data register. The read routine returns a 32 bit long value. We just need the first three bytes, so we shift it one byte to the left. The datasheet specifies 0&#215;800000 as null point, so we should subtract this value from readout. This was omitted here, since the datasheet also say that the value in REGISTER_CAP_OFFSET contains the real zero point after an calibration. So we just give back the value of REGISTER_CAP_OFFSET as offset. The content of REGISTER_CAP_OFFSET can be used in the external program logic (later more on that).</p>
<p>The AD7746 is not very nice to read from. The datasheet says, that you can write an address and then read as many bytes from the chip as you like. But not if you sent a STOP after you have written the address. But this is exactly what the Wire library does. So the readout routine (e.g. for Long values) looks a bit nasty since the address pointer is set back to 0:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> readLong<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">union</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> value<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  byteMappedLong<span style="color: #339933;">;</span>
&nbsp;
  byteMappedLong.<span style="color: #202020;">value</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0L</span><span style="color: #339933;">;</span>
&nbsp;
  Wire.<span style="color: #202020;">beginTransmission</span><span style="color: #009900;">&#40;</span>I2C_ADDRESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// begin read cycle</span>
  Wire.<span style="color: #202020;">send</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//pointer to first data register</span>
  Wire.<span style="color: #202020;">endTransmission</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// end cycle</span>
  <span style="color: #666666; font-style: italic;">//the data pointer is reset anyway - so read from 0 on</span>
&nbsp;
  Wire.<span style="color: #202020;">requestFrom</span><span style="color: #009900;">&#40;</span>I2C_ADDRESS<span style="color: #339933;">,</span>r<span style="color: #339933;">+</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// reads 2 bytes plus all bytes before the register</span>
&nbsp;
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Wire.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>r<span style="color: #339933;">+</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//wait</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span>r<span style="color: #339933;">+</span><span style="color: #0000dd;">3</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    uint8_t c <span style="color: #339933;">=</span> Wire.<span style="color: #202020;">receive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      byteMappedLong.<span style="color: #202020;">data</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span> c<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> byteMappedLong.<span style="color: #202020;">value</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now that we are getting some real values we can try to calibrate the chip. It comes factory calibrated, which is reset after each reset. First of all we try to perform an built in calibration:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> calibrate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  calibration <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Calibrating CapDAC A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #993333;">long</span> value <span style="color: #339933;">=</span> readValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>value<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>VALUE_UPPER_BOUND <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> calibration <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">128</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    calibration<span style="color: #339933;">++;</span>
    writeRegister<span style="color: #009900;">&#40;</span>REGISTER_CAP_DAC_A<span style="color: #339933;">,</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> calibration<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    value <span style="color: #339933;">=</span> readValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;done&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>After this i done we just switch over to continuous read mode, read out a value, print it with all calibration settings to the serial port:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">  writeRegister<span style="color: #009900;">&#40;</span>REGISTER_CAP_SETUP<span style="color: #339933;">,</span>_BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// cap setup reg - cap enabled</span>
&nbsp;
  writeRegister<span style="color: #009900;">&#40;</span>REGISTER_EXC_SETUP<span style="color: #339933;">,</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// EXC source A</span>
&nbsp;
  writeRegister<span style="color: #009900;">&#40;</span>REGISTER_CONFIGURATION<span style="color: #339933;">,</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> _BV<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// continuous mode</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// main program begins</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #009900;">&#91;</span>…<span style="color: #009900;">&#93;</span>
&nbsp;
  <span style="color: #993333;">long</span> value <span style="color: #339933;">=</span> readValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>offset<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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><span style="color: #339933;">;</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>calibration<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>valueVALUE_UPPER_BOUND<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    outOfRangeCount<span style="color: #339933;">++;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>outOfRangeCount<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>MAX_OUT_OF_RANGE_COUNT<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> VALUE_LOWER_BOUND<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      calibrate<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>CALIBRATION_INCREASE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      calibrate<span style="color: #009900;">&#40;</span>CALIBRATION_INCREASE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    outOfRangeCount<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The whole sketch contains a bit more code and can be much better understood if you got all the code – but that would be too much code for this post. So download the whole <a href="http://interactive-matter.org/wp-content/uploads/2009/07/AD7746.zip">Arduino AD7746 Sketch</a> and try it yourself.</p>
<h3>Displaying the results</h3>
<p>The results are displayed with an simple processing sketch, mimicking some kind of cheapo oscilloscope. It reads the values from the serial port and displays them. Anybody interested in the details of the sketch can download the whole <a href="http://interactive-matter.org/wp-content/uploads/2009/07/adjd7746-processing.zip">AD7746 processing sketch</a>.</p>
<p>The formula used to calculate the real capacitance is derrived by th datasheet:</p>
<pre>capacitance = (value-calibration) * 2.44e-07-capdac*0.164;</pre>
<p>I do not know if it completely perfect, but it gives some useful values, interestingly always smaller than 0 – despite the fact that the sensor should be calibrated to 0. For getting absolute capacitance readouts I suggest quadruple checking this to the datasheet and trying to optimize the adjustment of the sensor.</p>
<p>Leaving the sensor alone leads to some graphics like this:</p>
<p><a title="AD7746 Screenshot 1" href="http://farm4.static.flickr.com/3423/3732535736_c329e32923_o.png"><img class="slickr-post colorbox-274" src="http://farm4.static.flickr.com/3423/3732535736_41a5454e04.jpg" alt="AD7746 Screenshot 1" width="500" height="250" /></a></p>
<p>As you can see we there is some noise present, we could filter out, but for now we live with it. It is not very strong. Especially if you compare it with the next graph.</p>
<p>If you tap on the sensing wires it gets a very strong readout &#8211; just by touching the two fine lines on the board:</p>
<p><a title="AD7746 Screenshot 4" href="http://farm4.static.flickr.com/3419/3731737831_001af444b9_o.png"><img class="slickr-post colorbox-274" src="http://farm4.static.flickr.com/3419/3731737831_fa7e23c952.jpg" alt="AD7746 Screenshot 4" width="500" height="250" /></a></p>
<p>This gives a much stronger readout (you can still see the noise &#8211; but that is very easy to distinct from the &#8217;signal&#8217;). This should be very easy to detect. If you look closer you will see that the readout does not really get back to the values just before touching the wires &#8211; It will go down slowly. So for detecting a signal it should be fairly easy to just compare the difference between two readouts and if it is bigger than some threshold it will interpreted as a &#8216;touch&#8217;.</p>
<p>If you use the touch pad, which comes with the AD7746 breakout board and touch the bare metal you get readout which is extremely strong &#8211; but that seems impractical because you would probably never you would never expose such big pads on your design, without some kind of coating.</p>
<p><a title="AD7746 Screenshot 5" href="http://farm4.static.flickr.com/3418/3731737927_240a8d61be_o.png"><img class="slickr-post colorbox-274" src="http://farm4.static.flickr.com/3418/3731737927_130f770797.jpg" alt="AD7746 Screenshot 5" width="500" height="250" /></a></p>
<p>But if you lay a cover of paper over the sensor you get still an extremely sharp signal:</p>
<p><a title="AD7746 Screenshot 6" href="http://farm4.static.flickr.com/3117/3732574394_7d58a07190_o.png"><img class="slickr-post colorbox-274" src="http://farm4.static.flickr.com/3117/3732574394_f7acb08325.jpg" alt="AD7746 Screenshot 6" width="500" height="250" /></a></p>
<h2>The Bottom Line</h2>
<p>In the end you see that the AD7746 is very interesting for creating some kind of hidden input elements. But it is some dificult part. The read routines are not really compatible with the wire library. Combing all the different possibilities to adjust the sensor and the complexity of calculationg the real value (the datasheet is a bit hard to understand on that topic) makes it very difficutl to tune the sensor optimally. But I hope that this material gives enough hints to use this sensor for a project. But nevertheless there are perhaps easier capacitive input sensors out there.</p>


<p>Related posts:<ul><li><a href='http://interactive-matter.org/2009/02/arduino-lis302dl/' rel='bookmark' title='Permanent Link: Arduino &#038; LIS302DL'>Arduino &#038; LIS302DL</a></li>
<li><a href='http://interactive-matter.org/2009/12/arduino-barometric-pressure-sensor-bmp085/' rel='bookmark' title='Permanent Link: Arduino &#038; Barometric Pressure Sensor BMP085'>Arduino &#038; Barometric Pressure Sensor BMP085</a></li>
<li><a href='http://interactive-matter.org/2008/08/tinkering-with-adjd-s371-q999/' rel='bookmark' title='Permanent Link: Tinkering with ADJD-S371-Q999'>Tinkering with ADJD-S371-Q999</a></li>
</ul></p><img src="http://feeds.feedburner.com/~r/interactive-matter/~4/En-F070dnPE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://interactive-matter.org/2009/07/arduino-ad7746/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://interactive-matter.org/2009/07/arduino-ad7746/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 2.784 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-03-12 04:06:46 -->
