<?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>bildr</title>
	<atom:link href="http://bildr.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://bildr.org</link>
	<description>bildr - communal know-how</description>
	<lastBuildDate>Wed, 11 Apr 2012 00:08:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Controlling 2 motors with the TB6612FNG + Arduino</title>
		<link>http://bildr.org/2012/04/tb6612fng-arduino/</link>
		<comments>http://bildr.org/2012/04/tb6612fng-arduino/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 12:00:53 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[h-bridge]]></category>
		<category><![CDATA[motor]]></category>
		<category><![CDATA[TB6612FNG]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=2059</guid>
		<description><![CDATA[
First off: I know&#8230; we went overboard with the motor illustration. In previous articles we have discussed how to control motors with simple transistors. And&#8230; with PWM you could control the speed. But that is just one motor, and you can only go one direction. Today we are going to talk about the TB6612FNG dual [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2012/03/TB6612FNG.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<strong>First off</strong>: I know&#8230; we went overboard with the motor illustration.</p>
<p>In <a href="http://bildr.org/2012/03/rfp30n06le-arduino/">previous articles</a> we have discussed how to control motors with simple <a href="http://wiki.bildr.org/index.php/transistors">transistors</a>. And&#8230; with <a href="http://wiki.bildr.org/index.php/PWM">PWM</a> you could control the speed. But that is just one <a href="http://wiki.bildr.org/index.php/motor">motor</a>, and you can only go one direction. Today we are going to talk about the TB6612FNG dual motor driver, specifically the <a href="http://www.sparkfun.com/products/9457">TB6612FNG breakout board</a> from <a href="http://www.sparkfun.com/">sparkfun</a>.</p>
<p>The TB6612FNG isn&#8217;t just a dual motor driver, it is a dual <a href="http://wiki.bildr.org/index.php/H-bridge">H-bridge</a>. An h-bridge is basically a specific setup of <a href="http://wiki.bildr.org/index.php/transistors">transistors</a> that allow you to switch direction of <a href="http://wiki.bildr.org/index.php/current">current</a>. So hooked up to a motor, that means you can have it spin in both directions, and with <a href="http://wiki.bildr.org/index.php/PWM">PWM</a> input, you can use your arduino to make them spin at any speed. Because the TB6612FNG has 2 H-bridges, you can not only make a robot go forwards and backwards, but also turn around by having each wheel spin in a different direction.</p>
<p><strong>Quick stats on this guy</strong>: It is capable of supplying up to 13<a href="http://wiki.bildr.org/index.php/V">V</a> and 1.2<a href="http://wiki.bildr.org/index.php/A">A</a> (3.2 peak)
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2012/03/TB6612FNG_arduino_hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/03/TB6612FNG_arduino_hookup-400x306.png" alt="" title="TB6612FNG_arduino_hookup" width="400" height="306" class="alignleft size-medium wp-image-2060" /></a></p>
</div>
</div>
<div class="wideBody">
<h3>Hooking it up</h3>
<p>As you can tell from the illustration this guy requires a few pins from your arduino to get it running. And it probably looks complicated at first. But it&#8217;s not that bad. The first thing to notice however, is that you do need an external power source for your motors (<strong>the TB6612FNG can work with 2.5 to 13v</strong>), the 5v pin on the arduino just can not source enough power to drive 2 motors, and you could damage your arduino if you do.</p>
<p>But why it uses so many pins is for several reasons. First, there is a standby pin, if this pin is held LOW, the motors are basically disconnected from power. And&#8230; Each motor also has 3 control pins, 2 for direction, and one for speed.</p>
<h3>Code</h3>
<p>The code for this is very basic. We created a function for you that makes controlling the TB6612FNG from your arduino easier, but you can also change it up and do it your own way.</p>
<p>As I mentioned above, Each motor has 3 control pins, 2 for direction, and one for speed. When one direction pin is HIGH and the other is LOW the motor will spin one direction, flip them and it spins the other direction (both HIGH or both LOW and the motor stops). The PWM pin allows you to analogWrite to this pin to control the speed of that one motor. andlogWrite 0 and the motor stops, 255, and it will go full speed.</p>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">//motor A connected between A01 and A02</span>
<span class="co1">//motor B connected between B01 and B02</span>

<span class="kw4">int</span> STBY <span class="sy0">=</span> <span class="nu0">10</span><span class="sy0">;</span> <span class="co1">//standby</span>

<span class="co1">//Motor A</span>
<span class="kw4">int</span> PWMA <span class="sy0">=</span> <span class="nu0">3</span><span class="sy0">;</span> <span class="co1">//Speed control </span>
<span class="kw4">int</span> AIN1 <span class="sy0">=</span> <span class="nu0">9</span><span class="sy0">;</span> <span class="co1">//Direction</span>
<span class="kw4">int</span> AIN2 <span class="sy0">=</span> <span class="nu0">8</span><span class="sy0">;</span> <span class="co1">//Direction</span>

<span class="co1">//Motor B</span>
<span class="kw4">int</span> PWMB <span class="sy0">=</span> <span class="nu0">5</span><span class="sy0">;</span> <span class="co1">//Speed control</span>
<span class="kw4">int</span> BIN1 <span class="sy0">=</span> <span class="nu0">11</span><span class="sy0">;</span> <span class="co1">//Direction</span>
<span class="kw4">int</span> BIN2 <span class="sy0">=</span> <span class="nu0">12</span><span class="sy0">;</span> <span class="co1">//Direction</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>STBY<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>

  <span class="kw3">pinMode</span><span class="br0">&#40;</span>PWMA<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>AIN1<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>AIN2<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>

  <span class="kw3">pinMode</span><span class="br0">&#40;</span>PWMB<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>BIN1<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>BIN2<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  move<span class="br0">&#40;</span>1<span class="sy0">,</span> 255<span class="sy0">,</span> 1<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//motor 1, full speed, left</span>
  move<span class="br0">&#40;</span>2<span class="sy0">,</span> 255<span class="sy0">,</span> 1<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//motor 2, full speed, left</span>

  <span class="kw3">delay</span><span class="br0">&#40;</span>1000<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//go for 1 second</span>
  stop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//stop</span>
  <span class="kw3">delay</span><span class="br0">&#40;</span>250<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//hold for 250ms until move again</span>

  move<span class="br0">&#40;</span>1<span class="sy0">,</span> 128<span class="sy0">,</span> 0<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//motor 1, half speed, right</span>
  move<span class="br0">&#40;</span>2<span class="sy0">,</span> 128<span class="sy0">,</span> 0<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//motor 2, half speed, right</span>

  <span class="kw3">delay</span><span class="br0">&#40;</span>1000<span class="br0">&#41;</span><span class="sy0">;</span>
  stop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">delay</span><span class="br0">&#40;</span>250<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> move<span class="br0">&#40;</span><span class="kw4">int</span> motor<span class="sy0">,</span> <span class="kw4">int</span> speed<span class="sy0">,</span> <span class="kw4">int</span> direction<span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="co1">//Move specific motor at speed and direction</span>
<span class="co1">//motor: 0 for B 1 for A</span>
<span class="co1">//speed: 0 is off, and 255 is full speed</span>
<span class="co1">//direction: 0 clockwise, 1 counter-clockwise</span>

  <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>STBY<span class="sy0">,</span> <span class="kw2">HIGH</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//disable standby</span>

  <span class="kw4">boolean</span> inPin1 <span class="sy0">=</span> <span class="kw2">LOW</span><span class="sy0">;</span>
  <span class="kw4">boolean</span> inPin2 <span class="sy0">=</span> <span class="kw2">HIGH</span><span class="sy0">;</span>

  <span class="kw1">if</span><span class="br0">&#40;</span>direction <span class="sy0">==</span> 1<span class="br0">&#41;</span><span class="br0">&#123;</span>
    inPin1 <span class="sy0">=</span> <span class="kw2">HIGH</span><span class="sy0">;</span>
    inPin2 <span class="sy0">=</span> <span class="kw2">LOW</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>

  <span class="kw1">if</span><span class="br0">&#40;</span>motor <span class="sy0">==</span> 1<span class="br0">&#41;</span><span class="br0">&#123;</span>
    <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>AIN1<span class="sy0">,</span> inPin1<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>AIN2<span class="sy0">,</span> inPin2<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw3">analogWrite</span><span class="br0">&#40;</span>PWMA<span class="sy0">,</span> speed<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span>
    <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>BIN1<span class="sy0">,</span> inPin1<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>BIN2<span class="sy0">,</span> inPin2<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw3">analogWrite</span><span class="br0">&#40;</span>PWMB<span class="sy0">,</span> speed<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> stop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="co1">//enable standby  </span>
  <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>STBY<span class="sy0">,</span> <span class="kw2">LOW</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2012/04/tb6612fng-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling a ton of servos &#8211; TLC5940 + Arduino</title>
		<link>http://bildr.org/2012/03/servos-tlc5940-arduino/</link>
		<comments>http://bildr.org/2012/03/servos-tlc5940-arduino/#comments</comments>
		<pubDate>Tue, 27 Mar 2012 12:33:42 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Servo]]></category>
		<category><![CDATA[TLC5940]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1895</guid>
		<description><![CDATA[
This is something we have been asked a lot about. How do I control a ton of Servo motors with my arduino? Well&#8230; using the TLC5940 is one way. And this nice break outboard from sparkfun makes connecting a ton of servos easy. The output pins on the board are all setup and spaced to [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2012/01/TLC5940.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<p>This is something we have been asked a lot about. How do I control a ton of Servo motors with my arduino? Well&#8230; using the TLC5940 is one way. And this <a href="http://www.sparkfun.com/products/10616">nice break outboard</a> from <a href="http://www.sparkfun.com/">sparkfun</a> makes connecting a ton of servos easy. The output pins on the board are all setup and spaced to allow you to just solder some male headers to it and plugin some servo cables.</p>
<h4>Why Do I need something special to control them?</h4>
<p>First off, if you don&#8217;t know why something special is needed to control extra servos, let&#8217;s go over a few basic things. A simple RC Servo (most <a href="http://www.sparkfun.com/search/results?term=servo&#038;what=products">smaller servos</a> in the sub $20 range) is a DC motor that knows its rotation position, and is most often limited to moving 180 degrees. You can instruct one of these servos to move to a specific degree (0-180) using <a href="http://wiki.bildr.org/index.php/PWM">PWM</a>, Pulse Width Modulation. (Seriously, click the link to get a better visual understanding of what it is). On the arduino you usually think of this as analogWrite. Well, because there are only a few PWM pins on your arduino, if you want to control more servos than you have PWM pins, you need something like the TLC5940.</p>
<p>You can think of the TLC5940 as PWM pin multiplier because it needs a few PWM pins to operate correctly, but it gives you back a bunch more. If you were wondering, no, it can&#8217;t add PWM capabilities to a controller that has no PWM pins.</p>
<h3>Hooking it up</h3>
<p>Hooking the TLC5940 up to your arduino is a little more complicated than most, but if you follow the diagram, you will be all set.</p>
<p>The power supply isn&#8217;t always necessary, and you could connect the VCC pin to the 5V pin on your Arduino. But, if you plan on moving more than a couple of the Servos at a time, you will need an extra power supply, and yes, it must be 5V (and remember to connect the external supply ground to the arduino&#8217;s ground as shown in the illustration). If you don&#8217;t use a power supply, and you use too much power by moving too many of the servos at a time, you can cause the Arduino to restart due to power failure, and you will just get a bunch of twitching servos.</p>
<h4>chaining them together</h4>
<p>If you need more PWM/Servo connections, you can chain the TLC5940s together. Just connect another board&#8217;s input pins to the output pins of the first and you are good to go. </p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2012/02/Tlc5940_arduino_hookup2.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/02/Tlc5940_arduino_hookup2-400x671.png" alt="" title="Tlc5940_arduino_hookup2" width="400" height="671" class="alignleft size-medium wp-image-1968" /></a></p>
</div>
</div>
<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2012/02/TLC5940_chain-950x129.png"/></p>
<div class="wideBody">
<h3>Code</h3>
<p>The code for this board is a bit on the complex side, so it uses <a href="http://code.google.com/p/tlc5940arduino/">a library</a> to make your life easier. Im going to do something a little unordinary here. <strong style="color: red;">The library is just a little too big to work well with our code delivery system. But you can <a style="color: darkred;" href="http://code.google.com/p/tlc5940arduino/downloads/detail?name=Tlc5940_r014_2.zip&#038;can=2&#038;q= ">download the library here (zip file)</a></strong>.
</div>
<div class="columnBody">
<div class="leftColumn">
<p>To make this code work, <strong>before you load the code, or even open the Arduino program</strong>, you will need to place the downloaded &#8220;Tlc5940&#8243; folder (see above for link) into your Arduino Library. If you don’t know where your libraries folder is by default, Look to the right.
</div>
<div class="rightColumn">
<h3>Default Library Folder Location</h3>
<p><span style="font-size: 10px; line-height:12px;"><strong>On your Mac:</strong>: In (home directory)/Documents/Arduino/libraries<br />
<strong>On your PC:</strong>: My Documents -> Arduino -> libraries<br />
<strong>On your Linux box:</strong>: (home directory)/sketchbook/libraries<br />
</span></p>
</div>
</div>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">//From the bildr article: http://bildr.org/2012/03/servos-tlc5940-arduino</span>
<span class="co1">//Requires the Tlc5940 library. http://code.google.com/p/tlc5940arduino/downloads/list</span>

<span class="co2">#include &quot;Tlc5940.h&quot;</span>
<span class="co2">#include &quot;tlc_servos.h&quot;</span>

<span class="kw4">int</span> numberOfServos <span class="sy0">=</span> <span class="nu0">9</span><span class="sy0">;</span> <span class="co1">//how many servos on the chain?</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  tlc_initServos<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>  <span class="co1">// Note: this will drop the PWM freqency down to 50Hz.</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="co1">//loop through all the servos and move one at a time to 180º</span>
  <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0">&lt;</span>numberOfServos<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><span class="br0">&#123;</span>

    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> angle <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> angle <span class="sy0">&lt;</span> <span class="nu0">180</span><span class="sy0">;</span> angle<span class="sy0">+=</span> 10<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      tlc_setServo<span class="br0">&#40;</span>i<span class="sy0">,</span> angle<span class="br0">&#41;</span><span class="sy0">;</span>
      Tlc.<span class="me1">update</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw3">delay</span><span class="br0">&#40;</span>20<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>

    <span class="kw3">delay</span><span class="br0">&#40;</span>200<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>

  <span class="co1">//loop through all the servos and move one at a time to 0º</span>
  <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0">&lt;</span>numberOfServos<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><span class="br0">&#123;</span>

    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> angle <span class="sy0">=</span> <span class="nu0">180</span><span class="sy0">;</span> angle <span class="sy0">&gt;=</span> <span class="nu0">0</span><span class="sy0">;</span> angle<span class="sy0">-=</span> 10<span class="br0">&#41;</span> <span class="br0">&#123;</span>
      tlc_setServo<span class="br0">&#40;</span>i<span class="sy0">,</span> angle<span class="br0">&#41;</span><span class="sy0">;</span>
      Tlc.<span class="me1">update</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw3">delay</span><span class="br0">&#40;</span>20<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>

    <span class="kw3">delay</span><span class="br0">&#40;</span>200<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>

<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
<h3>Video</h3>
<p><iframe src="http://player.vimeo.com/video/38274663?portrait=0" width="950" height="534" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2012/03/servos-tlc5940-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stable Orientation &#8211; Digital IMU 6DOF + Arduino</title>
		<link>http://bildr.org/2012/03/stable-orientation-digital-imu-6dof-arduino/</link>
		<comments>http://bildr.org/2012/03/stable-orientation-digital-imu-6dof-arduino/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 01:26:16 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[6DOF]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[IMU]]></category>
		<category><![CDATA[Orentation]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1933</guid>
		<description><![CDATA[
A while back we wrote an article on sensing orientation with the adxl335 accelerometer. In that article I mentioned all the drawbacks of trying to do this with just an accelerometer, and said that if you needed something stable, what you really needed was an IMU. Well&#8230; We are back with an article covering just [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2012/01/6dof.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<p>A while back we wrote an article on <a href="http://bildr.org/2011/04/sensing-orientation-with-the-adxl335-arduino/">sensing orientation with the adxl335 accelerometer</a>. In that article I mentioned all the drawbacks of trying to do this with just an accelerometer, and said that if you needed something stable, what you really needed was an IMU. Well&#8230; We are back with an article covering just that, the <a href="http://www.sparkfun.com/products/10121">Digital IMU 6DOF (6 degrees of freedom) breakout board</a> from <a href="http://www.sparkfun.com/">sparkfun</a>.</p>
<p>An IMU (Inertial Measurement Unit) is a system comprised of an accelerometer and a gyroscope working in tandem to compensate for the pitfalls of each other. This particular board is comprised of the ADXL345 accelerometer (<a href="http://bildr.org/2011/03/adxl345-arduino/">bildr article</a>) and the ITG-3200 gyroscope. Correctly setup, the gyro is able to kick in where an accelerometer leaves off, and vise versa. A gyro is great at measuring rotation, but has no understanding of orientation. And an accelerometer is good at determining orientation, but has no ability to keep track during movement and rotation. But just sticking these together wont give you a clean orientation, we need some hardcore math that will be able to take both the readings, along with previous readings, and make a really good estimate of what is going on. The math for this is known as filtering.</p>
<p>You may have heard of something called a kalman filter. I have searched for years and have never seen a working version for 3axis that could run on the arduino. Sadly, the arduino just dosnt have the power to make it work. Thankfully Kalman isnt the only name in town, and the fusion filter does an excellent job, and is very light mathematically and runs really well on the arduino. The awesome thing about this is that the guys over at <a href="http://www.varesano.net">varesano</a> did all the hard work in their <a href="http://www.varesano.net/projects/hardware/FreeIMU">library for the 9DOF</a>( has 3 axis magnetometer )</p>
<h3>Hooking it up</h3>
<p>The both components of the Digital IMU 6DOF are <a href="http://wiki.bildr.org/index.php/I2C">I2C</a> devices on a single bus. I2C is a 2-wire serial connection, so we just need to connect the SDA (Data) and SCL (Clock) lines to your Arduino for communication. On your Arduino (everything but the <a href="http://wiki.bildr.org/index.php/Arduino_Mega ">mega</a>) SDA is on analog pin 4, and SCL is on analog pin 5. On an arduino mega, SDA is digital 20, and SCL is digital 21. (The Arduino Leonardo will also be different). Other than these 2 lines, we just need to connect power(3.3v), ground and we are all set.</p>
<p><strong>Note:</strong> I noticed that this device is particularly sensitive to so-so wiring, so make sure your connections are solid, or you will see this guy freezing left and right.</p>
</div>
<div class="rightColumn">
<a href="http://bildr.org/blog/wp-content/uploads/2012/01/6DOF_arduino_hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/01/6DOF_arduino_hookup-400x646.png" alt="" title="6DOF_arduino_hookup" width="400" height="646" class="alignleft size-medium wp-image-1937" /></a>
</div>
</div>
<div class="wideBody">
<h3>Code</h3>
<p>Using this part isnt simple from a code point, so we have a library for you, and a big one at that. As I said before the guys over at <a href="http://www.varesano.net">varesano</a> did all the hard work in their <a href="http://www.varesano.net/projects/hardware/FreeIMU">library for the 9DOF</a>( has 3 axis magnetometer ) I just modified for use specifically for this board and made it into a single library so it wouldn&#8217;t cause any conflicts. Because this is based off of the FreeIMU code, we are keeping their GPL license on it.
</div>
<div class="columnBody">
<div class="leftColumn">
<p>To make this code work, <strong>before you load the code, or even open the Arduino program</strong>, we need to place the &#8220;FreeSixIMU&#8221; folder into your Arduino Library. If you don’t know where that is by default, Look to the right.</p>
<p>If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.</p>
</div>
<div class="rightColumn">
<h3>Default Library Folder Location</h3>
<p><span style="font-size: 10px; line-height:12px;"><strong>On your Mac:</strong>: In (home directory)/Documents/Arduino/libraries<br />
<strong>On your PC:</strong>: My Documents -> Arduino -> libraries<br />
<strong>On your Linux box:</strong>: (home directory)/sketchbook/libraries<br />
</span></p>
</div>
</div>

	<div class="clear">
	<script src="http://code.bildr.org/render/6dof/arduino.js"></script>
	</div>
	
<div class="wideBody">
<h3>Visualizing the orientation with a processing sketch</h3>
<p>Sometimes it is hard to see if the output is correct&#8230; So we can verify it with a processing sketch (check out the video below). We have included a processing example &#8220;freeSixCube&#8221; and it has 2 parts. A specialized arduino firmware that must be loaded first, and a processing sketch. You need to configure the sketch to use the correct serial port.</p>
<p><strong>If you are having issues with processing sketch missing a font, let me know, I did my best to not require any font files.</strong></p>
<p>When you launch the processing sketch, (make sure to hold it very still for the first 2 seconds) it should draw up a cube, and after a second it will move to mimic your movement of the 6DOF board. You can hit &#8220;h&#8221; to reset the orientation to level so you can get it to what you consider level, hit &#8220;h&#8221; and it should look just like how you hold it from there on out.</p>
<p>You will see it drifting (moving onscreen without you moving the sensor) quite a bit at first, but hold it still and it will smooth out. But even then, the yaw will still be drifting a bit. To understand why, read on.</p>
<h3>Drifting Yaw</h3>
<p><a href="http://wiki.bildr.org/index.php/Yaw">Yaw</a> is name for rotation around an axis that is similar to spinning a top, or shaking your head “no.” Accelerometers can’t measure this type of motion, but gyros can. Unfortunately gyros have no sense of direction, and also drift. So your yaw measurements from this will be without a sense of direction, and will drift over time. How much? Maybe a few degrees a second, maybe less, it&#8217;s hard to say because this library does a good job if suppressing it, but it&#8217;s not perfect.</p>
<p><strong style="color: darkred;">In the first second after the Arduino resets (due to code upload, serial connection, etc), the firmware will try to reduce the drift from the gyroscope. So Make sure to keep the IMU steady during that startup time for best results.</strong></p>
<p>If you need direction, and no drift in your yaw you need to get your self an AHRS, that&#8217;s an IMU with a magnetometer on it. <a href="http://www.sparkfun.com/products/10724">Like this guy here</a>.
</div>
<h3>Video</h3>
<p><iframe src="http://player.vimeo.com/video/38274662?portrait=0" width="950" height="534" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2012/03/stable-orientation-digital-imu-6dof-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>High-Power Control: Arduino + N-Channel MOSFET</title>
		<link>http://bildr.org/2012/03/rfp30n06le-arduino/</link>
		<comments>http://bildr.org/2012/03/rfp30n06le-arduino/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 13:18:27 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[MOSFET]]></category>
		<category><![CDATA[N-Channel MOSFET]]></category>
		<category><![CDATA[rfp30n06le]]></category>
		<category><![CDATA[Transistor]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=2014</guid>
		<description><![CDATA[
Eventually you are going to find yourself holding a 12v solenoid, motor, or light and wondering &#8220;How the heck am I supposed to control this from my Arduino?&#8221; And we have covered this in the past. Today we are going to talk about another way of doing just that, this time with an N-Channel MOSFET [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/03/tip120.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<p>Eventually you are going to find yourself holding a 12v <a href="http://wiki.bildr.org/index.php/solenoid">solenoid</a>, <a href="http://wiki.bildr.org/index.php/motor">motor</a>, or light and wondering &#8220;How the heck am I supposed to control this from my Arduino?&#8221; And we have <a href="http://bildr.org/2011/03/high-power-control-with-arduino-and-tip120/">covered this in the past</a>. Today we are going to talk about another way of doing just that, this time with an N-Channel MOSFET <strong>metal–oxide–semiconductor field-effect transistor</strong>, specifically the RFP30N06LE MOSFET (You can pick these up from <a href="http://www.sparkfun.com/products/10213">sparkfun</a>). <strong>but you can use any N-Channel MOSFET exactly the same way.</strong></p>
<h3>How this works</h3>
<p>WARNING: I am about to simplify the crud out of this, so beware&#8230; it is here in an attempt to explain, in simple terms, what is going on.</p>
<p>First off, a MOSFET is a transistor, just a special kind.</p>
<p>If you don&#8217;t know transistors at all, they are 3 lead components that have 2 simple functions, to switch or amplify (in this example it is setup as a switch). You basically have an <strong>In</strong> called the <strong>Source</strong>, an <strong>Out</strong> called the <strong>Drain</strong>, and a <strong>Control</strong> called the <strong>Gate</strong>. When you send a HIGH signal to the gate (control pin), the transistor switches and allows current to flow from the source (in) to the drain (out).</p>
<p>So we connect it so that our motor, solenoid or light is connected to V+ but not ground (V-). Ground is connected to the transistor&#8217;s drain. When our arduino sends a HIGH signal to the transistor&#8217;s gate, it switches the transistor (connecting the drain and source) and completes the circuit for the motor, solenoid, or light.</p>
<h3>More Information</h3>
<p>If you want to know more, or actually know what is actually going on in there. <a href="http://www.sparkfun.com/news/819">Pete over at Sparkfun put out amazing video explaining MOSFETs for a solid 20min</a>. Highly recommended.</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2012/03/rfp30n06le-arduino-solenoid.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/03/rfp30n06le-arduino-solenoid-400x218.png" alt="" title="rfp30n06le-arduino-solenoid" width="400" height="218" class="alignleft size-medium wp-image-2018" /></a></p>
<p><a href="http://bildr.org/blog/wp-content/uploads/2012/03/rfp30n06le-arduino-motor.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/03/rfp30n06le-arduino-motor-400x218.png" alt="" title="rfp30n06le-arduino-motor" width="400" height="218" class="alignleft size-medium wp-image-2019" /></a></p>
<p><a href="http://bildr.org/blog/wp-content/uploads/2012/03/rfp30n06le-arduino-lightbulb.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/03/rfp30n06le-arduino-lightbulb-400x218.png" alt="" title="rfp30n06le-arduino-lightbulb" width="400" height="218" class="alignleft size-medium wp-image-2017" /></a>
</div>
</div>
<div class="wideBody">
<h3>Hooking it up / What&#8217;s the diode used for?</h3>
<p>This circuit is pretty simple. The only part that looks funny is the resistor. This is a <a href="http://wiki.bildr.org/index.php/pull-down resistor">pull-down resistor</a>. The resistor holds the gate low when the arduino does not send a high signal. This is here incase the arduino comes loose, or the wiring is bad it will default to off. You don&#8217;t want this pin to ever be floating as it will trigger on and off.</p>
<p>You can see that in 2 of the 3 illustrations, there is a <a href="http://wiki.bildr.org/index.php/diode">diode</a> parallel to the device we are powering. Any time you are powering a device with a <a href="http://wiki.bildr.org/index.php/coil">coil</a>, such as a <a href="http://wiki.bildr.org/index.php/relay">relay</a>, <a href="http://wiki.bildr.org/index.php/solenoid">solenoid</a>, or <a href="http://wiki.bildr.org/index.php/motor">motor</a>, you need this guy, and don&#8217;t leave home without it. What happens is when you stop powering the coil, a reverse <a href="http://wiki.bildr.org/index.php/voltage">voltage</a>, up to several hundred volts, spikes back. This only lasts a few microseconds, but it is enough to kill our MOSFET. So this <a href="http://wiki.bildr.org/index.php/diode">diode</a> (only allows current to pass one way) is normally facing the wrong direction and does nothing. But when that voltage spikes comes flowing the opposite direction, the diode allows it to flow back to the coil and not the <a href="http://wiki.bildr.org/index.php/transistor">transistor</a>. We will need a diode fast enough to react to the kickback, and strong enough to take the load. A rectifier diode like the <a href="http://wiki.bildr.org/index.php/Diode Rectifier - 1A 50V ">1N4001</a> or <a href="http://www.fairchildsemi.com/ds/SB/SB560.pdf">SB560</a> should do the job. If you are looking for extra protection you could use an <a href="http://en.wikipedia.org/wiki/Opto-isolator">optoisolator</a> between the Arduino and the transistor. An optoisolator optically isolates both sides (high and low power) of the circuit so the high-voltage can not possibly come back to the microcontroller. </p>
<p>Just make sure that protection <a href="http://wiki.bildr.org/index.php/diode">diode</a> is facing the correct way (stripe facing the V+ of device). If it is facing the wrong direction, the device you are trying to power will not work as the <a href="http://wiki.bildr.org/index.php/diode">diode</a> will just allow the current to bypass it.</p>
<h3>Limitations</h3>
<p><a href="http://wiki.bildr.org/index.php/Transistors">Transistors</a> like the RFP30N06LE are really great for controlling high-power devices from your arduino, but they do have some limitations. This current configuration is only useful for switching <a href="http://wiki.bildr.org/index.php/DC">DC</a> current, so don&#8217;t try this with an <a href="http://wiki.bildr.org/index.php/AC">AC</a> source, also MOSFETS have both a <a href="http://wiki.bildr.org/index.php/voltage">voltage</a> and an <a href="http://wiki.bildr.org/index.php/amperage">amperage</a>/current limitation. The RFP30N06LE can handle switching up to 60V, and the amperage is limited to 30A (with heat sink and proper wiring). Anything over a few amps, especially when the current is constant (like in a motor) and not short pulses, I would recommend using a heat-sink. I usually just solder a bent pice of metal to the back, just something to help dissipate the heat. Just note, if you are using more than one of the RFP30N06LEs, you can not solder them to the same heat-sink as the back is connected to the drain of the MOSFET, not the source. If you need to switch AC, I would look at using a <a href="http://wiki.bildr.org/index.php/relay">relay</a> instead.</p>
<h3>Fade it!</h3>
<p>You know the <a href="http://wiki.bildr.org/index.php/PWM">PWM</a> outputs on your Arduino? Yeah, the thing that allows you to <strong>analogWrite(pin, value)</strong>. Well, <a href="http://wiki.bildr.org/index.php/PWM">PWM</a> is not actually an <a href="http://wiki.bildr.org/index.php/analog">analog</a> output. The Arduino is actually pulsing (very quickly) between 0 and 5v so that the average <a href="http://wiki.bildr.org/index.php/voltage">voltage</a> is somewhere in between 0 and 5. Because of this, the <a href="http://wiki.bildr.org/index.php/PWM">PWM</a> can be extended through the <a href="http://wiki.bildr.org/index.php/transistor">transistor</a> (the transistor can only turn on or off, but can do so very quickly) allowing us to fade lights or control the speed of a motor just like if they were connected directly to the Arduino. All you need to do in order to take advantage of this is make sure the MOSFET&#8217;s gate is connected to a <a href="http://wiki.bildr.org/index.php/PWM">PWM</a> pin.
</div>
<h3>Code</h3>
<p>You don&#8217;t really need code for this, you just send a HIGH signal to the gate pin, and BAM&#8230; it works. But I threw this together for you so you can test it fading with the PWM- This code fades in a sin wave like the video below. (only useful for a motor or light obviously).</p>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">//////////////////////////////////////////////////////////////////</span>
<span class="co1">//©2011 bildr</span>
<span class="co1">//Released under the MIT License - Please reuse change and share</span>
<span class="co1">//Simple code to output a PWM sine wave signal on pin 9</span>
<span class="co1">//////////////////////////////////////////////////////////////////</span>

<span class="co2">#define fadePin 3</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>fadePin<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>

  <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0">&lt;</span><span class="nu0">360</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
    <span class="co1">//convert 0-360 angle to radian (needed for sin function)</span>
    <span class="kw4">float</span> rad <span class="sy0">=</span> DEG_TO_RAD <span class="sy0">*</span> i<span class="sy0">;</span>

    <span class="co1">//calculate sin of angle as number between 0 and 255</span>
    <span class="kw4">int</span> sinOut <span class="sy0">=</span> <span class="kw3">constrain</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw3">sin</span><span class="br0">&#40;</span>rad<span class="br0">&#41;</span> <span class="sy0">*</span> 128<span class="br0">&#41;</span> <span class="sy0">+</span> 128<span class="sy0">,</span> 0<span class="sy0">,</span> 255<span class="br0">&#41;</span><span class="sy0">;</span> 

    <span class="kw3">analogWrite</span><span class="br0">&#40;</span>fadePin<span class="sy0">,</span> sinOut<span class="br0">&#41;</span><span class="sy0">;</span>

    <span class="kw3">delay</span><span class="br0">&#40;</span>15<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>

<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
<h3>Video</h3>
<p>This video is showing the capabilities of PWM with the RFP30N06LE.  The light, though it looks like a standard house light, is actually a <a href="http://www.amazon.com/15-Watt-Frosted-Appliance-Ceiling/dp/B0042F8HLS">15W 12V DC light</a>.</p>
<p><iframe src="http://player.vimeo.com/video/4402701?byline=0&amp;portrait=0" width="949" height="534" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2012/03/rfp30n06le-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Triple Axis Magnetometer HMC5883L + Arduino</title>
		<link>http://bildr.org/2012/02/hmc5883l_arduino/</link>
		<comments>http://bildr.org/2012/02/hmc5883l_arduino/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 13:46:58 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[HMC5883L]]></category>
		<category><![CDATA[Magnetometer]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1922</guid>
		<description><![CDATA[
One of the first articles we did was on the hmc6352 digital compass. Well this is his older brother (or younger but smarter). I really don&#8217;t know what to say about the HMC5883L other than it is a three axis magnetometer, so it is capable of sensing in 3 directions. That doesn&#8217;t mean that it [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/08/HMC5883L.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
One of the first articles we did was on <a href="http://bildr.org/2011/01/hmc6352/">the hmc6352 digital compass</a>. Well this is his older brother (or younger but smarter). I really don&#8217;t know what to say about the HMC5883L other than it is a three axis magnetometer, so it is capable of sensing in 3 directions.</p>
<p>That doesn&#8217;t mean that it is tilt compensated, because you really don&#8217;t know how it is orientated when the reading comes in. For that, you would need to combine this with an accelerometer to do that. But this can get you one step closer. <b>If you are looking at using this as a digital compass, make sure to read the following section.</b></p>
<h4>Magnetic Declination</h4>
<p>Something I found interesting and obvious once I thought about it, is that all compasses point to <a href="http://en.wikipedia.org/wiki/North_Magnetic_Pole">magnetic north</a>, and not <a href="http://en.wikipedia.org/wiki/True_north">true north</a>. The difference between them is called <a href="http://en.wikipedia.org/wiki/Magnetic_declination">Magnetic declination</a>. And how much they vary depends on where you are, and&#8230; when it is, because as weird as it is, it changes over time (<a href="http://upload.wikimedia.org/wikipedia/commons/4/43/Earth_Magnetic_Field_Declination_from_1590_to_1990.gif">awesome animation of that</a>). You can <a href="http://www.ngdc.noaa.gov/geomagmodels/Declination.jsp">look up your Magnetic declination here</a>.</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2012/01/HMC5883L_arduino_hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/01/HMC5883L_arduino_hookup-400x342.png" alt="" title="HMC5883L_arduino_hookup" width="400" height="342" class="alignleft size-medium wp-image-1923" /></a></p>
</div>
</div>
<div class="wideBody">
<h3>Hooking it up</h3>
<p>Hooking you HMC5883L up to your arduino is pretty simple. The HMC5883L is an <a href="http://wiki.bildr.org/index.php/I2C">I2C</a> device, a type 2-wire serial connection, so we just need to connect the SDA (Data) and SCL (Clock) lines to your Arduino for communication. On your Arduino (everything but the <a href="http://wiki.bildr.org/index.php/Arduino_Mega ">mega</a>) SDA is on analog pin 4, and SCL is on analog pin 5. On an arduino mega, SDA is digital 20, and SCL is digital 21. (The Arduino Leonardo will also be different). Other than these 2 lines, we just need to connect power(3.3v), ground and we are all set.</p>
</div>
<div class="columnBody">
<div class="leftColumn">
<h3>Code</h3>
<p>The code for the HMC5883Lis a bit more complex than his single-axis brother, and the readings from it come in a few different forms, so we will be using a library to achieve this.</p>
<p>To make this code work, <strong>before you load the code, or even open the Arduino program</strong>, we need to place the &#8220;HMC5883L&#8221; folder into your Arduino Library. If you don’t know where that is by default, Look to the right.</p>
<p>If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.</p>
</div>
<div class="rightColumn">
<h3>Default Library Folder Location</h3>
<p><span style="font-size: 10px; line-height:12px;"><strong>On your Mac:</strong>: In (home directory)/Documents/Arduino/libraries<br />
<strong>On your PC:</strong>: My Documents -> Arduino -> libraries<br />
<strong>On your Linux box:</strong>: (home directory)/sketchbook/libraries<br />
</span></p>
</div>
</div>

	<div class="clear">
	<script src="http://code.bildr.org/render/HMC5883L/arduino.js"></script>
	</div>
	
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2012/02/hmc5883l_arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tilt Sensing with the RPI-1031 + Arduino</title>
		<link>http://bildr.org/2012/02/rpi-1031_arduino/</link>
		<comments>http://bildr.org/2012/02/rpi-1031_arduino/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 13:16:29 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Tilt Sensor]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1909</guid>
		<description><![CDATA[
Once in a while something comes out that I think is going to be really awesome, but when you get it, it is just so so. Im sure you all know what I mean&#8230; But yeah&#8230; This is one of those. The RPI-1031 available from sparkfun is a pretty simple (heck, it is dead simple) [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2012/01/tilt.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<p>Once in a while something comes out that I think is going to be really awesome, but when you get it, it is just so so. Im sure you all know what I mean&#8230; But yeah&#8230; This is one of those.</p>
<p>The RPI-1031 <a href="http://www.sparkfun.com/products/10621">available</a> from <a href="http://www.sparkfun.com/">sparkfun</a> is a pretty simple (heck, it is dead simple) sensor for sensing when it is tilted. And it does this really well. But it seriously only does that. If it is not tilted, it freaks out and reports tilt anyways.</p>
<p>It actually just uses a metal ball that rolls around inside (you can hear it moving around when you tip it). Because of how it is made, the ball is always up against one side even when it is flat. Unfortunately this means you can never know the difference between a reading, and it being flat, only changes in reading.</p>
<h3>Hooking it up</h3>
<p>This is as simple as it gets I guess. Just power and ground, then connect the 2 digital pins and you are done. These 2 digital pins will output LOW/LOW, LOW/HIGH, HIGH/LOW and HIGH/HIGH depending on the wall it is touching. Again, even if it is flat, it is still touching a wall.</p>
<h3>Code</h3>
<p>The code for this guy is really simple, it just checks 2 pins, to see what side is being touched &#8211; The simple function just takes the 2 digital outputs and returns 0,1,2 or 3 depending on the side. </p>
</div>
<div class="rightColumn">
<a href="http://bildr.org/blog/wp-content/uploads/2012/01/RPI-1031_arduino_hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/01/RPI-1031_arduino_hookup-400x597.png" alt="" title="RPI-1031_arduino_hookup" width="400" height="597" class="alignleft size-medium wp-image-1910" /></a>
</div>
</div>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">//For the RPI-1031 - http://www.sparkfun.com/products/10621 </span>

<span class="kw4">int</span> tilt_s1 <span class="sy0">=</span> <span class="nu0">2</span><span class="sy0">;</span>
<span class="kw4">int</span> tilt_s2 <span class="sy0">=</span> <span class="nu0">3</span><span class="sy0">;</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
 <span class="kw3">pinMode</span><span class="br0">&#40;</span>tilt_s1<span class="sy0">,</span> <span class="kw2">INPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
 <span class="kw3">pinMode</span><span class="br0">&#40;</span>tilt_s2<span class="sy0">,</span> <span class="kw2">INPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
 <span class="kw3">Serial</span>.<span class="me1">begin</span><span class="br0">&#40;</span>9600<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw4">int</span> position <span class="sy0">=</span> getTiltPos<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">Serial</span>.<span class="me1">println</span><span class="br0">&#40;</span>position<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">delay</span><span class="br0">&#40;</span>200<span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//only here to slow down the serial output</span>
<span class="br0">&#125;</span>

<span class="kw4">int</span> getTiltPosition<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
   <span class="kw4">int</span> s1 <span class="sy0">=</span> <span class="kw3">digitalRead</span><span class="br0">&#40;</span>tilt_s1<span class="br0">&#41;</span><span class="sy0">;</span>
   <span class="kw4">int</span> s2 <span class="sy0">=</span> <span class="kw3">digitalRead</span><span class="br0">&#40;</span>tilt_s2<span class="br0">&#41;</span><span class="sy0">;</span>
   <span class="kw1">return</span> <span class="br0">&#40;</span>s1 <span class="sy0">&lt;&lt;</span> 1<span class="br0">&#41;</span> <span class="sy0">|</span> s2<span class="sy0">;</span> <span class="co1">//bitwise math to combine the values</span>
<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2012/02/rpi-1031_arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sensing color with the ADJD-S311 + Arduino</title>
		<link>http://bildr.org/2012/01/adjd-s311_arduino/</link>
		<comments>http://bildr.org/2012/01/adjd-s311_arduino/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 13:41:05 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[adjd-S311]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[color]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1928</guid>
		<description><![CDATA[
A year ago we had an article called Sensing color with the ADJD-S371. Well the ADJD-S371 is long gone, and its replacement is the ADJD-S311 (breakout board available from sparkfun). It is basically the same all around, so without shame, I will be copying a lot of that article, because&#8230; Why reinvent the wheel? A [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2012/01/adjd-S311.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
A year ago we had an article called <a href="http://bildr.org/2011/01/adjd-s371-tutorial/">Sensing color with the ADJD-S371</a>. Well the ADJD-S371 is long gone, and its replacement is the <a href="http://www.sparkfun.com/products/10701">ADJD-S311</a> (breakout board available from sparkfun). It is basically the same all around, so without shame, I will be copying a lot of that article, because&#8230; Why reinvent the wheel? </p>
<p>A few things you should know about the ADJD-S311 before we dive in too deep: I have never been able to get perfect color sampling from this guy without limiting the colors it would detect to just 6, and accurately reproducing color on an <a href="http://wiki.bildr.org/index.php/LED">LED</a> is not as simple as one would hope. The color reading from the sensor could be spot on, but the reproduced color on the LED may be way off. (you can blame your eyes and the LEDs)</p>
<h3>Hooking it up</h3>
<p>The ADJD-S311 is an <a href="http://wiki.bildr.org/index.php/I2C">I2C</a> device (I2C is a 2-wire serial connection), so we just need to connect the SDA (Data) and SCL (Clock) lines to your Arduino for communication. On your Arduino (everything but the <a href="http://wiki.bildr.org/index.php/Arduino_Mega ">mega</a>) SDA is on analog pin 4, and SCL is on analog pin 5. On an arduino mega, SDA is digital 20, and SCL is digital 21. (The Arduino Leonardo will also be different). Other than these 2 lines, we just need to connect power(3.3v), ground, and the onboard LED to digital 2 (you can change that in code if you want).</p>
<p>The ADJD-S311 has 4 sensors built into it to detect Red, Green, Blue, and Clear. It reports back an individual reading from each sensor. The white, or clear, sensor is mainly for sensing brightness.</p>
</div>
<div class="rightColumn">
<a href="http://bildr.org/blog/wp-content/uploads/2012/01/ADJD-S311-Arduino-Hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2012/01/ADJD-S311-Arduino-Hookup-400x579.png" alt="" title="ADJD-S311-Arduino-Hookup" width="400" height="579" class="alignleft size-medium wp-image-2008" /></a>
</div>
</div>
<div class="columnBody">
<div class="leftColumn">
The ADJD-S311 is designed to sense reflected light using the onboard LED, but I have found that by turning the onboard LED off, it works even better for sensing projected light (like from your monitor or projector). If you are interested in using the sensor for sensing reflected colors, you want the sensor to be about 1-2mm from the subject so the onboard LED can bounce off the material and back to the sensor. </p>
</div>
<div class="rightColumn">
<a href="http://bildr.org/blog/wp-content/uploads/2011/01/led-bounce.png"><br />
<img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/01/led-bounce.png"/></a>
</div>
</div>
<div class="wideBody">
<h3>Code</h3>
<p>The code for this guy is long and obnoxious, so we made a library out of it. This code is based on the sparkfun code, that was based on the old bildr code, that was based on the code by Marcus over at <a href="http://interactive-matter.eu/">Interactive Matter</a>. I love open source!</p>
<p>This library is really simple, you can call calibrate to calibrate to white (make sure you have a white objet or light source in front of it when you do this), you can turn the LED on and off, and you can read. Reading gives you back a RGBC (red,green,blue,clear) variable that has the readings from the sensor. See the code for how to use it.
</p></div>
<div class="columnBody">
<div class="leftColumn">
<p>To make this code work, <strong>before you load the code, or even open the Arduino program</strong>, we need to place the &#8220;ADJDS311&#8243; folder into your Arduino Library. If you don’t know where that is by default, Look to the right.</p>
<p>If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.</p>
</div>
<div class="rightColumn">
<h3>Default Library Folder Location</h3>
<p><span style="font-size: 10px; line-height:12px;"><strong>On your Mac:</strong>: In (home directory)/Documents/Arduino/libraries<br />
<strong>On your PC:</strong>: My Documents -> Arduino -> libraries<br />
<strong>On your Linux box:</strong>: (home directory)/sketchbook/libraries<br />
</span></p>
</div>
</div>

	<div class="clear">
	<script src="http://code.bildr.org/render/ADJD-S311/arduino.js"></script>
	</div>
	
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2012/01/adjd-s311_arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickly: KS0108B Graphic LCD 128&#215;64 + Arduino</title>
		<link>http://bildr.org/2011/10/ks0108b-arduino/</link>
		<comments>http://bildr.org/2011/10/ks0108b-arduino/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 03:32:58 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[KS0108B]]></category>
		<category><![CDATA[LCD]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1829</guid>
		<description><![CDATA[
This is an incredibly quick post, and it is actually here simply because this thing was a pain to figure out how to hook it up. But, I wasn&#8217;t able to do anything with it more than the Arduino library was able to do out of the box. So, if you have this screen sold [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/10/KS0108B.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
This is an incredibly quick post, and it is actually here simply because <a href="http://www.sparkfun.com/products/710">this thing</a> was a pain to figure out how to hook it up. But, I wasn&#8217;t able to do anything with it more than the Arduino library was able to do out of the box.</p>
<p>So, if you have <a href="http://www.sparkfun.com/products/710">this screen</a> sold from SparkFun, and you wanted to hook it up to your Arduino, here is how you do that.</p>
<h2>Hooking it up</h2>
<p>LCD screens of this type are more difficult to work with than ones specifically designed for text. With these you have individual pixel control, so you can draw completely custom graphics with it. But it also means you have to keep track of a lot of pixels, hence all the extra wires. Making matters worse, many of these screens actually require a negative voltage on the dimmer pot to get an image from it. But luckily this particular one includes all the circuitry needed.</p>
<p><strong>Note: this is hookup for the non-mega Arduino. The Arduino Megas actually connect differently to this screen. </strong> Just make sure to connect all the wires to the Arduino as seen on the right. You can click on the image to get a closer look.</p>
<p>To drive this graphic display you need a library, and for that, Arduino has you covered: <a href="http://www.arduino.cc/playground/Code/GLCDks0108">http://www.arduino.cc/playground/Code/GLCDks0108</a></p>
<p>I know this is a lame excuse for an article. But like I said, it is just here incase you need to know how to hook it up.</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/10/KS0108B-hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/10/KS0108B-hookup-400x511.png" alt="" title="KS0108B-hookup" width="400" height="511" class="alignleft size-medium wp-image-1833" /></a></p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/10/ks0108b-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>High Sensitivity Light Sensor TSL230R + Arduino</title>
		<link>http://bildr.org/2011/09/tsl230r-arduino/</link>
		<comments>http://bildr.org/2011/09/tsl230r-arduino/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 12:03:37 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Light]]></category>
		<category><![CDATA[TSL230R]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1642</guid>
		<description><![CDATA[
A while back we covered the TEMT6000, a great little analog sensor for getting ambient light readings when you need something a bit more sensitive than a simple Photoresistor. Well in the spirit of documenting everything we can get our hands on, this week we will be taking the sensitivity to the next level with [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/08/TSL230R.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<p>A while back we <a href="http://bildr.org/2011/06/temt6000_arduino/">covered</a> the <a href="http://wiki.bildr.org/index.php/TEMT6000">TEMT6000</a>, a great little <a href="http://wiki.bildr.org/index.php/analog">analog</a> sensor for getting ambient light readings when you need something a bit more sensitive than a simple <a href="http://wiki.bildr.org/index.php/Photoresistor">Photoresistor</a>. Well in the spirit of documenting everything we can get our hands on, this week we will be taking the sensitivity to the next level with the <a href="http://www.sparkfun.com/products/8940">TSL230R Light Intensity Sensor</a>. </p>
<p>I actually bought this a long time ago simply because it looked awesome. I mean really&#8230; How often do you see a clear chip? That was enough, I had to have it. Well, aside from looking downright awesome, it is also an incredibly sensitive digital light sensor. This awesome guy is sensitive enough to be used for photography light metering, or be able to tell when someone walks by a lamp on the other side of the room. Also, to top it all off, it actually has 3 sensitivity settings, so if you are in a low-light situation, it has you covered!</p>
</div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/TSL230R-hookup.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/TSL230R-hookup-400x228.png" alt="" title="TSL230R-hookup" width="400" height="228" class="alignleft size-medium wp-image-1648" /></a></p>
</div>
</div>
<div class="wideBody">
<h3>Hooking it up</h3>
<p>So the TSL230R is actually pretty simple, it really only has power, and signal out. But it has a bunch of extra pins so you can change sensitivity and output type if you want. We don&#8217;t care about changing the output format, but I did want to keep the &#8220;sensitivity select&#8221; open for you incase you need it.</p>
<p>So just connect it up to your Arduino as shown in the image. Make sure to take note of either the larger pin in the bottom left (pin 4) or the circle on the top left (pin 1) to make sure you have it facing the right way.</p>
<h3>Code</h3>
<p><strong>Before we get to far!</strong> If you are looking for a photo-ready reading from this sensor, in ISO, ASA, Lux or other, you are in the wrong place. You want this article here: <a href="http://roamingdrone.wordpress.com/2008/11/13/arduino-and-the-taos-tsl230r-light-sensor-getting-started/">Arduino and the Taos TSL230R Light Sensor: Getting Started</a>. </p>
<p>If you want to be able to check for changes in light, and have some simpler code to tame this beast, keep reading. </p>
<p>So what the TSL230R does, is it sends out a digital <a href="http://wiki.bildr.org/index.php/Square Wave">Square Wave</a> (simple up and down) signal that gets longer with less light, and shorter with more light. So we need to look at how long the wave is so we can figure out the brightness. We will actually be taking a few samples and averaging them so the signal will be more accurate and smoother. If you are looking at using a threshold to trigger something, you may want to up the number of samples it takes so it is even smoother and you don&#8217;t get false positives. (but this will slow down how long it takes to read)</p>
<p>This code simply checks the output of the TSL230R, and prints to the Arduino&#8217;s software serial terminal. With higher readings meaning brighter. You can change the sensitivity of the TSL230R as well. In the sketch, under setupTSL230, you can set TSL230_s0, and TSL230_s1 HIGH or LOW to make the sensor more or less sensitive to light. Great for low-light, or ultra-bright situations.</p>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;"><span class="co1">// Reports the frequency from the TSL230, higher number means brighter</span>
<span class="co1">// Part: http://www.sparkfun.com/products/8940</span>
<span class="co1">// Article:  http://bildr.org/2011/08/tsl230r-arduino/ </span>

<span class="kw4">int</span> TSL230_Pin <span class="sy0">=</span> <span class="nu0">4</span><span class="sy0">;</span> <span class="co1">//TSL230 output</span>
<span class="kw4">int</span> TSL230_s0 <span class="sy0">=</span> <span class="nu0">3</span><span class="sy0">;</span> <span class="co1">//TSL230 sensitivity setting 1</span>
<span class="kw4">int</span> TSL230_s1 <span class="sy0">=</span> <span class="nu0">2</span><span class="sy0">;</span> <span class="co1">//TSL230 sensitivity setting 2</span>

<span class="kw4">int</span> TSL230_samples <span class="sy0">=</span> <span class="nu0">6</span><span class="sy0">;</span> <span class="co1">//higher = slower but more stable and accurate</span>

<span class="kw4">void</span> setup<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw3">Serial</span>.<span class="me1">begin</span><span class="br0">&#40;</span>9600<span class="br0">&#41;</span><span class="sy0">;</span>
  setupTSL230<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">void</span> loop<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>

  <span class="kw4">float</span> lightLevel <span class="sy0">=</span> readTSL230<span class="br0">&#40;</span>TSL230_samples<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">Serial</span>.<span class="me1">println</span><span class="br0">&#40;</span>lightLevel<span class="br0">&#41;</span><span class="sy0">;</span>

<span class="br0">&#125;</span>

<span class="kw4">void</span> setupTSL230<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>TSL230_s0<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">pinMode</span><span class="br0">&#40;</span>TSL230_s1<span class="sy0">,</span> <span class="kw2">OUTPUT</span><span class="br0">&#41;</span><span class="sy0">;</span> 

  <span class="co1">//configure sensitivity - Can set to</span>
  <span class="co1">//S1 LOW  | S0 HIGH: low</span>
  <span class="co1">//S1 HIGH | S0 LOW:  med</span>
  <span class="co1">//S1 HIGH | S0 HIGH: high</span>

  <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>TSL230_s1<span class="sy0">,</span> <span class="kw2">LOW</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw3">digitalWrite</span><span class="br0">&#40;</span>TSL230_s0<span class="sy0">,</span> <span class="kw2">HIGH</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>

<span class="kw4">float</span> readTSL230<span class="br0">&#40;</span><span class="kw4">int</span> samples<span class="br0">&#41;</span><span class="br0">&#123;</span>
<span class="co1">//sample light, return reading in frequency</span>
<span class="co1">//higher number means brighter</span>

  <span class="kw4">float</span> start <span class="sy0">=</span> <span class="kw3">micros</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="kw4">int</span> readings <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span>

  <span class="kw1">while</span><span class="br0">&#40;</span>readings <span class="sy0">&lt;</span> samples<span class="br0">&#41;</span><span class="br0">&#123;</span>
   <span class="kw3">pulseIn</span><span class="br0">&#40;</span>TSL230_Pin<span class="sy0">,</span> <span class="kw2">HIGH</span><span class="br0">&#41;</span><span class="sy0">;</span>
   readings <span class="sy0">++;</span>
  <span class="br0">&#125;</span>

  <span class="kw4">float</span> length <span class="sy0">=</span> <span class="kw3">micros</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">-</span> start<span class="sy0">;</span>
  <span class="kw4">float</span> freq <span class="sy0">=</span> <span class="br0">&#40;</span>1000000 <span class="sy0">/</span> <span class="br0">&#40;</span>length <span class="sy0">/</span> samples<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">10</span><span class="sy0">;</span>

  <span class="kw1">return</span> freq<span class="sy0">;</span>
<span class="br0">&#125;</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/09/tsl230r-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaying on Paper &#8211; Thermal Printer + Arduino</title>
		<link>http://bildr.org/2011/08/thermal-printer-arduino/</link>
		<comments>http://bildr.org/2011/08/thermal-printer-arduino/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 11:48:03 +0000</pubDate>
		<dc:creator>ameyer</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[thermal printer]]></category>

		<guid isPermaLink="false">http://bildr.org/?p=1656</guid>
		<description><![CDATA[
The following code and library are compatible with arduino software 1.0+ ONLY. You can download the newest version of the arduino software here. Outputting data can be extremely useful, and typically when we look at doing this, it is either to the Arduino&#8217;s serial terminal, or to some sort of display. But what about making [...]
]]></description>
			<content:encoded><![CDATA[<p><img class="noFrame" src="http://bildr.org/blog/wp-content/uploads/2011/08/thermalPrinter.jpg"/></p>
<div class="columnBody">
<div class="leftColumn">
<div class="intro">
<strong>The following code and library are compatible with arduino software 1.0+ ONLY. You can download the newest version of the <a href="http://www.arduino.cc/en/Main/Software">arduino software here.</a></strong>
</div>
<p>Outputting data can be extremely useful, and typically when we look at doing this, it is either to the Arduino&#8217;s serial terminal, or to some sort of display. But what about making physical copies of the data? So a few months back, <a href="http://sparkfun.com">SparkFun</a> started selling a <a href="http://www.sparkfun.com/products/10438">thermal printer that you could connect to a microcontroller</a> (<a href="http://www.adafruit.com/products/597">or via adafruit</a> ). That same day my brain filled with crazy thing you could do with it, like a giant fortune cookie that could print your fortune on the fly.</p>
<p>Anyways&#8230; If you dont know about thermal printers, they are most often the printers your store&#8217;s receipts are printed on. The reason for this is that they dont use ink, or use a cartridge of any sort. The paper it prints on turns black when heated. So this printer simply applies heat where another printer would apply ink. Eventually the printers head will wear out, but this after several miles of printing. Yes, miles &#8211; about 30 of them. So given that the rolls of paper are 34ft long, you can print about 4,600 rolls before the print head dies, meaning for most of us, you will never see that happen.</p>
<h3>Hooking it up</h3>
<p>So this printer can be powered off of 5V, but NOT the 5v pin on your arduino, and no via USB. It uses very little power when it is is just sitting by, but uses around a full amp when it is printing! And because the most USB can handle is half of that, we need an external power supply. Something between 5 and 9V, and a minimum of 1400ma output (larger is fine). I found that powering the printer with 9v, it printed much faster, and slightly darker than 5v, and if you have it available, I recommend using 9v.</p>
<p>There are two ways of connecting the power supply as shown in the illustrations. You can either power your arduino and the printer separately, or you can power the arduino, and power the printer off of the arduino. </p>
<p>To do the latter, the printer&#8217;s power wire (red) needs to connect to the VIN pin on the arduino, not the 5v pin. The reason is that the 5v pin goes through a regulator and is not meant to supply this kind of power, but the VIN pin is directly connected to the power input on the arduino. So it can supply much more.</p>
<p>Now just connect the rest of the wires as shown.</p>
<h3>Code</h3>
<p>The printer needs a serial connection to the arduino. And normally that would mean we would connect to digital pins 0,1 but, if we did this, anything you printed to the serial terminal for debugging or otherwise the printer would see and possibly print out. We don&#8217;t want that, so we will be using a libraty so that you can keep those pins free.</p>
<p>This printer has a huge amount of features. 2 different barcode, text output, size settings etc, and each one needs a new configuration to get it working. So we created a library for this so that you could keep your code clean, and simple.
</p></div>
<div class="rightColumn">
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/Thermal-Printer-arduino-21.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/Thermal-Printer-arduino-21-400x464.png" alt="" title="Thermal-Printer-arduino-2" width="400" height="464" class="alignleft size-medium wp-image-1663" /></a></p>
<p><a href="http://bildr.org/blog/wp-content/uploads/2011/08/Thermal-Printer-arduino-1.png"><img src="http://bildr.org/blog/wp-content/uploads/2011/08/Thermal-Printer-arduino-1-400x454.png" alt="" title="Thermal-Printer-arduino-1" width="400" height="454" class="alignleft size-medium wp-image-1659" /></a></p>
</div>
</div>
<div class="columnBody">
<div class="leftColumn">
<p>To make this code work, <strong>before you load the code, or even open the Arduino program</strong>, we need to place the &#8220;Thermal&#8221; folder into your Arduino Library. If you don’t know where that is by default, Look to the right.</p>
<p>If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.</p>
</div>
<div class="rightColumn">
<h3>Default Library Folder Location</h3>
<p><span style="font-size: 10px; line-height:12px;"><strong>On your Mac:</strong>: In (home directory)/Documents/Arduino/libraries<br />
<strong>On your PC:</strong>: My Documents -> Arduino -> libraries<br />
<strong>On your Linux box:</strong>: (home directory)/sketchbook/libraries<br />
</span></p>
</div>
</div>

	<div class="clear">
	<script src="http://code.bildr.org/render/Thermal Printer/arduino.js"></script>
	</div>
	
<div class="wideBody">
<h3>darkness And Speed Calibration</h3>
<p>If you want to get a little more speed, or darkness out of the printer, you can change some settings in the thermal.cpp file of the Thermal library.</p>
<div class="codesnip-container" >
<div class="codeHead">
				<a class="copy" href="#">Copy Code</a>
			</div>
<pre class="arduino codesnip" style="font-family:monospace;">heatTime <span class="sy0">=</span> <span class="nu0">120</span><span class="sy0">;</span> <span class="co1">//80 is default from page 23 of datasheet. Controls speed of printing and darkness</span>
heatInterval <span class="sy0">=</span> <span class="nu0">50</span><span class="sy0">;</span> <span class="co1">//2 is default from page 23 of datasheet. Controls speed of printing and darkness</span></pre>
<div class="codeFoot">
				Unless otherwise stated, this code is released under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> &#8211; Please use, change and share it.
			</div>
</p></div>
<p>Changing heatTime and heatInterval to lower values, will yield a faster, but lighter printing, and raising them will yield a slower, but  darker printing. If you are running off of 5V, and find the printing too light, try changing both values to 255.</p>
<p>You can make changes to the file with the arduino sketch open. Just save the Thermal.cpp file and re-upload the sketch to see the changes.</p>
<h4>Help expand the library</h4>
<p>We would love help expanding the library if you are interested. We would like to add to support for bitmap printing and other text setting. Also there may be a better way to set many of the settings than we are now. If you are interested in helping, let us know in the forum.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bildr.org/2011/08/thermal-printer-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

