<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>(Baltimore) Harford Hackerspace &#187; Tutorials</title>
	<atom:link href="http://baltimorehackerspace.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://baltimorehackerspace.com</link>
	<description>Maryland Electronics, Software, Science and Robotics Club</description>
	<lastBuildDate>Tue, 24 Jan 2012 20:46:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sequence Animoog on your iPad from your PC with Fruity Loops over WIFI</title>
		<link>http://baltimorehackerspace.com/2011/11/sequence-animoog-on-your-ipad-from-your-pc-with-fruity-loops-over-wifi/</link>
		<comments>http://baltimorehackerspace.com/2011/11/sequence-animoog-on-your-ipad-from-your-pc-with-fruity-loops-over-wifi/#comments</comments>
		<pubDate>Sun, 06 Nov 2011 01:34:16 +0000</pubDate>
		<dc:creator>superfro</dc:creator>
				<category><![CDATA[How-Tos]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://harfordhackerspace.org/?p=1654</guid>
		<description><![CDATA[Just playing around with the iPad app Animoog, which I believe is still available for $0.99 at the iTunes app store. This is a huge bargain on a really really cool app.  I won&#8217;t get into the specifics of the app, but if you want to know more about what Animoog is or how to use [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://harfordhackerspace.org/wp-content/uploads/2011/11/animoog.jpg"><img class="alignleft size-medium wp-image-1655" style="margin: 10px;" title="animoog screenshot" src="http://harfordhackerspace.org/wp-content/uploads/2011/11/animoog-300x225.jpg" alt="animoog screenshot" width="300" height="225" /></a>Just playing around with the iPad app <a title="moog app" href="http://www.moogmusic.com/products/apps/animoog" target="_blank">Animoog</a>, which I believe is still available for $0.99 at the <a href="http://itunes.apple.com/us/app/animoog/id471638724?mt=8" target="_blank">iTunes app store</a>. This is a huge bargain on a really really cool app.  I won&#8217;t get into the specifics of the app, but if you want to know more about what Animoog is or how to use it, I recommend this <a href="http://www.youtube.com/watch?v=qOLIJnW4llQ" target="_blank">YouTube video</a>.</p>
<p>So, while playing around with the Animoog app, if you go into the setup menu there is a selection under &#8216;Refresh MIDI input(s)&#8217; where  you can select &#8216;Off&#8217; or &#8216;Network Session 1&#8242;.  This intrigued me!  Apparently you can use MIDI over the &#8216;Network&#8217;.  After some Googling I was still unclear on how to get this setup, so I thought I&#8217;d just tell everyone how I did it so you can get to making some cool tunes yourself.</p>
<p><span id="more-1654"></span></p>
<p><a href="http://harfordhackerspace.org/wp-content/uploads/2011/11/rtp1.jpg"><img class="alignleft size-medium wp-image-1657" style="margin: 10px;" title="rtp1" src="http://harfordhackerspace.org/wp-content/uploads/2011/11/rtp1-300x234.jpg" alt="" width="300" height="234" /></a>I&#8217;m assuming your PC has iTunes installed and you have the Bonjour service that comes with it.  It should work without it but you lose the auto-discovery.  OK, so first thing you&#8217;re going to need is the Animoog app on your iPad.  Once that is installed, you&#8217;re going to need <a href="http://www.tobias-erichsen.de/rtpMIDI.html" target="_blank">rtpMIDI </a>which is available for free <a href="http://www.tobias-erichsen.de/rtpMIDI.html" target="_blank">here</a>.  (Download link on the top right).  I&#8217;m using Windows 7 64 bit for reference.  Once you download the rtpMIDI, unzip it and execute the .msi file to install it.  There is a better tutorial for installing rtpMIDI <a href="http://www.tobias-erichsen.de/rtpMIDI_configuration.html" target="_blank">here </a>so I won&#8217;t re-iterate everything.  The TL;DR version is Install, click Next, Next, Next, agree to anything that pops up, and done.</p>
<p><a href="http://harfordhackerspace.org/wp-content/uploads/2011/11/rtp2.jpg"><img class="alignleft size-medium wp-image-1658" style="margin: 10px;" title="rtp2" src="http://harfordhackerspace.org/wp-content/uploads/2011/11/rtp2-300x192.jpg" alt="" width="300" height="192" /></a><a href="http://harfordhackerspace.org/wp-content/uploads/2011/11/rtp3.jpg"><img class="size-medium wp-image-1659 alignleft" style="margin: 10px;" title="rtp3" src="http://harfordhackerspace.org/wp-content/uploads/2011/11/rtp3-300x192.jpg" alt="" width="300" height="192" /></a><br />
After the rtpMIDI is installed, run rtpMIDI from the start menu.  Click the + under &#8216;My Sessions&#8217; and choose a new name or leave it as default.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Next highlight the (only) session and click the enable box on the right.  Now at this point Bonjour probably hasn&#8217;t caught up with you yet to display your iPad in the Directory box like mine.  If it does, click connect.  If it doesn&#8217;t click the + under Directory and type in the IP address of your iPad followed by :5004.  eg.  &#8217;192.168.5.104:5004&#8242; which is the case with mine.  You can get the WIFI IP address of your iPad by going to Settings -&gt;General-&gt;Network-&gt;Wi-Fi-&gt;(Your Wi-Fi access point&#8217;s name) and you&#8217;ll see &#8216;IP Address&#8217;.  It&#8217;s usually something like 192.168.1.100 or so.</p>
<p>After adding an item in the Directory, highlight it and click connect.  If successfull it should show up in the &#8216;Participants window&#8217;.  Leave this application running.</p>
<p>OK, still with me?  Good.  Next, run Animoog, click on the top right where it says &#8216;Settings&#8217;, then on the left under &#8216;Refresh MIDI input(s)&#8217; select &#8216;Network Session 1&#8242;.</p>
<p>At this point I&#8217;m going to presume that most software that uses MIDI output on  your PC will work, however I did not try them.  I&#8217;m going to use <a href="http://flstudio.image-line.com/" target="_blank">Fruity Loops Studio 9</a>.</p>
<p><a href="http://harfordhackerspace.org/wp-content/uploads/2011/11/fl1.jpg"><img class="alignleft size-medium wp-image-1660" style="margin: 10px;" title="fl1" src="http://harfordhackerspace.org/wp-content/uploads/2011/11/fl1-300x168.jpg" alt="" width="300" height="168" /></a>Once you fire up Fruity Loops, start with a fresh setup.  Goto Options-&gt;MIDI settings.  On the top you should see something similar to my screenshot.  The name of your &#8216;Session&#8217; you used in rtpMIDI.  Highlight that MIDI Device, click Send Master Sync (so you can control BPM from FLStudio) and set the Port Number to 0.  Close this dialog.</p>
<p>&nbsp;</p>
<p><a href="http://harfordhackerspace.org/wp-content/uploads/2011/11/fl2.jpg"><img class="alignleft size-medium wp-image-1661" style="margin: 10px;" title="fl2" src="http://harfordhackerspace.org/wp-content/uploads/2011/11/fl2-300x293.jpg" alt="" width="300" height="293" /></a></p>
<p><a href="http://harfordhackerspace.org/wp-content/uploads/2011/11/fl3.jpg"><img class="size-medium wp-image-1662 alignleft" style="margin: 10px;" title="fl3" src="http://harfordhackerspace.org/wp-content/uploads/2011/11/fl3-236x300.jpg" alt="" width="236" height="300" /></a></p>
<p>Next, goto Channels-&gt;Add one-&gt;MIDI out.  On the channel settings, make sure you set the Channel to &#8217;1&#8242; and the Port to &#8217;0&#8242;.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>At this point you should be able to click the little virtual keyboard and hear it play on your iPad.</p>
<p>If this works, then you are all set up.  If not then either you missed a step or I forgot to mention the step (hah!).</p>
<p>You can start making your patterns with notes and hear them play back on the iPad.  You still have to setup your preset in Animoog on the iPad, and it doesn&#8217;t appear that all the functionality is supported.  Some notes don&#8217;t appear to work (things like pitch, etc.)  I presume if you had multiple iPads you could set them all up with different presets and make some really killer music.</p>
<p>&nbsp;</p>
<p>And here is a quick little YouTube video showing it working.</p>
<p><iframe src="http://www.youtube.com/embed/9dEe1GYUJac" frameborder="0" width="560" height="315"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://baltimorehackerspace.com/2011/11/sequence-animoog-on-your-ipad-from-your-pc-with-fruity-loops-over-wifi/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Netduino Début with Color Sensor</title>
		<link>http://baltimorehackerspace.com/2010/07/netduino-debut/</link>
		<comments>http://baltimorehackerspace.com/2010/07/netduino-debut/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 17:43:45 +0000</pubDate>
		<dc:creator>Squintz</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Microcontroller]]></category>
		<category><![CDATA[Netduino]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://harfordhackerspace.org/?p=905</guid>
		<description><![CDATA[Netduino Over the last few weeks Harford Hackerspace has had the pleasure of beta testing the Netduino. The Netduino is a development board with a form factor similar to the Arduino. Care was taken when designing the Netduino to ensure compatibility with most of the existing Arduino shields. That&#8217;s about where the similarities of the two devices [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_1020" class="wp-caption alignleft" style="width: 210px"><a href="http://harfordhackerspace.org/wp-content/uploads/2010/07/CW0001_3.jpg"><img src="http://harfordhackerspace.org/wp-content/uploads/2010/07/CW0001_3-300x218.jpg" alt="Netduino" title="Netduino" width="200" height="118" class="size-medium wp-image-1020" /></a><p class="wp-caption-text">Netduino</p></div><strong>Netduino</strong></p>
<p>Over the last few weeks Harford Hackerspace has had the pleasure of beta testing the <a title="Netduino" href="http://www.netduino.com" target="_blank">Netduino</a>. The Netduino is a development board with a form factor similar to the <a title="Arduino" href="http://www.arduino.cc/" target="_blank">Arduino</a>. Care was taken when designing the Netduino to ensure compatibility with most of the existing Arduino shields. That&#8217;s about where the similarities of the two devices ends.</p>
<p>The Netduino uses Microsoft&#8217;s Open Source .net Micro Framework SDK along with Visual Studio C# (or VS C# Express) as the primary development environment. C# application developers will be able to quickly adapt to the .net Micro Framework and start programming microcontrollers in a matter of minutes. However, this does not let them off the hook for learning the basics of electronics.<br />
<span id="more-905"></span><br />
After downloading and installing <a title="Visual Studio Express" href="http://www.microsoft.com/express/Windows/" target="_blank">Visual Studio C# Express 2010</a>, the <a title=".net Microframework 4.1 SDK" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=cff5a7b7-c21c-4127-ac65-5516384da3a0&amp;displayLang=en" target="_blank">.net Micro Framework 4.1 SDK</a> , and the Secret Labs Netduino SDK we started with the &#8220;Hello World&#8221; of microcontrollers and blinked the on-board LED. That was easy&#8230;! You&#8217;ll be able to get details to do this yourself from the Netduino website.</p>
<p><strong>SparkFun Color Sensor</strong><br />
<div id="attachment_909" class="wp-caption alignright" style="width: 247px"><a href="http://harfordhackerspace.org/wp-content/uploads/2010/07/08663-04-L.jpg"><img src="http://harfordhackerspace.org/wp-content/uploads/2010/07/08663-04-L-300x300.jpg" alt="Sparkfun Color Sensor" title="Sparkfun Color Sensor" width="227" height="227" class="size-medium wp-image-909" /></a><p class="wp-caption-text">ADJD-S371-Q999</p></div><br />
I purchased the ADJD-S371 color sensor(right) from SparkFun several months ago with the intention of connecting it to a PIC microcontroller and creating a device that will print the HTML color name (i.e. DarkRed) of an object that it sees. I&#8217;m particularly interested in this project because I happen to be Color Blind. There are several off the shelf products available but where is the fun in that?</p>
<p>The ADJD-S371 is a 4 channel RGB+Clear sensor and uses the 2-wire I2C protocol to communicate with the microcontroller.  It&#8217;s a complex little device that will test your puzzle solving skills. What I mean is that the device does not simply give you the correct color when you ask for it. You&#8217;ll have to play around with the Gain calibration algorithm and come up with something that works best for your application. However, for simple testing purposes you can use the code described in this tutorial. Here&#8217;s a quick video to demonstrate the project:</p>
<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/uprZ1NBShAk&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/uprZ1NBShAk&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="545" height="385"></embed></object></p>
<p>The code was originally created by Nathan Seidle for the PIC microcontroller and was ported and modified for the Arduino by Marcus from <a title="Interactive Matter Tutorial" href="http://interactive-matter.org/2008/08/tinkering-with-adjd-s371-q999/" target="_blank">Interactive Matter</a>. Paul King and I ported it once again to the C# Language for the .net Micro Framework.</p>
<p><div id="attachment_1076" class="wp-caption alignright" style="width: 310px"><a href="http://harfordhackerspace.org/wp-content/uploads/2010/07/Colorimeter_Schematic_Image1.png"><img src="http://harfordhackerspace.org/wp-content/uploads/2010/07/Colorimeter_Schematic_Image1-300x204.png" alt="Colorimeter Schematic" title="Colorimeter Schematic" width="300" height="204" class="size-medium wp-image-1076" /></a><p class="wp-caption-text">Click to Enlarge</p></div>The schematic to the right shows how we hooked up the Netduino. There are a few things to note. First, we are using an external LED for our light source so there is no need to connect the LED pin on the ADJD-S371-Q999. Also, note that we skip a pin when we hooked up the RGB LED. This is because our protoshield was broke and that pin was not working. You can use any of the Digital IO Pins. You just need to change a little code when setting up the Output Ports. Finally, the RGB LED could be hooked to 3.3v or 5v. You may need to adjust the resistor sizes for your RGB LED anyways.</p>
<p><strong>C# Code</strong></p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO.Ports</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Threading</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.SPOT</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.SPOT.Hardware</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">SecretLabs.NETMF.Hardware.Netduino</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>Lines 1 through 6 define a namespace. This allows you to use classes or types without having to type out the full namespace where those types exist. For example, instead of typing:<br />
<code class="codecolorer csharp default"><span class="csharp">SecretLabs<span style="color: #008000;">.</span><span style="color: #0000FF;">NETMF</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Hardware</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Netduino</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Pins</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ONBOARD_LED</span></span></code><br />
We can simply type:<br />
<code class="codecolorer csharp default"><span class="csharp">Pins<span style="color: #008000;">.</span><span style="color: #0000FF;">ONBOARD_LED</span></span></code></p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">namespace</span> Squintz<span style="color: #008000;">.</span><span style="color: #0000FF;">Colorimeter</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Program<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> I2C_ADDRESS <span style="color: #008000;">=</span> 0x74<span style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// 7bit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_CAP_RED &nbsp; &nbsp; &nbsp;<span style="color: #008000;">=</span>0x06<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_CAP_GREEN &nbsp; &nbsp;<span style="color: #008000;">=</span>0x07<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_CAP_BLUE &nbsp; &nbsp; <span style="color: #008000;">=</span>0x08<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_CAP_CLEAR &nbsp; &nbsp;<span style="color: #008000;">=</span>0x09<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_INT_RED_LO &nbsp; <span style="color: #008000;">=</span>0x0A<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_INT_RED_HI &nbsp; <span style="color: #008000;">=</span>0x0B<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_INT_GREEN_LO <span style="color: #008000;">=</span>0x0C<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_INT_GREEN_HI <span style="color: #008000;">=</span>0x0D<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_INT_BLUE_LO &nbsp;<span style="color: #008000;">=</span>0x0E<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_INT_BLUE_HI &nbsp;<span style="color: #008000;">=</span>0x0F<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_INT_CLEAR_LO <span style="color: #008000;">=</span>0x10<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_INT_CLEAR_HI <span style="color: #008000;">=</span>0x11<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_DATA_RED_LO &nbsp;<span style="color: #008000;">=</span>0x40<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_DATA_RED_HI &nbsp;<span style="color: #008000;">=</span>0x41<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_DATA_GREEN_LO<span style="color: #008000;">=</span>0x42<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_DATA_GREEN_HI<span style="color: #008000;">=</span>0x43<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_DATA_BLUE_LO <span style="color: #008000;">=</span>0x44<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_DATA_BLUE_HI <span style="color: #008000;">=</span>0x45<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_DATA_CLEAR_LO<span style="color: #008000;">=</span>0x46<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> REG_DATA_CLEAR_HI<span style="color: #008000;">=</span>0x47<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> I2CDevice rtc <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> I2CDevice<span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> I2CDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Configuration</span><span style="color: #008000;">&#40;</span>I2C_ADDRESS, <span style="color: #FF0000;">100</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> readBuffer <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>Lines 7 through 33 are constants defined in the Color Sensors documentation. Line 35 creates a new I<sup>2</sup>C device object named rtc. We use this object to actually send the data from the Netduino to the Color Sensor. I<sup>2</sup>C is a bus protocol which means that multiple devices can share the same wires. So the I2CDevice object requires us to give it a slave address. We defined this as the constant I2C_Address on line 11. The I2CDevice object also requires us to specify a rate in Kilohertz(Khz). 100Khz seemed to do that trick. We tried other speeds without much luck.</p>
<p>Line 37 creates a variable of type byte array. Note that we are only initializing the size of the array to 1. The color  sensor does not actually need an array of bytes but the I2CDevice.CreateReadTransaction requires a byte array as one of its parameters and does not have an overloaded method for using just a byte.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputPort redpin <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> OutputPort<span style="color: #008000;">&#40;</span>Pins<span style="color: #008000;">.</span><span style="color: #0000FF;">GPIO_PIN_D10</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputPort greenpin <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> OutputPort<span style="color: #008000;">&#40;</span>Pins<span style="color: #008000;">.</span><span style="color: #0000FF;">GPIO_PIN_D9</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputPort bluepin <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> OutputPort<span style="color: #008000;">&#40;</span>Pins<span style="color: #008000;">.</span><span style="color: #0000FF;">GPIO_PIN_D7</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> cc <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> red <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> green <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> blue <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> clearGain<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> colorGain<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> num_samples<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> i<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearGain <span style="color: #008000;">=</span> getClearGain<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_gain<span style="color: #008000;">&#40;</span>REG_INT_CLEAR_LO, clearGain<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; colorGain <span style="color: #008000;">=</span> getColorGain<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_gain<span style="color: #008000;">&#40;</span>REG_INT_RED_LO, colorGain<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_gain<span style="color: #008000;">&#40;</span>REG_INT_GREEN_LO, colorGain<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_gain<span style="color: #008000;">&#40;</span>REG_INT_BLUE_LO, colorGain<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; num_samples <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span>i<span style="color: #008000;">=</span><span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i<span style="color: #008000;">&lt;</span>num_samples <span style="color: #008000;">;</span>i <span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Program<span style="color: #008000;">.</span><span style="color: #0000FF;">performMeasurement</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cc <span style="color: #008000;">+=</span>get_readout<span style="color: #008000;">&#40;</span>REG_DATA_CLEAR_LO<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; red <span style="color: #008000;">+=</span>get_readout<span style="color: #008000;">&#40;</span>REG_DATA_RED_LO<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; green <span style="color: #008000;">+=</span>get_readout<span style="color: #008000;">&#40;</span>REG_DATA_GREEN_LO<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blue <span style="color: #008000;">+=</span>get_readout<span style="color: #008000;">&#40;</span>REG_DATA_BLUE_LO<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cc<span style="color: #008000;">/=</span>num_samples<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; red <span style="color: #008000;">/=</span>num_samples<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; green <span style="color: #008000;">/=</span>num_samples<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blue <span style="color: #008000;">/=</span>num_samples<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; redpin<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; greenpin<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bluepin<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>red <span style="color: #008000;">&gt;</span> green <span style="color: #008000;">&amp;&amp;</span> red <span style="color: #008000;">&gt;</span> blue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; redpin<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>green <span style="color: #008000;">&gt;</span> red <span style="color: #008000;">&amp;&amp;</span> green <span style="color: #008000;">&gt;</span> blue<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; greenpin<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>blue <span style="color: #008000;">&gt;</span> red <span style="color: #008000;">&amp;&amp;</span> blue <span style="color: #008000;">&gt;</span> green<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bluepin<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Debug<span style="color: #008000;">.</span><span style="color: #0000FF;">Print</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;C: &quot;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>cc <span style="color: #008000;">&gt;&gt;</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;R:&quot;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>red <span style="color: #008000;">&gt;&gt;</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;G:&quot;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>green <span style="color: #008000;">&gt;&gt;</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;B:&quot;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>blue <span style="color: #008000;">&gt;&gt;</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">500</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Lines 38 is the main entry point for our program. On lines 40 through 42 we setup 3 pins which we are using to control an RGB LED. By adding the SecretLabs.NETMF.Hardware.Netduino.dll to our list of resources and declaring it with the using statement on line 6 we don&#8217;t have to remember the actual microcontrollers pin numbers. SecretLabs has already looked all this up for us and they allow us to use Pins.xxxxx. You notice that the intellisense aka code complete feature of Visual Studio automatically pops up a context menu allowing you to select from a list of available pins.</p>
<p><span style="color: #1F0000;"><em>[*UPDATE: If you use the SecretLabs SDK Installer you can start a new "Netduino Application" which removes the need for manually adding the dll's to your resource list and also removes the need to manually add the SecretLabs using statements.]</em></span></p>
<p>On line 56 we create an infinite loop so that our program never ends. Without this our program would only run once and then terminate.</p>
<p>Lines 58 through 64 is where you could get creative. The <a href="http://www.sparkfun.com/datasheets/Sensors/Imaging/AV02-0314EN.pdf">color sensors datasheet</a> and <a href="http://www.sparkfun.com/datasheets/Sensors/Imaging/AV02-0359EN.pdf">application note</a> are a little fuzzy on explaining the proper way to calibrate and set the gain of your sensor. However, you <strong>MUST</strong> set the gain for each color before you request the color. If you fail to set the gain then you will get low results. We learned this the hard way. We just could not figure out why we only got numbers from 0 to 3!</p>
<p>Lines 65 through 78 is where we sample the colors through the use of a few helper methods which you&#8217;ll read about below. The key thing to note here is that the more samples you take the more stable your numbers will appear. We are taking 10 samples and adding the results together and dividing by 10 to get the average value. </p>
<p>Lines 80 through 93 is where we set the color of our RGB LED. We are using a very simple algorithm to determine the most dominate color and turning on just that leg of the RGB LED. We experimented with mixing colors but our LED was not diffused enough to mix the colors together. We were able to see the individual colors which did not have a good effect.</p>
<p>On Line 95 we call Debug.Print and output the values to Visual Studios output window. The clear value indicates an overall light intensity which the Red, Green, and Blue values are the intensity as seen through a light filter.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>99<br />100<br />101<br />102<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> performMeasurement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_register<span style="color: #008000;">&#40;</span>0x00,0x01<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// start sensing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now we start getting deep into the color sensors protocol. To tell the color sensor to take a sample we set the register 0&#215;00 to the value of 0&#215;01. The color sensor then takes a sample and stores it.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>103<br />104<br />105<br />106<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> get_readout<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span> readRegister<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> read_register<span style="color: #008000;">&#40;</span>readRegister<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span> read_register<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>readRegister <span style="color: #008000;">+</span> 0x01<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&lt;&lt;</span><span style="color: #FF0000;">8</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The color sensor stores its color values in two 8 bit registers. So. on lines 103 through 106, get_readout() takes the first register as a parameter and assumes the next register is just 1 more address above that register. So we read the value of the first register and then read the value of the second register and then shift the value of the second register 8 bits to the left leaving us with the full 16 bit integer. However, only 10 bits are actually put into the integer because the High registers only return the two least significant bits and the Low register returns 7 Bits.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> set_gain<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span> gainRegister, <span style="color: #6666cc; font-weight: bold;">int</span> gain<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>gain <span style="color: #008000;">&lt;</span><span style="color: #FF0000;">4096</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">byte</span> hi <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>gain <span style="color: #008000;">&gt;&gt;</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">byte</span> lo <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>gain<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_register<span style="color: #008000;">&#40;</span>gainRegister, lo<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_register<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>gainRegister<span style="color: #008000;">+</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>, hi<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Each color has two of its own gain registers. We defined these in our constants in the first few lines. Here we again assume that since we know the register address of the lower register, we can just add 1 to that address to get the higher register address. Then we assign the gain values through the help of set_register().</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> set_register<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span> r, <span style="color: #6666cc; font-weight: bold;">byte</span> v<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rtc<span style="color: #008000;">.</span><span style="color: #0000FF;">Execute</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> I2CDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">I2CTransaction</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I2CDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateWriteTransaction</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span>r, v<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">&#125;</span>, <span style="color: #FF0000;">5000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>set_register is where the magic happens. Here we create a new byte array which contains two values. The first is r for register and the second is v for value. We pass this byte array to a new I2CDevice.CreateWriteTransaction object and then pass that object to the rtc.Execute method. You should recall that rtc is our I2CDevice object which knows about the slave address of our color sensor. So, in a nutshell our set_register function is where we package everything up and send it on its way.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span> read_register<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span> r<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rtc<span style="color: #008000;">.</span><span style="color: #0000FF;">Execute</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> I2CDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">I2CTransaction</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I2CDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateWriteTransaction</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span>r<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I2CDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateReadTransaction</span><span style="color: #008000;">&#40;</span>readBuffer<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span>, <span style="color: #FF0000;">5000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> readBuffer<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>On Lines 127 through 136 we are sending a request for our color values. We pass it &#8216;r&#8217; which is the color we want to read. Remember that this happens twice for each color in order to get the full value. We wait 5000 milliseconds or 5 seconds for the return before we timeout.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> getClearGain<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> gainFound <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> upperBox <span style="color: #008000;">=</span> <span style="color: #FF0000;">4096</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> lowerBox <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> half <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> halfValue<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>gainFound <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; half <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>upperBox <span style="color: #008000;">-</span> lowerBox<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> lowerBox<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//no further halfing possbile</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>half <span style="color: #008000;">==</span> lowerBox<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gainFound <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_gain<span style="color: #008000;">&#40;</span>REG_INT_CLEAR_LO, half<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; performMeasurement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; halfValue <span style="color: #008000;">=</span> get_readout<span style="color: #008000;">&#40;</span>REG_DATA_CLEAR_LO<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>halfValue <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">1000</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; upperBox <span style="color: #008000;">=</span> half<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>halfValue <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1000</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lowerBox <span style="color: #008000;">=</span> half<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gainFound <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> half<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Lines 137 to 174 is where you can again play around to perfect your results. You&#8217;ll need to derive a way to obtain a gain value which compensates for the ambient light and all the other environmental factors which may change the sensitivity. I&#8217;ll be honest. I&#8217;m not too sure what is going on here. You should check out <a title="Interactive Matter Tutorial" href="http://interactive-matter.org/2008/08/tinkering-with-adjd-s371-q999/" target="_blank">Interactive Matter</a> for more information about this method.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> getColorGain<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> gainFound <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> upperBox <span style="color: #008000;">=</span> <span style="color: #FF0000;">4096</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> lowerBox <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> half <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> halfValue<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>gainFound <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; half <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>upperBox <span style="color: #008000;">-</span> lowerBox<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> lowerBox<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//no further halfing possbile</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>half <span style="color: #008000;">==</span> lowerBox<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gainFound <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_gain<span style="color: #008000;">&#40;</span>REG_INT_RED_LO, half<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_gain<span style="color: #008000;">&#40;</span>REG_INT_GREEN_LO, half<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set_gain<span style="color: #008000;">&#40;</span>REG_INT_BLUE_LO, half<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; performMeasurement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; halfValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; halfValue <span style="color: #008000;">=</span> <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Math</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>halfValue, get_readout<span style="color: #008000;">&#40;</span>REG_DATA_RED_LO<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; halfValue <span style="color: #008000;">=</span> <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Math</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>halfValue, get_readout<span style="color: #008000;">&#40;</span>REG_DATA_GREEN_LO<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; halfValue <span style="color: #008000;">=</span> <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Math</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>halfValue, get_readout<span style="color: #008000;">&#40;</span>REG_DATA_BLUE_LO<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>halfValue <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">1000</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; upperBox <span style="color: #008000;">=</span> half<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>halfValue <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1000</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lowerBox <span style="color: #008000;">=</span> half<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gainFound <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> half<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Finally, lines 175 to 220 tries to establish a suitable gain for each color. This will be called 3 times because each color has a different sensitivity. You can get creative here and come up with your own algorithm which suits your specific application. If you had a controlled environment then in theory this would be very simple. Make sure you post back here and let us know if you stumble across a better way to determine the gain values.</p>
]]></content:encoded>
			<wfw:commentRss>http://baltimorehackerspace.com/2010/07/netduino-debut/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using the PICkit 2 : As a Programmer</title>
		<link>http://baltimorehackerspace.com/2010/04/using-the-pickit-2-as-a-programmer/</link>
		<comments>http://baltimorehackerspace.com/2010/04/using-the-pickit-2-as-a-programmer/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 17:11:07 +0000</pubDate>
		<dc:creator>superfro</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Microcontroller]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://harfordhackerspace.org/?p=695</guid>
		<description><![CDATA[Around the space, we have been using the PICkit 2 Debug Express quite a bit lately.  This has allowed us to get pretty cozy with the functions of this handy little programmer and I thought I would share some of these features with you. I&#8217;m sure you&#8217;ve read the previous tutorial &#8216;Programming PIC Microcontrollers in [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_535" class="wp-caption alignright" style="width: 155px"><a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/PICKit2.jpg"><img class="size-full wp-image-535 " style="margin: 10px;" title="PICKit2" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/PICKit2.jpg" alt="PicKit2 Debug Express" width="145" height="145" /></a><p class="wp-caption-text">PicKit2 Debug Express</p></div>
<p>Around the space, we have been using the <a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en023805">PICkit 2 Debug Express</a> quite a bit lately.  This has allowed us to get pretty cozy with the functions of this handy little programmer and I thought I would share some of these features with you.</p>
<p>I&#8217;m sure you&#8217;ve read the previous tutorial &#8216;<a href="http://harfordhackerspace.org/2010/02/programming-pic-microcontrollers-in-c/">Programming PIC Microcontrollers in C</a>&#8216;, if you haven&#8217;t, you should go familiarize yourself with it now.  Continuing on from there, after we have a successful build of a led blinking we can use the PICkit 2 to program our chip via the ICSP header.</p>
<p><span id="more-695"></span></p>
<p>Our Debug Express Kit&#8217;s came with a Demo Board which has a 44 pin PIC16F887 microchip. The microcontroller is connected to a 6 Pin Male header called the ICSP (In-Circuit Serial Programmer) header.  All PIC microcontrollers with the letter &#8220;F&#8221; in their name can be programmed this way, even if you are using a breadboard and wires to make the connections. The &#8220;F&#8221; stands for Flash.  Maybe in a future article we will show you how to construct the ICSP header from the data sheet, but we will just assume you are using the 44 Pin Demo Board for now.</p>
<p><a href="http://harfordhackerspace.org/wp-content/uploads/2010/04/selectprogrammer.png"><img class="alignleft size-medium  wp-image-696" style="margin: 10px;" title="selectprogrammer" src="http://harfordhackerspace.org/wp-content/uploads/2010/04/selectprogrammer-300x249.png" alt="" width="300" height="249" /></a></p>
<p><br class="spacer_" /></p>
<p>You should already have the PICkit 2 connected to your PC via the USB port, so after a successful build of our program, we can program the chip by selecting the &#8216;Programmer&#8217; menu from within MPLAB, and then selecting &#8216;Select Programmer&#8217;, then &#8216;PICkit 2&#8242;.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><a href="http://harfordhackerspace.org/wp-content/uploads/2010/04/connected.png"><img class="size-medium wp-image-698 alignright" style="margin: 10px;" title="connected" src="http://harfordhackerspace.org/wp-content/uploads/2010/04/connected-300x155.png" alt="" width="300" height="155" /></a></p>
<p><br class="spacer_" /></p>
<p>At that point below in the debug window you should see a message such as &#8216;Found PICkit 2 &#8211; Operating System Version 2.32.0 &#8230;&#8217; If you do not, select &#8216;Programmer&#8217; then &#8216;Connect&#8217; from MPLAB.</p>
<p><br class="spacer_" /></p>
<p><a href="http://harfordhackerspace.org/wp-content/uploads/2010/04/program.png"><img class="alignleft size-medium wp-image-725" style="margin: 10px;" title="program" src="http://harfordhackerspace.org/wp-content/uploads/2010/04/program-159x300.png" alt="" width="159" height="300" /></a></p>
<p><br class="spacer_" /></p>
<p>Finally we select &#8216;Programmer&#8217; then &#8216;Program&#8217;, and it should start erasing and programming the chip.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><a href="http://harfordhackerspace.org/wp-content/uploads/2010/04/settings1.png"><img class="alignright size-medium wp-image-737" style="margin: 10px;" title="settings" src="http://harfordhackerspace.org/wp-content/uploads/2010/04/settings1-251x300.png" alt="" width="251" height="300" /></a></p>
<p><br class="spacer_" /></p>
<p>Lastly, one tip that speeds up the programming process is to go to the &#8216;Programmer&#8217; menu and then click &#8216;settings&#8217;. Then check the boxes &#8216;Program after a successful build&#8217; and &#8216;Run after a successful program&#8217;.  Once you do that you can just hit F10 to compile and flash the pic over and over as you make small adjustments to your code.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>In the end, this simple task is actually quite convenient. Being able to program a chip in-circuit, instead of taking the chip out of the socket, putting it in a programmer, programming it, taking it out, putting it back into the other socket, turning on, etc.</p>
<p><br class="spacer_" /></p>
<p>Finally, an often overlooked feature is that the PICkit 2 will power your chip if it doesn&#8217;t detect any voltage, which for me personally is the case before I have a power supply set up.  I wouldn&#8217;t overdue it, you can power small things, led&#8217;s, tiny motors but don&#8217;t try to draw too much current from it.  The maximum power draw is 200-300mA less than the USB port puts out, which in most cases is around 500mA leaving you with 200-300mA.  So don&#8217;t try to overdue it, if you&#8217;ve got a lot of power draw in your circuit, set up your own power source and the PICkit 2 will detect the voltage during program and wont try to power it.</p>
<p><br class="spacer_" /></p>
<p>Happy Hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://baltimorehackerspace.com/2010/04/using-the-pickit-2-as-a-programmer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programming PIC Microcontrollers in C</title>
		<link>http://baltimorehackerspace.com/2010/02/programming-pic-microcontrollers-in-c/</link>
		<comments>http://baltimorehackerspace.com/2010/02/programming-pic-microcontrollers-in-c/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 21:46:18 +0000</pubDate>
		<dc:creator>Squintz</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[CCS]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://harfordhackerspace.org/?p=526</guid>
		<description><![CDATA[Learning to program microcontrollers seems like an impossible task but with the help and support of a Hackerspace you&#8217;ll find that it&#8217;s actually simple to get started. The members of Harford Hackerspace set out to learn by starting at the basics and gradually taking on more difficult applications. The key to our quick success was group [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/pic16f877a.png"><img class="alignleft size-full wp-image-527" title="pic16f877a" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/pic16f877a.png" alt="" width="210" height="62" /></a>Learning to program microcontrollers seems like an impossible task but with the help and support of a Hackerspace you&#8217;ll find that it&#8217;s actually simple to get started. The members of Harford Hackerspace set out to learn by starting at the basics and gradually taking on more difficult applications. The key to our quick success was group participation. Most of us had at least attempted PIC programming, but it took a group effort to get the whole picture.</p>
<p>In this tutorial we will teach you what we learned. You can then take this new knowledge to your local hackerspace and put it to good use. Let&#8217;s get started!</p>
<p><span id="more-526"></span></p>
<h1>What will you need?</h1>
<div id="attachment_535" class="wp-caption alignright" style="width: 155px"><a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/PICKit2.jpg"><img class="size-full wp-image-535 " title="PICKit2" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/PICKit2.jpg" alt="PicKit2 Debug Express" width="145" height="145" /></a><p class="wp-caption-text">PicKit2 Debug Express</p></div>
<ul>
<li><a title="PicKits" href="http://www.microchipdirect.com/productsearch.aspx?Keywords=DV164121" target="_blank">PicKit2 or PicKit3 Debug Express</a>- The PicKits come with software, an in-circuit programmer (ICP) and a demo board. On the demo board is a PIC Microcontroller, 8 LEDs, 1 Potentiometer (variable resistor), and 1 momentary push button switch. You&#8217;ll want the Debug Express version.</li>
<li><a title="MPLAB IDE" href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en019469&amp;part=SW007002" target="_blank">MPLAB IDE</a> &#8211; The PicKits come with MPLAB IDE (Integrated Development Environment) software on a CD. However, you should download and install the latest version, as with any software, to avoid running into bugs. MPLAB is where you will do your C Programming.</li>
<li><a title="CCS Compiler" href="http://www.ccsinfo.com/content.php?page=compilers" target="_blank">CCS Compiler</a>- There is a free demo version of the CCS Compiler. However it&#8217;s limited in features. If you plan to do a lot of programming you may want to fork out the money for a full version. CCS comes with its own IDE but you won&#8217;t be using that.</li>
<li><a title="Debug Express Examples" href="http://ww1.microchip.com/downloads/en/DeviceDoc/PICkit%202-DBE%20887%20Lessons%20(b).zip" target="_blank">Debug Express Examples</a> &#8211; The PicKit 2 comes with a second CD which includes mostly assembly (.asm) examples but does include a couple Hi-Tech C examples. Hi-Tech is an alternative compiler to CCS and chances are these C examples will not work. However, they contain enough information that they are worth looking at.</li>
</ul>
<p style="text-align: center;">
<div id="attachment_538" class="wp-caption aligncenter" style="width: 510px"><a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/PicKit_DemoBoard_edited.jpg"><img class="size-full wp-image-538 " title="PicKit2 44 Pin Demo Board" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/PicKit_DemoBoard_edited.jpg" alt="" width="500" height="285" /></a><p class="wp-caption-text">PicKit2 44Pin Demo Board</p></div>
<h1>Software Installation</h1>
<p>Installing the software is fairly straight forward. Start by installing MPLAB and the Debug Express Examples. Then install the CCS Compiler.  You can post a comment here if you have trouble but I don&#8217;t think you will.</p>
<h1>Start a new Project</h1>
<ol>
<li>Start MPLAB</li>
<li>From the Project Menu select Project Wizard</li>
<li>Click Next &#8211; This is just a splash screen telling you about the wizard</li>
<li>Select your PIC device &#8211; Our PicKit2s came with PIC16F887 chips. Yours may be different so make sure you select the correct chip.<a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/wizard_step_one.jpg"><img class="aligncenter size-full wp-image-553" title="wizard_step_one" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/wizard_step_one.jpg" alt="" width="382" height="317" /></a></li>
<li>Click Next &#8211; This takes you to the second step which is the Compiler Setup.</li>
<li>From the Active Toolsuite drop down box select CCS C Compiler&#8230;<a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/wizard_step_two.jpg"><img class="aligncenter size-full wp-image-555" title="wizard_step_two" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/wizard_step_two.jpg" alt="" width="384" height="296" /></a></li>
<li>Under Toolsuite Contents,  CCS C Compiler (ccsc.exe) should be selected.</li>
<li>Browse to the location of ccsc.exe which by default is C:\Program files\Picc\CCSC.exe</li>
<li>Click Next &#8211; This takes you to the third step which is naming your project.<a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/wizard_step_three.jpg"><img class="aligncenter size-full wp-image-559" title="wizard_step_three" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/wizard_step_three.jpg" alt="" width="387" height="298" /></a></li>
<li>Click browse and create a new project folder and create a new file called Blink. You can use any name but for this tutorial we will be blinking an LED so we call it Blink. It&#8217;s a good idea to put projects in their own folder because a bunch of files will be created and associated with the project.<a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/wizard_step_four1.jpg"><img class="aligncenter size-full wp-image-562" title="wizard_step_four" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/wizard_step_four1.jpg" alt="" width="245" height="176" /></a></li>
<li>Click Next &#8211; This takes you to the fourth step which is adding files to your project. We won&#8217;t be adding any existing files here so you can just Click Next.</li>
<li>Click Finish &#8211; It may look like nothing happened or there are no windows open. In this case select View -&gt; Project and this should show the Project Tree.</li>
<li>Select File -&gt; New</li>
<li>Type the following code:</li>
<pre lang="c">#include &lt;16f887.h&gt;

void main()
{

}
</pre>
<li>Select File -&gt; Save and save the file as main.c in your Blink project folder.</li>
<li>Right Click on the Source Files folder in your Project Tree and select Add Files&#8230; Then select the main.c file you just created.<a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/add_file.jpg"><img class="aligncenter size-full wp-image-547" title="add_file" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/add_file.jpg" alt="Add File" width="312" height="222" /></a></li>
<li>Select Project -&gt; Build All and notice that several new files have been created for you. If you get an error check your code.<a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/build_all.jpg"><img class="aligncenter size-medium wp-image-548" title="build_all" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/build_all-170x300.jpg" alt="" width="170" height="300" /></a></li>
</ol>
<div id="attachment_550" class="wp-caption alignleft" style="width: 212px"><a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/header_in_tree.jpg"><img class="size-full wp-image-550" title="header_in_tree" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/header_in_tree.jpg" alt="" width="202" height="350" /></a><p class="wp-caption-text">Project Tree</p></div>
<p>After you select build all you should notice several new files in your Project Tree. The most important to note is the 16F887.h file under the Header Files folder. Depending on your chip it may be named something different.</p>
<h1>Sample Code</h1>
<p>So, did you pick up on what just happened here?  We created a Source File which we called main.c. It could have been named anything. By using the code #include &lt;16F887.h&gt; and selecting build all the compiler found a compatible header file for our PIC chip and automatically inserted it into our project.</p>
<p>Now you have a complete skeleton project ready for you to fill in the blanks. We&#8217;ll give you your first program and examine it line by line. We will also tell you how we learned which functions would work for the compiler and chip combination we are using.</p>
<p>First, we need to get some reading material or resources. You will need to open the help file for the CCS Compiler. They are nice and give you an executable in Windows Start -&gt; Programs -&gt; Pic-C -&gt;Pic C Help. This was installed with the CCS Compiler. Then, we need to get the Datasheet for our chip.</p>
<p><a title="PIC16F887 Datasheet" href="http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf" target="_blank">PIC16F887 Datasheet</a></p>
<p>Here is our sample Blink code:</p>
<pre lang="c">#include &lt;16f887.h&gt;
#fuses NOMCLR, INTRC_IO, NOBROWNOUT
#use delay(clock=8M)

void main()
{
    while(true)
    {
      output_high(PIN_D1);
      delay_ms(50);
      output_low(PIN_D1);
      delay_ms(50);
    }
}
</pre>
<p><strong>Line 1:</strong><br />
We already know that this file is what tells the compiler to load the header file in our Project Tree. This line also tells the preprocessor to treat the contents of the 16F887.h file as if those contents had appeared in the source program starting from this line. Keywords that start with the character # are called a preprocessor directive. Some examples are #include, #use, #define, and #fuses which are used most often. This code is used to setup the compiler before it starts compiling your code.</p>
<pre lang="c">#fuses NOMCLR, INTRC_IO, NOBROWNOUT
</pre>
<p><strong>Line 2:</strong><br />
The #fuses directive tells the compiler how we want to setup our chip. The available #fuses can be found by looking at the top of the 16f887.h header file. Just double click on it in the Project Tree to open it. At the very top there will be a several-line comment which tells you what fuses can be set. This is one of the murky areas for us still but we can explain what we know so far.</p>
<p>We are setting 3 fuses in our example code. The first NOMCLR stands for No Master Clear. Master Clear is a pin on most chips which can be used to reset the chip. Usually this pin doubles as a Input/Output (I/O) pin. In order to use it as an I/O you must set the fuse NOMCLR to disable it as a Master Clear pin. You&#8217;ll always want to do this if you are not using it as a Master Clear because leaving it float will cause your chip to randomly reboot itself.</p>
<p>The second fuse is INTRC_IO which tells the compiler we want to use the Internal RC (Resistor Capacitor) Oscillator and that we want Pins (9) OSC1/CLKIN and (10) OSC2/CLKOUT set as outputs. In our chips datasheet this is cryptically explained on page 61. You might be tempted to use INTRC instead of INTRC_IO. INTRC outputs a clock on Pin 10 which is 4 times slower than our internal oscillator. This is usually written as Fosc/4. Pin 9 is an I/O when using INTRC.</p>
<p>The third fuse we set in NOBROWNOUT. Brownout is a circuit protection feature. If voltage to our chip drops below a certain threshold the chip will shutdown or reset. On page 216 this is described as Vbor for Voltage Brown Out Reset. In our particular chip the brown out voltage can be set at 4Volts or 2.1volts. In our case we don&#8217;t want the chip to ever reset no matter what the voltage is. So we set NOBROWNOUT.</p>
<pre lang="c">#use delay(clock=8M)
</pre>
<p><strong>Line 3:</strong><br />
The #use directive is followed by another keyword delay. This must be set to the speed at which are oscillator is actually running. Since we are using the INTRC_IO oscillator we know we are using the internal oscillator of this chip. Therefore you need to look in the datasheet of the chip and find out what the normal operating speed of the internal oscillator is. Some chips, including this one, can have their clocks divided to slow them down or they can be clocked faster using an external oscillator such as a crystal. On page 3 of our chip&#8217;s datasheet we can see that our chip actually has two internal oscillators. 8Mhz and 31Khz. We are using the 8Mhz here.</p>
<p>The reason #use delay needs to be defined is actually because we are using the delay_ms() function on line 10. delay_ms() uses the #use delay to know how fast the oscillator is running so that it can correctly delay the execution of our code. If you set #use delay to an incorrect value your delay_ms() will function but it will be at the wrong speed. We&#8217;ll touch on this again in a minute.</p>
<pre lang="c">void main()
{
</pre>
<p><strong>Line 5:</strong><br />
Every program needs a starting point. void main() is the starting point for our program. This is simply how the C language works. Our chip needs to know where to start executing code and it will start in the void main() function. Why void? Void is simply saying that we do not expect our function to return any value. It could be int main but then we would have to return an integer at the end of our program. This is sometimes done to indicate a successful run of the program, but what&#8217;s the point? So we just use void and then we don&#8217;t have to return anything.</p>
<pre lang="c">void main()
{
    while(true)
    {
      output_high(PIN_D1);
      delay_ms(50);
      output_low(PIN_D1);
      delay_ms(50);
    }
}
</pre>
<p><strong>Line 6 and 14, 8 and 13:</strong><br />
Sets of brackets are called blocks. Line 6 starts a block of code and line 14 ends that block of code. Lines 8 and 13 are another pair of brackets and are nested inside of the void main(){} code block. A common syntax error is having too many or two few brackets. For each open bracket you need a matching close bracket.</p>
<pre lang="c">    while(true)
    {
      output_high(PIN_D1);
      delay_ms(50);
      output_low(PIN_D1);
      delay_ms(50);
    }
</pre>
<p><strong>Line 7:</strong><br />
We use a while(true) loop so our code keeps restarting. If we did not use a while(true) loop our LED would turn on and off only one time. We want the LED to keep blinking.</p>
<div id="attachment_598" class="wp-caption aligncenter" style="width: 486px"><a href="http://harfordhackerspace.org/wp-content/uploads/2010/02/help.jpg"><img class="size-full wp-image-598" title="help" src="http://harfordhackerspace.org/wp-content/uploads/2010/02/help.jpg" alt="CCS Help Program" width="476" height="467" /></a><p class="wp-caption-text">CCS Help Program</p></div>
<p><strong>Line 9:</strong><br />
output_high() is a compiler function. This is unique to the CCS Compiler. Remember that Help File I told you to get ready? It&#8217;s located under Windows Start -&gt; Programs -&gt; Pic-C -&gt; Pic C Help. If you select the index tab and type &#8216;output&#8217; you will see a long list of output options. output_A would control an entire bank, or PORT, of outputs. In our case we only want to toggle one output and we want to set it to High (on). The parameter PIN_D1 is defined in the 16f887.h header file.</p>
<p>See&#8230;That header file is coming in handy after all. Instead of you having to look in the datasheet and try to figure out what the hex value of PIN_D1 is, the CCS Compiler has given you a header file which defines a constant name for the value. All you need to know is where to look for the name (in the header file). If you look at the pinout diagram in your datasheet you might notice there is no pin labeled D1. It&#8217;s actually labeled RD1. &#8216;D&#8217; is the Bank and 1 is the Port. Honestly, I don&#8217;t know what the R means but who cares. Let&#8217;s try another one. What do you think output_high(PIN_A0) will do? You&#8217;ve got it. It will turn the pin labeled RA0 in your datasheet to high. See&#8230;It&#8217;s not that hard once you know where to look.</p>
<pre lang="c">delay_ms(50);
</pre>
<p><strong>Line 10 and Line 12:</strong><br />
We already touched on delay_ms(50) when we were talking about the #use directive. Just a refresher here: In order for delay_ms to work you must set #use delay to the proper clock speed. A wrong clock speed will cause delay_ms to not work properly. delay_ms stands for Delay Milliseconds. Where do you think you would look if you wanted to delay micro seconds? You look in the CCS Help program and simply type delay. You would then notice you can delay for Microseconds(_us) or Cycles(_cycles). Clicking on those entries gives you examples of their use.</p>
<p><strong>Line 11:</strong><br />
This one I am going to leave for your homework. If output_high(PIN_D1) turns the LED on then what do you think output_low(PIN_D1) does? Here&#8217;s a tip. Look in the CCS Help file.</p>
<h1>Conclusion</h1>
<p>So, you flashed an LED and now you are bored again. Use the CCS Help file and look up ADC for Analog to Digital Converter. Your Potentiometer is connected to an ADC pin and you should be able to read the help file and learn how to read the position of the potentiometer. You can also search the <a href="http://ww1.microchip.com/downloads/en/DeviceDoc/41296a.pdf">44 Pin Demo Board User guide</a> and learn what port the pushbutton is connected to. Then search the CCS Help for Input_State and learn how to use an input to control the LED. So don&#8217;t stop with this tutorial. There is lots to learn.</p>
<p>This is where I&#8217;m supposed to tell you to come join our hackerspace. But if you don&#8217;t live near Baltimore, check out www.hackerspaces.org and find a hackerspace near you. They are all over the world and are a ton of fun.</p>
<p>We are taking the knowledge we learned about flashing LEDs and applying it to hacking Toy RC Cars to make them autonomous (drive themselves). Check out our <a href="http://wiki.harfordhackerspace.org">wiki.harfordhackerspace.org</a> projects page for details on that project. It&#8217;s actually a very simple yet rewarding project.</p>
]]></content:encoded>
			<wfw:commentRss>http://baltimorehackerspace.com/2010/02/programming-pic-microcontrollers-in-c/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Sourceforge and TortoiseSVN Tutorial</title>
		<link>http://baltimorehackerspace.com/2009/07/sourceforge-and-tortoisesvn-tutorial/</link>
		<comments>http://baltimorehackerspace.com/2009/07/sourceforge-and-tortoisesvn-tutorial/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 01:24:34 +0000</pubDate>
		<dc:creator>Squintz</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Sourceforge]]></category>
		<category><![CDATA[TortoiseSVN]]></category>

		<guid isPermaLink="false">http://harfordhackerspace.org/index.php/?p=201</guid>
		<description><![CDATA[If you&#8217;ve ever come across an OpenSource or OpenHardware project then you have probably heard of Sourcforge. I have to admit that I have know about Sorceforge and (Sub)version Control for years but I could never figure out why someone would want to use something so complex. I finally figured it out&#8230;it&#8217;s because Sourceforge and Version control is not at [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-328" title="SourceForge_net" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/SourceForge_net.png" alt="SourceForge_net" width="210" height="62" />If you&#8217;ve ever come across an OpenSource or OpenHardware project then you have probably heard of <a href="http://sourceforge.net/" target="_blank">Sourcforge</a>. I have to admit that I have know about Sorceforge and (Sub)version Control for years but I could never figure out why someone would want to use something so complex. I finally figured it out&#8230;it&#8217;s because Sourceforge and Version control is not at all complex. In fact it is actually very cool.  In order to use Sourceforge you&#8217;ll need a subversion (SVN) client. TortoiseSVN is the self proclaimed &#8220;coolest interface to (sub)version control&#8221;. This tutorial will get you up and running quickly with an existing Sourceforge project. You will be able to Checkout entire projects and have an exact copy on your local PC for editing and you will also learn how to Add files and Commit changed files<span id="more-201"></span></p>
<h3>Overview of TortoiseSVN</h3>
<p>TortoiseSVN is a shell application. That means it&#8217;s an application that it interacts with the operating system. In this case it interacts with the file system. This will become visible in just a few moments. The other thing to know about TortoiseSVN is that you won&#8217;t find an icon in your start menu to run some elaborate  GUI (Graphical User Interface). Instead, you will notice a new menu whenever you Right-Click on your Desktop, a File Folder, or a File.  The Windows file system esentially becomes your GUI for working with Files.</p>
<p>The subversion process works by creating a local copy of the existing files. You will be able to distinguish these files from others because they will have additonal icons overlayed on top of your files and folders to show you the status. Once you are finished editing existing files and adding new files you then commit the changes to the remote file server (i.e.  Sourceforge.)</p>
<p><strong>About Those Icons: <img class="alignnone size-full wp-image-300" title="svn_folderjpg" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/svn_folderjpg1.JPG" alt="svn_folderjpg" width="19" height="22" /></strong></p>
<p><img class="size-full wp-image-228" title="insubversionicon" src="http://harfordhackerspace.org/wp-content/uploads/2009/06/insubversionicon.png" alt="insubversionicon" width="32" height="32" />A fresh checked out working copy has a green checkmark as overlay. That means the Subversion status is <em>Normal</em>.<br />
<img class="size-full wp-image-230" title="modifiedicon" src="http://harfordhackerspace.org/wp-content/uploads/2009/06/modifiedicon.png" alt="modifiedicon" width="32" height="32" />As soon as you start editing a file, the status changes to <em>Modified</em> and the icon overlay then changes to a red exclamation mark. That way you can easily see which files were changed since you last updated your working copy and need to be committed.</p>
<p><img class="size-full" title="conflicticon" src="http://harfordhackerspace.org/wp-content/uploads/2009/06/conflicticon.png" alt="conflicticon" width="32" height="32" />If during an update a <em>conflict</em> occurs then the icon changes to a yellow exclamation mark.<br />
<img class="size-full wp-image-225" title="readonlyicon" src="http://harfordhackerspace.org/wp-content/uploads/2009/06/readonlyicon.png" alt="readonlyicon" width="32" height="32" />If you have set the</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">svn:needs-lock</div></td></tr></tbody></table></div>
<p>property on a file, Subversion makes that file <em>ReadOnly</em> until you get a lock on that file. Read-only files have this overlay to indicate that you have to get a lock first before you can edit that file.</p>
<p><img class="size-full wp-image-229" title="lockedicon" src="http://harfordhackerspace.org/wp-content/uploads/2009/06/lockedicon.png" alt="lockedicon" width="32" height="32" />If you hold a lock on a file, and the Subversion status is normal, this icon overlay reminds you that you should release the lock if you are not using it to allow others to commit their changes to the file.</p>
<p><img class="size-full wp-image-227" title="deletedicon" src="http://harfordhackerspace.org/wp-content/uploads/2009/06/deletedicon.png" alt="deletedicon" width="32" height="32" />This icon shows you that some files or folders inside the current folder have been scheduled to be <em>deleted</em> from version control or a file under version control is missing in a folder.</p>
<p><img class="alignnone size-full wp-image-239" title="AddedIcon" src="http://harfordhackerspace.org/wp-content/uploads/2009/06/AddedIcon.png" alt="AddedIcon" width="32" height="32" />The plus sign tells you that a file or folder has been scheduled to be <em>added</em> to version control.</p>
<h3>Installation</h3>
<p>Download the latest  TortoiseSVN installer from <a href="http://tortoisesvn.net/downloads" target="_blank">http://tortoisesvn.net/downloads</a>. It will have the .msi (Microsoft Installer) file extention. The  TortoiseSVN installer is very straight forward. Just follow the instructions.</p>
<h3>Working with Sourceforge</h3>
<p>Setting up a Sourceforge account is beyond the scope of this tutorial. We will be looking at this from a supporters or end users perspective. In order to make changes to a projects repository you will need permission from the projects administrator. Sign up for an account and notify the administrator providing them your username.</p>
<p>You will need the URL to the projects repository. This can be found by browsing to the projects homepage and clicking the Develop link on the top menu. Under the subversion access section you will find a URL that looks similar to this: <a href="https://hhscnc.svn.sourceforge.net/svnroot/hhscnc">https://hhscnc.svn.sourceforge.net/svnroot/hhscnc</a>.</p>
<p><img class="alignnone size-full wp-image-313" title="sourceforge_develop_url" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/sourceforge_develop_url.jpg" alt="sourceforge_develop_url" width="570" height="174" /></p>
<h3>Putting it all Together</h3>
<p>Now that you have installed TortoiseSVN and you found the URL to the repository you want to work with you&#8217;ll need to create a local copy of that repository on your machine.</p>
<p> 1. First, right click on your desktop or in a windows file explorer window where you want the folder to be created. Then click the SVN Checkout button.</p>
<p><img class="alignnone size-full wp-image-309" title="desktop_shell_menu_checkout" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/desktop_shell_menu_checkout.jpg" alt="desktop_shell_menu_checkout" width="242" height="320" /></p>
<p> 2. Enter the URL obtained earlier from the projects sourceforge page. Then enter the file path where you would like the folder to be created. We used &#8220;New Folder&#8221; as our example folder. Then click OK.</p>
<p><img class="alignnone size-full wp-image-314" title="tortoise_checkout_enter_url" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/tortoise_checkout_enter_url.jpg" alt="tortoise_checkout_enter_url" width="456" height="346" /></p>
<p> 3. If you have not already created the folder you will be asked if you would like TortoiseSVN to automatically create it.</p>
<p><img class="alignnone size-full wp-image-316" title="tortoise_create_directory_modal" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/tortoise_create_directory_modal.jpg" alt="tortoise_create_directory_modal" width="460" height="352" /></p>
<p> 4. Watch as TortoiseSVN downloads the files from the remote server and saves them as a local copy in the folder you named above. Then press OK.</p>
<p><img class="alignnone size-full wp-image-315" title="tortoise_confirm_checkout_ok" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/tortoise_confirm_checkout_ok.jpg" alt="tortoise_confirm_checkout_ok" width="676" height="312" /></p>
<p> 5. You should now have a new folder on your desktop. You may or may not see the icon overlays on the root folder. If you don&#8217;t see an icon like ours don&#8217;t worry it&#8217;s still working properly and should show up after you work with the local copies and make a few changes to the files and folders.</p>
<p><img class="alignnone size-full wp-image-310" title="local_desktop_icon" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/local_desktop_icon.jpg" alt="local_desktop_icon" width="80" height="110" /></p>
<p>Now that you have a local copy of the repository you can start making changes to those files. Don&#8217;t worry about messing anything up because the changes do not show up in the remote repository unless you commit them and even if you do mess something up the administrator of the project can revert back to a previous copy of the file. You should try to be careful when commiting changes because reverting (rolling back) to a previous version of a file is not always easy.</p>
<p>Here is an example of what your folder structures may look like locally. Note the icons as mentioned earlier. In our case all of our folders and files are unchanged. Under settings you can have TortoiseSVN check for updates automatically. This is setup by default as to check weekly but you may change it.</p>
<p><img class="alignnone size-medium wp-image-312" title="local_folder_icons" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/local_folder_icons-300x223.jpg" alt="local_folder_icons" width="300" height="223" /></p>
<p><img class="alignnone size-medium wp-image-311" title="local_file_icons" src="http://harfordhackerspace.org/wp-content/uploads/2009/07/local_file_icons-300x225.jpg" alt="local_file_icons" width="300" height="225" /></p>
<p><strong> </strong><strong>Working with Folders and Files</strong></p>
<p>Adding, Deleting, Renaming and Commiting changes to the files and folders is very simple. Just work with the folder as if it were any other folder on your file system. After all it actually is just like every other folder. When you create a new file or folder you need to right click on that file or folder and select Add from the TortoiseSVN menu. This does not actually commit the file to the repository. You will need to right click on the folder and select SVN Commit&#8230; from the menu to commit added, renamed, deleted or changed files.</p>
<p>One last thing to note is that there is a Delete option under the TortoiseSVN menu. Insteady of simply pressing Delete when working with your files and folders you may want to use this menu item as it will also delete the remote copy of the file the next time you commit the changes.</p>
<p><strong>Final Thoughts</strong></p>
<p>This tutorial is meant to get you up and running quickly. TortoiseSVN is well documented and you should read about any features not discussed here before using those features. Especially if you don&#8217;t own the project you are working on.</p>
]]></content:encoded>
			<wfw:commentRss>http://baltimorehackerspace.com/2009/07/sourceforge-and-tortoisesvn-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New! Tutorials Section</title>
		<link>http://baltimorehackerspace.com/2009/06/testing-new-tutorials-section/</link>
		<comments>http://baltimorehackerspace.com/2009/06/testing-new-tutorials-section/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 19:48:23 +0000</pubDate>
		<dc:creator>Squintz</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[Website]]></category>

		<guid isPermaLink="false">http://harfordhackerspace.org/index.php/?p=191</guid>
		<description><![CDATA[Coming Soon&#8230; Tutorials written by our members for our members and for the rest of the world. These tutorials will typically be hackerspace related but are not limited to hackerspace topics. The idea is that if we use a piece of software, hardware, or a tool that some people may need a little help with [...]]]></description>
			<content:encoded><![CDATA[<p>Coming Soon&#8230; Tutorials written by our members for our members and for the rest of the world.<span id="more-191"></span><br />
These tutorials will typically be hackerspace related but are not limited to hackerspace topics. The idea is that if we use a piece of software, hardware, or a tool that some people may need a little help with then we can write a tutorial about it here. This will make sure all new members are on the same page when working together.</p>
]]></content:encoded>
			<wfw:commentRss>http://baltimorehackerspace.com/2009/06/testing-new-tutorials-section/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

