<?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>Brett&#039;s Build Log &#187; software</title>
	<atom:link href="http://brettinman.com/tag/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://brettinman.com</link>
	<description>Hardware tinkering with the occasional bit of software</description>
	<lastBuildDate>Thu, 11 Mar 2010 09:24:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Sketching with the USB Power Shield</title>
		<link>http://brettinman.com/2009/07/16/sketching-with-the-usb-power-shield/</link>
		<comments>http://brettinman.com/2009/07/16/sketching-with-the-usb-power-shield/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 05:04:25 +0000</pubDate>
		<dc:creator>brettinman</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[USB Power Shield]]></category>
		<category><![CDATA[Woot-Off Lights Project]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[relay]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://brettinman.com/?p=132</guid>
		<description><![CDATA[So you have a USB Power Shield (or anything that uses a latching relay). How do you control it in an Arduino Sketch? Normal relays are pretty simple &#8211; supply voltage/current to the coil and it generates a magnetic field, which pushes the switch to the ON position. You only need one pin to run [...]]]></description>
			<content:encoded><![CDATA[<p>So you have a USB Power Shield (or anything that uses a latching relay). How do you control it in an Arduino Sketch?</p>
<p>Normal relays are pretty simple &#8211; supply voltage/current to the coil and it generates a magnetic field, which pushes the switch to the ON position. You only need one pin to run it, although you may need a transistor to supply more current because most microcontrollers can only supply 50mA, which often isn&#8217;t enough current to create a magnetic field to move the switch. You must maintain the current to keep the switch on.</p>
<p>Latching relays are similar to this, but once put into position, it &#8220;latches&#8221; there and requires no further current to stay in that position. This uses less power and makes the switching more reliable &#8211; if there is a decrease in current supplied, the switch will still stay in position, unlike the regular relay which could flicker. The downside is that the common types require two pins. Sending current in one direction switches on, and reversing the current switches it off.</p>
<p>So how do you control it? Set two pins to be outputs (the USB Power Shield uses 12/11 and 10/9 for the two relays). Write one pin LOW and the other pin HIGH. After a sufficient time to make the switching happen (50ms or less, check the datasheet for the relay), switch the HIGH pin back to low. This gives the magnetic field a place to sink, as well as making sure no more current is supplied to the coil, preventing overheating and wasting power. </p>
<p>Ideally, with a normal relay you&#8217;d like to force the stored current from the magnetic field back through the coil by using a flyback diode across it, but with a latched relay and current running in both directions, a diode would be needed in each direction. And that would simply cause a short circuit both ways. I&#8217;ve tested the relays used in the USB Power Shield and they don&#8217;t harm the Arduino (even over thousands of cycles) so this isn&#8217;t a huge worry here.</p>
<p>Below is some sample code for using the USB Power Shield with an Arduino. <span id="more-132"></span></p>
<p>Simply set up the pins for relay1 and relay2:<br />
<code>//give the pins names<br />
int relay11 = 12;<br />
int relay12 = 11;<br />
int relay21 = 10;<br />
int relay22 = 9;<br />
void setup()<br />
{<br />
//set the pins to outputs<br />
  pinMode(relay11, OUTPUT);<br />
  pinMode(relay12, OUTPUT);<br />
  pinMode(relay21, OUTPUT);<br />
  pinMode(relay22, OUTPUT);<br />
//make sure they start in the off position<br />
  relay1(false);<br />
  relay2(false);<br />
  // do other stuff<br />
}</code></p>
<p>Then add these functions to turn the relays on and off:<br />
<code>void relay1 (bool state)<br />
{<br />
  if (state)<br />
  {<br />
    digitalWrite(relay12,LOW); //set the current in one direction<br />
    digitalWrite(relay11,HIGH);<br />
    delay(50); //hold long enough to switch<br />
    digitalWrite(relay11,LOW);   //set both to ground to stop current<br />
  }<br />
  else<br />
  {<br />
    digitalWrite(relay11,LOW);<br />
    digitalWrite(relay12,HIGH);<br />
    delay(50);<br />
    digitalWrite(relay12,LOW);<br />
  }<br />
}<br />
void relay2 (bool state)<br />
{<br />
  if (state)<br />
  {<br />
    digitalWrite(relay22,LOW);<br />
    digitalWrite(relay21,HIGH);<br />
    delay(50);<br />
    digitalWrite(relay21,LOW);<br />
  }<br />
  else<br />
  {<br />
    digitalWrite(relay21,LOW);<br />
    digitalWrite(relay22,HIGH);<br />
    delay(50);<br />
    digitalWrite(relay22,LOW);<br />
  }<br />
}</code></p>
<p>Then simply write your main loop to do whatever you wish. Call relay1(true) to turn relay1 on, call relay2(false) to turn relay2 off, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://brettinman.com/2009/07/16/sketching-with-the-usb-power-shield/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Woot-Off Lights &#8211; in Python</title>
		<link>http://brettinman.com/2009/06/03/woot-off-lights-in-python/</link>
		<comments>http://brettinman.com/2009/06/03/woot-off-lights-in-python/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 01:07:56 +0000</pubDate>
		<dc:creator>brettinman</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Woot-Off Lights Project]]></category>
		<category><![CDATA[diy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[serial]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[wootofflights]]></category>

		<guid isPermaLink="false">http://brettinman.com/?p=70</guid>
		<description><![CDATA[The Woot-Off Lights project continues to slowly progress. Over the weekend we moved over to Python for the coding, since that&#8217;s the language Alex is most familiar with right now (especially in networking). Serial control of the lights in Python took longer than expected &#8211; we could have saved over an hour of troubleshooting had [...]]]></description>
			<content:encoded><![CDATA[<p>The Woot-Off Lights project continues to slowly progress. Over the weekend we moved over to Python for the coding, since that&#8217;s the language Alex is most familiar with right now (especially in networking). </p>
<p>Serial control of the lights in Python took longer than expected &#8211; we could have saved over an hour of troubleshooting had we simply waited two seconds between opening the serial connection and transmitting the first byte (allowing the connection protocols time to complete), but instead we tried half a dozen Python libraries, thinking the problem was somewhere in the code library. Lesson learned &#8211; the exact specifics of interaction between software and hardware is not to be ignored.</p>
<p>We then were able to force the Woot Tracker to update it&#8217;s cache, pull down the XML file generated by the tracker, parse it for the value we are looking for (wootoff, true or false), and take action based upon it. </p>
<p>Now we&#8217;re simply trying to figure out how to package the program into an .exe that can be hidden in the tray, and also figure out how the timing should work &#8211; I would prefer that my server didn&#8217;t get a ton of update requests at the same time, especially during a Woot-Off. Right now it looks like we&#8217;ll run a custom version of the software on our machine to update the tracker, and the software we distribute publicly will simply pull down the XML (without first updating the cache, because our software has already done so).</p>
<p>On the hardware side of things, I&#8217;ve consolidated the driver circuitry onto a small piece of protoboard that pops into the Arduino like a shield. I&#8217;ve also cut up an Altoids tin and housed the assembly inside of it. Don&#8217;t forget the isolate the top/bottom of the board with electrical tape or similar so the metal case doesn&#8217;t short anything.</p>
<p>Here&#8217;s a few pictures of the assembly, with the lights being controlled via the Python application.</p>
<p style="text-align: center;">
<div class="ngg-galleryoverview" id="ngg-gallery-1-70">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-1" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://brettinman.com/blog/wp-content/gallery/tin/tin1.jpg" title=" " rel="lightbox[set_1]" >
								<img title="tin1.jpg" alt="tin1.jpg" src="http://brettinman.com/blog/wp-content/gallery/tin/thumbs/thumbs_tin1.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-2" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://brettinman.com/blog/wp-content/gallery/tin/tin2.jpg" title=" " rel="lightbox[set_1]" >
								<img title="tin2.jpg" alt="tin2.jpg" src="http://brettinman.com/blog/wp-content/gallery/tin/thumbs/thumbs_tin2.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-3" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://brettinman.com/blog/wp-content/gallery/tin/tin3.jpg" title=" " rel="lightbox[set_1]" >
								<img title="tin3.jpg" alt="tin3.jpg" src="http://brettinman.com/blog/wp-content/gallery/tin/thumbs/thumbs_tin3.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>

</p>
]]></content:encoded>
			<wfw:commentRss>http://brettinman.com/2009/06/03/woot-off-lights-in-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
