<?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>zenlogic</title>
	<atom:link href="http://zenlogic.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://zenlogic.org</link>
	<description>musings of a self-proclaimed inventor named Travis</description>
	<lastBuildDate>Wed, 18 Apr 2012 04:22:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Anodizing Aluminium at Home</title>
		<link>http://zenlogic.org/2012/04/17/anodizing-aluminium-at-home/</link>
		<comments>http://zenlogic.org/2012/04/17/anodizing-aluminium-at-home/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 04:22:50 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Fabrication]]></category>
		<category><![CDATA[Gauges]]></category>
		<category><![CDATA[aluminium]]></category>
		<category><![CDATA[anodizing]]></category>
		<category><![CDATA[gauges]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=476</guid>
		<description><![CDATA[The faceplate for the Gauges project is 1/8&#8243; Aluminium sheet...]]></description>
			<content:encoded><![CDATA[<p>The faceplate for the Gauges project is 1/8&#8243; Aluminium sheet metal. I bought a 12&#8243;-square sheet through McMaster-Carr, and after cutting it to size decided it would be best to anodize the finished product to keep it from scratching or corroding. After a few successful tests, I ran the final process, though I switched the anode and cathode polarities by accident, resulting in a strange thin-film oxidation on the work piece, which gives rise to varied rainbow interference patterns.</p>
<h3>Step 1: Etch</h3>
<p>After sanding and thoroughly cleaning the Aluminium with detergent (dish soap), I etched it in a solution of lye (Sodium Hydroxide) to remove surface defects and give a matte finish, like that of the Apple MacBook. I bought the lye in a solid form, as crystals of drain cleaner, and assumed that the crystals were pure lye (a stretch, though it was the best conservative estimate I could make). I read a guide about the etching process that suggested a 15% lye solution, so I mixed 1 part lye to 6 parts water in a 5-gallon plastic bucket. Wearing gloves and goggles, I submerged the metal in the solution, and it heated up and bubbled furiously as the lye ate away the surface. I only left the piece in solution about 2 minutes, to give a consistent matte look without making pock marks.</p>
<h3>Step 2: Desmut</h3>
<p>I don&#8217;t have access to proper desmut solution, the solvent that takes off the impure &#8220;smut&#8221; residue that accumulates on the surface of treated Aluminium. I rinsed the part in water and cleaned it with dish soap to fair success, and proceeded to anodizing.</p>
<h3>Step 3: Anodize</h3>
<p>Well, this step is supposed to involve using the work piece as an anode (positive terminal) in a direct-current circuit. The theory is that the metal will form a thin oxide layer, a clear ceramic that adds scratch- and corrosion-resistance to the finish. However, I accidentally wired the system in reverse, so that the work piece was the cathode (negative terminal). The result was a strange thin film of oxide that creates rainbow interference patterns. I like the look, and I assume the coating is indeed Aluminium oxide as it should be, but I cannot know for sure. It seems to have moderate scratch resistance, but I may try again with the correct circuit some time in the future to get it right. In the mean time, I am enjoying the vintage effect the &#8220;cathodizing&#8221; created, and I may just decide to keep it this way.</p>
<p>Following the guide I found, I bought battery acid from the local auto parts store and mixed it into water in the ratio of 1 parts acid to 4 parts water. The acid comes as 50% solution, and the goal is to have around 10%, so a solution of about 12% acid is just about right. The solution stays at room temperature.</p>
<p>I fashioned an electrode (supposedly a cathode, though due to my error ultimately an anode) out of Aluminium stock, which I placed in the bottom of the bucket of acid solution. I used an old computer ATX power supply to run a current of around 16 Amps through the workpiece, dangling from a bar of Aluminium, into the acid solution and back out through the &#8220;cathode&#8221;. Because I had wired the whole thing in reverse, the intended &#8220;cathode&#8221; ended up with the MacBook-like finish while my part looked just about the same as it did going in.</p>
<p>I sealed the part with boiling water for about an hour, and the rainbow effects showed up. Not exactly what I was after, but cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2012/04/17/anodizing-aluminium-at-home/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Identifying the sensor for use in Gauges</title>
		<link>http://zenlogic.org/2012/03/21/identifying-the-sensor-for-use-in-gauges/</link>
		<comments>http://zenlogic.org/2012/03/21/identifying-the-sensor-for-use-in-gauges/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 05:46:33 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Gauges]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=468</guid>
		<description><![CDATA[I am prototyping the software for Gauges from the Ubuntu...]]></description>
			<content:encoded><![CDATA[<p>I am prototyping the software for Gauges from the Ubuntu partition on my white MacBook from 2007. One of the early tasks was finding the name of the temperature sensor corresponding to the main CPU. I installed a cool utility called Psensor that charts sensor outputs over time. Then I opened every application I could think of, and waited for the CPU temperature to increase. Psensor clearly showed that the sensor named &#8220;TC0D&#8221; corresponded to the CPU temperature. That acronym may mean &#8220;Temp-CPU 0 Die&#8221;, but I don&#8217;t know for sure.</p>
<div id="attachment_471" class="wp-caption alignright" style="width: 310px"><a href="http://zenlogic.org/wp-content/uploads/2012/03/Screenshot-at-2012-03-13-130526.png" class="gallery_colorbox"><img class="size-medium wp-image-471" title="Psensors Screenshot" src="http://zenlogic.org/wp-content/uploads/2012/03/Screenshot-at-2012-03-13-130526-300x147.png"  alt="Psensors Screenshot" width="300" height="147" /></a><p class="wp-caption-text">Psensors Output</p></div>
<p>Once I knew the sensor name, I ran &#8220;sensors&#8221; in a terminal and found that my computer uses a chip called &#8220;applesmc-isa-300&#8243;:</p>
<pre class="brush: bash; title: ; notranslate">
travis@travis-ubuntu:~/Projects/Gauges$ sensors
applesmc-isa-0300
Adapter: ISA adapter
Exhaust  :   3074 RPM  (min = 1800 RPM)
TB0T:         +32.5°C
TC0D:         +57.2°C
TC0P:         +55.0°C
TM0P:         +58.0°C
TN0P:         +54.0°C
TTF0:         +55.0°C
TW0P:         +74.0°C
Th0H:         +54.8°C
Th0S:         +54.5°C
Th1H:         +54.2°C
</pre>
<p>Every Linux sensor has a corresponding pseudo-file for reading programmatically. I dug through online references of various sorts until I found the directory of my chipset, called &#8216;/sys/bus/platform/devices/applesmc.768/&#8217;. Once I had the directory, I ran sensors again with the -u flag set for &#8220;debugging&#8221; output:</p>
<pre class="brush: bash; title: ; notranslate">

travis@travis-ubuntu:~/Projects/Gauges$ sensors -u
applesmc-isa-0300
Adapter: ISA adapter
Exhaust  :
  fan1_input: 2309.000
  fan1_min: 1800.000
TB0T:
  temp1_input: 32.500
TC0D:
  temp2_input: 58.250
TC0P:
  temp3_input: 56.000
TM0P:
  temp4_input: 57.750
TN0P:
  temp5_input: 54.500
TTF0:
  temp6_input: 56.250
TW0P:
  temp7_input: 74.000
Th0H:
  temp8_input: 56.000
Th0S:
  temp9_input: 55.750
Th1H:
  temp10_input: 55.500
</pre>
<p>The verbose output told me that the sensor I want, TC0D, is also called &#8220;temp2_input&#8221;. Looking in the</p>
<pre>/sys/bus/platform/devices/applesmc.768/</pre>
<p>directory, I found a pseudo-file called &#8220;temp2_input&#8221;. Perfect!</p>
<p>When my Python script reads &#8217;/sys/bus/platform/devices/applesmc.768/temp2_input&#8217;, it gets a string something like &#8220;59500&#8243; corresponding to 59.5°C. My script converts the number to a float, divides by 1000, then rounds off to the nearest integer so I can fit the number in one byte. Awesome!</p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2012/03/21/identifying-the-sensor-for-use-in-gauges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting to Gauges with Bluetooth</title>
		<link>http://zenlogic.org/2012/03/20/connecting-to-gauges-with-bluetooth/</link>
		<comments>http://zenlogic.org/2012/03/20/connecting-to-gauges-with-bluetooth/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 04:39:01 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Gauges]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=465</guid>
		<description><![CDATA[Over the past few days I&#8217;ve worked on connecting Gauges...]]></description>
			<content:encoded><![CDATA[<p>Over the past few days I&#8217;ve worked on connecting Gauges to my computer over Bluetooth. I have the physical gauges attached to an Arduino and a breadboard, and I am using a <a title="BlueSmirf Silver product page" href="http://www.sparkfun.com/products/10269">Sparkfun BlueSmirf Silver</a> to receive streaming data from my laptop.</p>
<p>I wrote a Python script using the <a title="PyBlueZ at Google Code" href="http://code.google.com/p/pybluez/">PyBlueZ</a> stack to connect to the Bluesmirf. I had tried using <a title="PySerial on SourceForge" href="http://pyserial.sourceforge.net/">PySerial</a>, a great package, to write directly to the symbolic /dev/rfcomm0 representing serial bluetooth devices in Linux, but <a title="My question on Ask Ubuntu" href="http://askubuntu.com/questions/114171/why-is-dev-rfcomm0-giving-pyserial-problems">the connection had problems</a>. The problems I thought I could avoid by switching to PyBlueZ popped up again, and I am still hunting for  solution.</p>
<p>When I start the Python script, which I call &#8220;gauges-daemon&#8221; since eventually it will run as a Linux daemon, or background task, the connection opens fine and the gauges respond. However, after a certain period of activity the script suddenly encounters BluetoothError #11, &#8220;Resource Temporaily Unavailable.&#8221; To counter this error I thought I could have the script re-open the connection, but then I get error #16, &#8220;Device or Resource Busy&#8221;.</p>
<p>I did some permuting and found that I can start the script, wait for it to fail, and then re-start the BlueSmirf. This allows the script to reconnect. The evidence seems to suggest that the problem is with the BlueSmirf, though I have pored over <a title="The RN-42 radio manual" href="http://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf">the datasheet (PDF)</a> and found no mention about necessary steps to keep connections alive.</p>
<p><strong>EDIT: The problem was a buffer overflow on the PC.</strong> I was sending Bluetooth messages to the Gauges, which would respond with status text. Because the Python script never read the port for incoming messages, these incoming packets collected in the Bluetooth serial buffer and everything halted until the buffer was cleared.</p>
<p>I fixed the Python script to represent the necessary changes:</p>
<pre class="brush: python; title: ; notranslate">
import psutil
import serial
import string
import time
import bluetooth

sampleTime = 1
numSamples = 5
lastTemp = 0

TEMP_CHAR = 't'
USAGE_CHAR = 'u'
SENSOR_NAME = 'TC0D'

filename = '/sys/bus/platform/devices/applesmc.768/temp2_input'

def parseSensorsOutputLinux(output):
	return int(round(float(output) / 1000))

def connect():
	while(True):
		try:
			gaugeSocket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
			gaugeSocket.connect(('00:06:66:42:22:96', 1))
			break;
		except bluetooth.btcommon.BluetoothError as error:
			gaugeSocket.close()
			print &quot;Could not connect: &quot;, error, &quot;; Retrying in 10s...&quot;
			time.sleep(10)
	return gaugeSocket;

gaugeSocket = connect()
while(True):
	usage = psutil.cpu_percent(interval=sampleTime)
	sensorFile = open(filename)
	temp = parseSensorsOutputLinux(sensorFile.read())
	try:
		gaugeSocket.send(USAGE_CHAR)
		gaugeSocket.send(chr(int(usage)))
		#print(&quot;Wrote usage: &quot; + str(int(usage)))

		gaugeSocket.send(TEMP_CHAR)
		gaugeSocket.send(chr(temp))
		print gaugeSocket.recv(1024)
		#print(&quot;Wrote temp: &quot; + str(temp))
	except bluetooth.btcommon.BluetoothError as error:
		print &quot;Caught BluetoothError: &quot;, error
		time.sleep(5)
		gaugeSocket = connect()
		pass

gaugeSocket.close()
</pre>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2012/03/20/connecting-to-gauges-with-bluetooth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gauges: Vintage Analog Computer Monitoring</title>
		<link>http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/</link>
		<comments>http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/#comments</comments>
		<pubDate>Wed, 14 Mar 2012 03:25:26 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Gauges]]></category>
		<category><![CDATA[gauges]]></category>
		<category><![CDATA[vintage]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=433</guid>
		<description><![CDATA[I love the look and feel of vintage analog gauges,...]]></description>
			<content:encoded><![CDATA[<div id="attachment_436" class="wp-caption alignright" style="width: 234px"><a href="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3134-e1331694355350.jpg" class="gallery_colorbox"><img class="size-medium wp-image-436" title="The stock gauge" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3134-e1331694355350-224x300.jpg"  alt="The stock gauge" width="224" height="300" /></a><p class="wp-caption-text">The stock gauge</p></div>
<p>I love the look and feel of vintage analog gauges, like those on the instrumentation panels of WWII-era planes and submarines. They have a certain aura of importance and longevity that attracts me. I have been thinking about a wireless hardware add-on that artfully displays my computer&#8217;s temperature and CPU usage, and I figured that some of those old gauges would be awesome for this project if I could find them at the right price.</p>
<p>I had actually looked around online for vintage panel meters before, but I was too specific: I was trying to find DC panel meters for voltages under 12V. I recently realized that I could instead choose any of the multitude of DC meters available on eBay, as most of them simply use scaling resistors to calibrate to the ranges on their faces. So, I ordered two that I thought looked cool, for around $20 each.</p>
<p>I got the first gauge in the mail today. It&#8217;s a &#8220;20 mA&#8221; DC current meter, with a metal faceplate, solid glass crystal, and a metal housing. It has two screw terminals on the back. It&#8217;s also waterproof and ruggedized. Of course, I want it to display CPU temperature and not &#8220;DC Milliamperes,&#8221; so I immediately started the teardown.</p>
<h3>The Teardown</h3>

<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3136/' title='The gauge with metal face removed'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3136-150x150.jpg" class="attachment-thumbnail" alt="The gauge with metal face removed" title="The gauge with metal face removed" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3137/' title='The gauge with crystal removed'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3137-150x150.jpg" class="attachment-thumbnail" alt="The gauge with crystal removed" title="The gauge with crystal removed" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3138/' title='The gauge outside its housing'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3138-e1331694474442-150x150.jpg" class="attachment-thumbnail" alt="The gauge outside its housing" title="The gauge outside its housing" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3139/' title='The gauge beside its removed faceplate'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3139-150x150.jpg" class="attachment-thumbnail" alt="The gauge beside its removed faceplate" title="The gauge beside its removed faceplate" /></a>

<p>The gauge has a metal face held on by six small machine screws. Removing these, along with the three mounting screws, I exposed the crystal.</p>
<p>The crystal lifts off, though it was a bit stuck down due to years of pressure on the rubber gasket. Prying up gently around the gasket, the crystal easily peeled off and I was left with the exposed inner gauge.</p>
<p>To get the gauge assembly out I had to remove the screw terminal nuts on the back of the unit. Then everything slid out of the housing.</p>
<p>The faceplate was held in place by two hex-headed machine screws. Removing these, I carefully slid the plate out from under the indicator needle. I popped the plate into the scanner, and it was time for a face lift.</p>
<h3>The Face Lift</h3>

<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3140/' title='The new faceplate, left, beside the original, right'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3140-150x150.jpg" class="attachment-thumbnail" alt="The new faceplate, left, beside the original, right" title="The new faceplate, left, beside the original, right" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3144/' title='Applying tape to the original faceplate'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3144-150x150.jpg" class="attachment-thumbnail" alt="Applying tape to the original faceplate" title="Applying tape to the original faceplate" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3146/' title='The tape, after trimming, without the adhesive exposed'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3146-150x150.jpg" class="attachment-thumbnail" alt="The tape, after trimming, without the adhesive exposed" title="The tape, after trimming, without the adhesive exposed" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3147/' title='The original plate, with the adhesive of the tape exposed'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3147-150x150.jpg" class="attachment-thumbnail" alt="The original plate, with the adhesive of the tape exposed" title="The original plate, with the adhesive of the tape exposed" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3148/' title='The finished new plate (paper taped to original metal)'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3148-150x150.jpg" class="attachment-thumbnail" alt="The finished new plate (paper taped to original metal)" title="The finished new plate (paper taped to original metal)" /></a>

<p>I loved the look of the face that came in the gauge. It just had the wrong label and units. So, I scanned the plate with a flatbed scanner, then cleaned up all around the edges with GIMP, my image editor of choice. I also rotated the face to align it with the program&#8217;s grid.</p>
<p>The plate had the word &#8220;MILLIAMPERES&#8221; across the center, so the first change I made was replacing this text with &#8220;CPU TEMP&#8221;. I also changed the smaller &#8220;D.C.&#8221; label to &#8220;°C&#8221;, and masked out all the numerals with background color.</p>
<p>To find the range of values I needed, I installed &#8220;Psensor,&#8221; a graphing utility for system vitals monitoring on Ubuntu. Then I opened every application I could, running multiple browsers with videos and music, etc. I wanted to find the maximum temperature of the CPU under normal conditions. It peaked around 88º C, so I decided on 50-100º C for the indicated values on the new faceplate.</p>
<p>Matching fonts as closely as I could, I aligned the new numerals where the old ones had been. I printed a test page, and fortunately it was exactly the right size!</p>
<p>I got out some fancy stationery that happened to closely match the color of the faceplate, and printed my new design on high quality. I cut the design out with a razor knife, and then carefully applied removable double-sided tape across the whole plate. I trimmed away the edges of the tape so it would&#8217;t show.</p>
<p>Finally, I applied the new face plate design and smoothed it down gently. Time to reassemble!</p>
<h3>The Reassembly</h3>

<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3149/' title='The new plate on the gauge'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3149-e1331694620341-150x150.jpg" class="attachment-thumbnail" alt="The new plate on the gauge" title="The new plate on the gauge" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3150/' title='A side view of the new plate on the gauge'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3150-e1331694641175-150x150.jpg" class="attachment-thumbnail" alt="A side view of the new plate on the gauge" title="A side view of the new plate on the gauge" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3151/' title='The gauge back in its housing'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3151-e1331694662603-150x150.jpg" class="attachment-thumbnail" alt="The gauge back in its housing" title="The gauge back in its housing" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3152/' title='Voila! The finished gauge with front plate re-installed'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3152-e1331694680260-150x150.jpg" class="attachment-thumbnail" alt="Voila! The finished gauge with front plate re-installed" title="Voila! The finished gauge with front plate re-installed" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3153/' title='Another view of the final piece'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3153-e1331695291191-150x150.jpg" class="attachment-thumbnail" alt="Another view of the final piece" title="Another view of the final piece" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3154/' title='The back of the finished gauge'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3154-150x150.jpg" class="attachment-thumbnail" alt="The back of the finished gauge" title="The back of the finished gauge" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3155/' title='One more side view'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3155-e1331694761870-150x150.jpg" class="attachment-thumbnail" alt="One more side view" title="One more side view" /></a>

<p>From here the project was simply a matter of working in reverse. The plate when onto the gauge assembly, and both of its screws went back in.</p>
<p>Then I slid the whole assembly into the housing, and applied the (now clean) crystal, followed by the outer gasket and metal face.</p>
<p>Around back, the screw terminal accessories went back on, and it was time to try some electrical experiments.</p>
<h3>Calibration</h3>
<p>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3156/' title='Measuring the ESR'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3156-e1331694781535-150x150.jpg" class="attachment-thumbnail" alt="Measuring the ESR" title="Measuring the ESR" /></a>
<a href='http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/img_3159/' title='The gauge at full swing'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/03/IMG_3159-e1331694839914-150x150.jpg" class="attachment-thumbnail" alt="The gauge at full swing" title="The gauge at full swing" /></a>
<br />
I wanted to find the full-swing current of the gauge. It was labelled &#8220;50mA&#8221;, but it came with resistors attached in parallel to the screw terminals on the back. I removed the resistors, attaching my multimeter across the gauge terminal. Its resistance mode measured the gauge at precisely 10 ohms.</p>
<p>Next I hooked the gauge to a 1.3V DC power supply in series with an ammeter and a 10K potentiometer. Dialing down the resistance, the gauge made a full swing at almost exactly 5mA. When I am ready to hook it to a microcontroller, there won&#8217;t be a problem sourcing such a small drive current. Awesome!</p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2012/03/13/gauges-vintage-analog-computer-monitoring/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>So Many Choices</title>
		<link>http://zenlogic.org/2012/03/09/so-many-choices/</link>
		<comments>http://zenlogic.org/2012/03/09/so-many-choices/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 04:41:33 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[environment]]></category>
		<category><![CDATA[society]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=430</guid>
		<description><![CDATA[ Last night I had an involved conversation with a peer....]]></description>
			<content:encoded><![CDATA[<p><!--StartFragment--> Last night I had an involved conversation with a peer. I had come back from class thinking about the state of the global economy, and specifically the advanced rate of gadget consumption in the U.S. I insisted, as I lately do, that our obsession with high rates of gadget turnover is both unhealthy for our environment and for our happiness.</p>
<p>My thinking was largely inspired by the TED talk I had just watched, at http://www.ted.com/talks/barry_schwartz_on_the_paradox_of_choice.html, about what speaker Barry Schwartz calls “The Paradox of Choice.” His thesis is that, given some choice over none, people tend to be happier, but at some critical point the number of choices overwhelms the consumer and people simply cannot feel happy about their choices.</p>
<p><span id="more-430"></span></p>
<p>Today’s consumers have perhaps more choices than ever before, and arguably more choices in tech than in any other department of goods. Take a look at Lenovo’s website. I was browsing the latest and greatest in workforce laptops, and I was greeted by a web page spread wider than my five-year-old laptop’s 1080 horizontal pixels. Scrolling up and down and over and back I saw more laptops than I could reasonably hold in mind at a time, and worse, I couldn’t discern the difference between most of them. How do I choose between “SmartBuy” and “Enhanced Experience” ? How could I know whether a ThinkPad on the lower end of its price range would serve me better than an IdeaPad outfitted with the more luxurious options?</p>
<p>It’s not Lenovo’s fault, per se, that their offering are so diverse; nor is this a problem with Lenovo in particular. Over-diversification is common to basically every tech company today, and especially those marketed to the US consumers. I understand that some enterprise managers want very specific options, but detailed customization of this fine grain is not appropriate on a product home page. In situations like this one, in which I am trying to evaluate the state of the tech market, I am tempted to ask the designers and engineers, “Which product are you proud of? Which one of these options did you work hardest on?”</p>
<p>I suppose that, at the root of it, I want to know that modern designers and scientists and engineers are driven &#8212; like those of yesteryear seemed to be &#8212; by good quality and pride in craftsmanship. Our country needs things that get better with age. Or, at least, things that don’t obsolete so quickly.</p>
<p>I don’t mean to imply that I oppose technological innovation and progress; contrarily, I believe that technology is a transformative and potentially empowering and beneficial element of humanity. I simply think that we need to shift our mainstream focus from consuming more goods, more quickly, to valuing what we have.</p>
<p>This kind of shift would benefit hugely from interoperable and modular parts. If my computer can accept a new processor a few years down the road, I will be more likely to keep it. I could simply upgrade the components that need upgrading and keep the rest, which is in all likelihood perfectly functional. Incremental modifications and upgrades would save consumers money, cause companies to focus on long-lasting product designs, and ultimately help people live a bit lighter on the world.</p>
<p>I’m calling on technological collaboration, but also a shift in our social paradigm. It’s time for everyone to slow down, evaluate our priorities, and ultimately reduce consumption.</p>
<p>I don’t profess environmental concern as a means of self-valuation or absolution. I know that many people use “environment” and “green” as words to throw around in gaining credibility. I truly love and respect the natural world, and I also believe that environmental safety is directly connected to our safety. However far people think they can divorce themselves from the environment, we are all fundamentally connected to our natural roots.<!--EndFragment--></p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2012/03/09/so-many-choices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StarTiny v1 is in!</title>
		<link>http://zenlogic.org/2012/02/15/startiny-v1-is-in/</link>
		<comments>http://zenlogic.org/2012/02/15/startiny-v1-is-in/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 06:06:27 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Stardweeny/StarTiny]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[light]]></category>
		<category><![CDATA[ornament]]></category>
		<category><![CDATA[stardweeny]]></category>
		<category><![CDATA[startiny]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=421</guid>
		<description><![CDATA[The circuit boards have come back through BatchPCB, and I...]]></description>
			<content:encoded><![CDATA[
<a href='http://zenlogic.org/2012/02/15/startiny-v1-is-in/img_3065/' title='StarTiny v1 Single PCB'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/02/IMG_3065-150x150.jpg" class="attachment-thumbnail" alt="StarTiny v1 Single PCB" title="StarTiny v1 Single PCB" /></a>
<a href='http://zenlogic.org/2012/02/15/startiny-v1-is-in/img_3066/' title='StarTiny v1 Panel PCBs'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/02/IMG_3066-150x150.jpg" class="attachment-thumbnail" alt="StarTiny v1 Panel PCBs" title="StarTiny v1 Panel PCBs" /></a>
<a href='http://zenlogic.org/2012/02/15/startiny-v1-is-in/img_3070/' title='StarTiny v1 First Test!'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/02/IMG_3070-e1329285839513-150x150.jpg" class="attachment-thumbnail" alt="StarTiny v1 First Test!" title="StarTiny v1 First Test!" /></a>
<a href='http://zenlogic.org/2012/02/15/startiny-v1-is-in/img_3071/' title='StarTiny v1 First Test, Dimmer'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/02/IMG_3071-e1329285873730-150x150.jpg" class="attachment-thumbnail" alt="StarTiny v1 First Test, Dimmer" title="StarTiny v1 First Test, Dimmer" /></a>
<a href='http://zenlogic.org/2012/02/15/startiny-v1-is-in/img_3074/' title='StarTiny v1 Up Close'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/02/IMG_3074-e1329285904653-150x150.jpg" class="attachment-thumbnail" alt="StarTiny v1 Up Close" title="StarTiny v1 Up Close" /></a>

<p>The circuit boards have come back through BatchPCB, and I couldn&#8217;t be happier with the results. The lines are clean, the sizes are just to spec, and I got 20 boards instead of the ten I ordered (presumably to account for manufacturing defects, though I haven&#8217;t found any). I populated one of the PCBs, and the design works!</p>
<h3>The Boards</h3>
<p>The StarTiny boards turned out just right. Granted, it&#8217;s a very simple design. However, the price was right at just $3 per board. I originally hoped to order in the US, but the cost was just too high for an entry-level designer trying to get a feel for the manufacturing process.</p>
<h3>The Code</h3>
<p>The code I had written for my solderless-breadboard ATtiny was close to correct, though the timings were a bit off from what I wanted. As I&#8217;ve said before, there&#8217;s not enough flash space to include floating-point math libraries, so I had to forgo the sin() function I used on the Ardweeny. The code uses a rudimentary linear ramp to approximate the sine, and the results are pretty good, though there is a bit less visual distinction between the nodes.</p>
<p>I altered the pin mappings in the code to reflect the connections on the PCB, and I think with a few more tweaks I can get the look just right.</p>
<h3>Change of Plans with Paper</h3>
<p>The paper doesn&#8217;t pass light as well as I had hoped. I could try sourcing brighter LEDs, but they would have to stay under the 20mA drive capabilities of the &#8216;tiny. I think I might go with lighter-colored (and thinner) paper instead. The issue then would be structural integrity, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2012/02/15/startiny-v1-is-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The StarTiny Paper Pattern</title>
		<link>http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/</link>
		<comments>http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 07:28:39 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Origami]]></category>
		<category><![CDATA[Stardweeny/StarTiny]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=410</guid>
		<description><![CDATA[StarTiny is cool, in my opinion, partly because it features...]]></description>
			<content:encoded><![CDATA[<p>StarTiny is cool, in my opinion, partly because it features a hand-crafted paper star housing. The paper gives the whole item a certain crafty feel that speaks of art and care. And I appreciate care in products.</p>
<h3>Photos of the Paper Patterns</h3>

<a href='http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/img_2906/' title='StarTiny Papers 1'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2906-150x150.jpg" class="attachment-thumbnail" alt="StarTiny Papers 1" title="StarTiny Papers 1" /></a>
<a href='http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/img_2907/' title='StarTiny purple point, inside'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2907-e1327044425619-150x150.jpg" class="attachment-thumbnail" alt="StarTiny purple point, inside" title="StarTiny purple point, inside" /></a>
<a href='http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/img_2908/' title='StarTiny purple point, up close'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2908-e1327044389939-150x150.jpg" class="attachment-thumbnail" alt="StarTiny purple point, up close" title="StarTiny purple point, up close" /></a>
<a href='http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/img_2909/' title='StarTiny points, ready for gluing'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2909-e1327044355795-150x150.jpg" class="attachment-thumbnail" alt="StarTiny points, ready for gluing" title="StarTiny points, ready for gluing" /></a>
<a href='http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/img_2911/' title='StarTiny Purple, Red, and Turquoise'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2911-e1327044312163-150x150.jpg" class="attachment-thumbnail" alt="StarTiny Purple, Red, and Turquoise" title="StarTiny Purple, Red, and Turquoise" /></a>
<a href='http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/img_2912/' title='StarTiny Red, up close'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2912-e1327044285574-150x150.jpg" class="attachment-thumbnail" alt="StarTiny Red, up close" title="StarTiny Red, up close" /></a>
<a href='http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/img_2913/' title='StarTiny Purple, up close'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2913-e1327044242982-150x150.jpg" class="attachment-thumbnail" alt="StarTiny Purple, up close" title="StarTiny Purple, up close" /></a>
<a href='http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/img_2914/' title='StarTiny Papers'><img width="150" height="150" src="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2914-e1327044200597-150x150.jpg" class="attachment-thumbnail" alt="StarTiny Papers" title="StarTiny Papers" /></a>

<p>I can&#8217;t wait to get the PCBs to bring these colors to life!</p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2012/01/20/the-startiny-paper-pattern/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Stardweeny evolves into StarTiny: PCBs sent to production!</title>
		<link>http://zenlogic.org/2012/01/20/stardweeny-evolves-into-startiny-pcbs-sent-to-production/</link>
		<comments>http://zenlogic.org/2012/01/20/stardweeny-evolves-into-startiny-pcbs-sent-to-production/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 07:07:43 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Stardweeny/StarTiny]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=406</guid>
		<description><![CDATA[The Stardweeny finally has its own PCB! The first version...]]></description>
			<content:encoded><![CDATA[<p>The Stardweeny finally has its own PCB! The first version was based on a<a title="Ardweeny by Solarbotics" href="http://www.solarbotics.com/products/kardw/"> Solarbotics Ardweeny</a> on a perfboard, but I wanted to lower the cost and especially the manufacturing complexity.</p>
<h3>Enter the StarTiny</h3>
<p>I made the new StarTiny PCB with <a title="gEDA/gaf EDA Suite" href="http://www.gpleda.org/">gEDA</a>. It is based on the ATtiny13 microcontroller from Atmel, as the name suggests. The tiny13 has just enough storage space to hold the necessary firmware for the star. It comes in a compact <a title="SOIC on Wikipedia" href="http://en.wikipedia.org/wiki/Small-outline_integrated_circuit">8-SOIC package</a> that fits neatly between the five LEDs on the board.</p>
<h3>The Order</h3>
<p>I ordered 10 of the StarTiny PCBs through <a title="BatchPCB Home" href="http://batchpcb.com/">BatchPCB</a>, a Sparkfun-related frontend to the Chinese Gold Phoenix PCB fab. The boards are only 1.25&#8243; to a side, so the cost comes out to only $3.95 per board. There&#8217;s a $10 per-order tooling fee (for panelization and human design verification) and a $5 shipping fee.</p>
<div id="attachment_407" class="wp-caption alignright" style="width: 160px"><a href="http://zenlogic.org/wp-content/uploads/2012/01/overview.png" class="gallery_colorbox"><img class="size-thumbnail wp-image-407" title="StarTiny v1 Overview" src="http://zenlogic.org/wp-content/uploads/2012/01/overview-150x150.png"  alt="StarTiny v1 Overview" width="150" height="150" /></a><p class="wp-caption-text">StarTiny v1 Overview</p></div>
<h3> The Files</h3>
<p>As you may have read in the first post on the Stardweeny, I&#8217;m sharing the design files freely. I want anyone to be able to share in the simple joy of soothing, blinky LEDs! The effect is really quite charming. Also, if you want, you can order your own PCB directly via <a title="The PCB on BatchPCB" href="http://www.batchpcb.com/product_info.php?products_id=77179&amp;check=26228635823ea789a06cf6bbb8f63b87">BatchPCB</a>.</p>
<ul>
<li><a href="http://zenlogic.org/wp-content/uploads/2012/01/startiny1.zip">StarTiny v1 Gerber Files</a></li>
</ul>
<div><em><strong>Please note: I have not yet received these boards from the manufacturer, so they aren&#8217;t tested. As usual, no guarantees!</strong></em></div>
<p><a href="http://creativecommons.org/licenses/by/3.0/" rel="license"><img style="border-width: 0;" src="http://i.creativecommons.org/l/by/3.0/88x31.png" alt="Creative Commons License" /></a><br />
StarTiny v1 by <a href="http://www.zenlogic.org/" rel="cc:attributionURL">Travis Geis</a> is licensed under a <a href="http://creativecommons.org/licenses/by/3.0/" rel="license">Creative Commons Attribution 3.0 Unported License</a>.<br />
Based on a work at <a href="http://www.zenlogic.org/" rel="dct:source">www.zenlogic.org</a>.<br />
Permissions beyond the scope of this license may be available at <a href="http://www.zenlogic.org/" rel="cc:morePermissions">http://www.zenlogic.org/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2012/01/20/stardweeny-evolves-into-startiny-pcbs-sent-to-production/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software PWM on the ATtiny13</title>
		<link>http://zenlogic.org/2012/01/11/software-pwm-on-the-attiny13/</link>
		<comments>http://zenlogic.org/2012/01/11/software-pwm-on-the-attiny13/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 04:28:07 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Stardweeny/StarTiny]]></category>
		<category><![CDATA[ATtiny]]></category>
		<category><![CDATA[ATtiny13]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[AVR-LibC]]></category>
		<category><![CDATA[led]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=394</guid>
		<description><![CDATA[This year for the holidays I created a little dynamic...]]></description>
			<content:encoded><![CDATA[<div id="attachment_403" class="wp-caption alignright" style="width: 160px"><a href="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2929.jpg" class="gallery_colorbox"><img class="size-thumbnail wp-image-403" title="Stardweeny ATtiny First Prototype" src="http://zenlogic.org/wp-content/uploads/2012/01/IMG_2929-e1326866475822-150x150.jpg"  alt="A first go at the Stardweeny using an ATtiny13" width="150" height="150" /></a><p class="wp-caption-text">Testing the ATtiny13 with one LED</p></div>
<p>This year for the holidays I created a little dynamic ornament with five channels of independent LED light. The prototype, which had to be finished in a matter of days, used an Ardweeny board from Solarbotics. The Ardweeny is based on the ATmega328, a great chip with more than five hardware channels for PWM (pulse-width modulation). While I love the ATmega chips, they get a bit pricey at $5 apiece just to drive some LEDs.</p>
<p>I was shopping on Digi-Key for alternatives and decided to try a couple of ATtiny13 microcontrollers. The ATtiny13 is a small, low-power AVR with the standard 8-bit core size, and conveniently comes with a 9.6-MHz internal RC oscillator. Because the ATtiny has an internal oscillator, I knew I could keep my hardware very minimal and thus very small, a requirement for the small paper ornament I was hoping to build.</p>
<p>The problem is that the ATtiny13 has only one PWM output. If I used only its hardware functionality, I would get one channel of control, where I needed five. To solution is to implement a simple software PWM. In this post I describe my process of getting software PWM (and embedded C programming in general) working on the ATtiny13.</p>
<p><span id="more-394"></span></p>
<p>The first step with programming any part is reading the datasheet [link]. The Attiny13 comes with 1KB of internal flash memory for programs. When I ordered it this sounded plenty large for my purposes, but I forgot to account for the heavy Arduino libraries I&#8217;m used to using, whose needed functionality I would have to implement myself in the code. 1KB turns out to feel like a tiny amount of space.</p>
<p>1KB is too small to hold the floating-point math libraries of AVR-LibC, the C library I use for AVR programs. It&#8217;s also too small to hold the math.h library, which includes the trigonometry functions. In my &#8217;328-based prototype I used a sin() function to calculate the brightness levels of the light channels, to give a soothing light pulsation. That won&#8217;t be an option on the tiny13.</p>
<p>I had a lot of trouble getting started with C on the ATtiny. It&#8217;s not too complicated once you get going, though.</p>
<p>[steps for strting with libc]</p>
<h2>Implementing Software PWM</h2>
<p>Software PWM uses an inbuilt functionality of the microcontroller called a timer. The timer counts off clock cycles, and when it reaches a certain point, in this case its maximum value of 255 (the max value of a single unsigned byte), the timer triggers an interrupt.</p>
<p>The interrupt is important precisely because it interrupts the running code. Specifically, it tells the microcontroller to jump to a predefined location in program memory, execute the instructions there, and then return to the main routine. For software-based PWM, the timer interrupt is perfect. It frees up the main program logic by periodically and consistently executing the same function, called an Interrupt Service Routine.</p>
<p>So the desired program flow looks like this:</p>
<pre class="brush: cpp; title: ; notranslate">
main(){
	loop infinitely, changing the output levels
	accordingly.
}

ISR(){
	run now and then, twiddling the hardware
	outputs to correspond with the output levels
	set in main
}
</pre>
<p>The main function in my case was supposed to set the output level of each of five LEDs such that one LED would &#8220;lead&#8221; the others in a gentle up-down pulsation. The ISR would be responsible for dealing with the actual on-off settings of the LEDs.</p>
<p>For my project I chose a PWM resolution of one byte, or eight bits. A byte allows for 256 possible output levels, plenty more than the eye can see in brightness gradation. A resolution of 256 means that there are 256 &#8220;time slots&#8221; wherein an LED can turn on or off.</p>
<p>For example, if the brightness of the LED is supposed to be 255, it is on from time slot &#8220;0&#8243; all the way to time slot &#8220;255&#8243;—in other words, all the time. If the brightness is 0, the LED is off for every cycle. If the brightness is 100, the LED is on for the first hundred cycles, then off for the remaining 155.</p>
<p>The resulting output is not smooth, but a series of full-on and full-off positions that, to the relatively slow human eye, average together to some intermediate brightness. So, now we know roughly what the ISR should do:</p>
<ol>
<li>Read the desired brightness level of an LED, in the form of a global variable.</li>
<li>Read the current progress through the 256 cycles</li>
<li>Compare the brightness level to the current progress</li>
<ol>
<li>If the progress is lower than the desired on-time, turn the LED on.</li>
<li>If the progress is past the desired on-time, turn the LED off.</li>
</ol>
<li>Increment the progress by one.</li>
</ol>
<p>AVR-LibC says that the ISR for the timer interrupt on the tiny13 has the signature</p>
<pre class="brush: cpp; title: ; notranslate">

ISR(TIM0_OVF_vect){}
</pre>
<p>The TIM0_OVF_vect parameter indicates that this ISR (potentially one of several) is specifically for interrupts triggered by a TIMER0 overflow.</p>
<p>Given the pin number of each LED channel, and the brightness level desired, the ISR body looks like:</p>
<pre class="brush: cpp; title: ; notranslate">
ISR(TIM0_OVF_vect)
{
	if(ISRcounter &lt; ch1) PORTB |= (1 &lt;&lt; CH1_PIN); //Write the ch1 pin high
	else PORTB &amp;= ~(1 &lt;&lt; CH1_PIN); //Write the ch1 pin low

	if(ISRcounter &lt; ch2) PORTB |= (1 &lt;&lt; CH2_PIN);
	else PORTB &amp;= ~(1 &lt;&lt; CH2_PIN);

	if(ISRcounter &lt; ch3) PORTB |= (1 &lt;&lt; CH3_PIN);
	else PORTB &amp;= ~(1 &lt;&lt; CH3_PIN);

	if(ISRcounter &lt; ch4) PORTB |= (1 &lt;&lt; CH4_PIN);
	else PORTB &amp;= ~(1 &lt;&lt; CH4_PIN);

	if(ISRcounter &lt; ch5) PORTB |= (1 &lt;&lt; CH5_PIN);
	else PORTB &amp;= ~(1 &lt;&lt; CH5_PIN);

	ISRcounter++;
}
</pre>
<p>where ch1, ch2, &#8230;, ch5 are the single-byte output levels of each channel, and CH1_PIN, CH2_PIN, &#8230;, CH5_PIN are the pin numbers for each channel.</p>
<p>The ISR is actually very simple:</p>
<p>ISRcounter holds the current count of ISR runs (0 to 255). For each channel, if the ISRcounter is less than the brightness level desired for that channel, write the LED HIGH (PORTB |= (1 &lt;&lt; pinNumber)). Once the counter exceeds the desired brightness level, keep writing the LED LOW (PORTB &amp;= ~(1 &lt;&lt; pinNumber)). So, in effect, the brightness level byte is simply the ON-time of the LED, out of 255.</p>
<p>The rest of the code can now fall into place:</p>
<pre class="brush: cpp; title: ; notranslate">
#define F_CPU 9.6E6L /* CPU Freq. Must come before delay.h include. 9.6MHz */

#include  /* For data types */
#include  /* Register and port definitions */
#include  /* Busy-wait delay functions */
#include  /* Exposes timers, counters and ISR functions */

#define CH1_PIN PB0 /* Bind output channels to specific PortB pins. This depends on schematic. */
#define CH2_PIN PB1
#define CH3_PIN PB2
#define CH4_PIN PB3
#define CH5_PIN PB4

#define TIME_OFFSET 50
#define DELAY_MS 3

uint8_t ch1, ch2, ch3, ch4, ch5; /* The one-byte PWM level of each channel */
uint8_t directions = 0xFF;
/*
This one-byte flag holds five channel direction bit flags
0x [nothing] [nothing] [nothing] [ch5] [ch4] [ch3] [ch2] [ch1]
*/

volatile uint8_t ISRcounter = 0; /* Count the number of times the ISR has run */
uint8_t timeCount;

int main(void);

int main(void)
{
	/* Setup */
	ch1 = 0;
	ch2 = TIME_OFFSET;
	ch3 = 2 * TIME_OFFSET;
	ch4 = 3 * TIME_OFFSET;
	ch5 = 4 * TIME_OFFSET;

	DDRB = 0xFF; //Every PORTB pin is output
	PORTB = 0x00; //Start with every pin low

	TCCR0B |= (1 &lt;&lt; CS00); // disable timer prescale (=clock rate)
	TIMSK0 |= (1 &lt;&lt; TOIE0); // enable timer overflow interrupt specifically 	sei(); // enable interrupts in general 	/* Loop */ 	while(1){ 		if(directions &amp; 1) ch1++; 		else ch1--; 		if(directions &amp; 0B00000010) ch2++; 		else ch2--; 		if(directions &amp; 0B00000100) ch3++; 		else ch3--; 		if(directions &amp; 0B00001000) ch4++; 		else ch4--; 		if(directions &amp; 0B00010000) ch5++; 		else ch5--; 		if(ch1 &gt; 254) directions &amp;= ~0B00000001;
		else if(ch1 &lt; 1) directions |= 0B00000001; 		if(ch2 &gt; 254) directions &amp;= ~0B00000010;
		else if(ch2 &lt; 1) directions |= 0B00000010; 		if(ch3 &gt; 254) directions &amp;= ~0B00000100;
		else if(ch3 &lt; 1) directions |= 0B00000100; 		if(ch4 &gt; 254) directions &amp;= ~0B00001000;
		else if(ch4 &lt; 1) directions |= 0B00001000; 		if(ch5 &gt; 254) directions &amp;= ~0B00010000;
		else if(ch5 &lt; 1) directions |= 0B00010000;

		_delay_ms(DELAY_MS);
	}
	return 0;
}
</pre>
<p>Like all AVR-LibC programs, the main() function is divided into a setup phase, which runs once at the time of power-up, and a loop phase, which runs after setup as long as power is supplied. The setup function here sets the five LED channels to a starting brightness with an interval determined by the macro TIME_OFFSET, so-named because it simulates the amount of time by which each LED leads the one &#8220;behind&#8221; it in the circular brightness pattern.</p>
<p>Then the loop logic uses a one-bit &#8220;direction&#8221; flag to decide whether to increment or decrement the brightness of each channel, and finally a comparison checks whether the direction needs to reverse (in case the LED is at minimum or maximum brightness). The loop delays by time DELAY_MS, in milliseconds, and starts again.</p>
<p>That&#8217;s it! Beyond setting up the timer details with the lines</p>
<pre class="brush: cpp; title: ; notranslate">
	TCCR0B |= (1 &lt;&lt; CS00); // disable timer prescale (=clock rate)
	TIMSK0 |= (1 &lt;&lt; TOIE0); // enable timer overflow interrupt specifically

	sei(); // enable interrupts in general
</pre>
<p>as given in the ATtiny13 datasheet, the main() function and the ISR together handle everything the program has to do to make pretty blinky lights.</p>
<p>There is one more step, actually. By default, the ATtiny13 ships with a 1/8th clock prescaler enabled, a fuse called &#8220;CKDIV8&#8243; or &#8220;clock divide 8.&#8221; To make the timer count quickly enough for the PWM to be invisible to the human eye, we need to disable this clock divisor. To do so, we must run the command</p>
<pre class="brush: plain; title: ; notranslate">
&quot;avrdude -c usbtiny -p t13 -U lfuse:w:0x7A:m&quot;
</pre>
<p>instructing avrdude to wirte 0x7A to the low fuse. This is the same as the default low fuse value in every way but the CKDIV8 bit, which has been disabled.</p>
<p>The complete code:</p>
<pre class="brush: cpp; title: ; notranslate">
/*
* Stardweeny Source Code
* Author: Travis Geis
* Version: 1
* Date: January 2012
* URL: http://zenlogic.org/
*
* file: main.c
*
* The Stardweeny project runs five channels of software PWM to
* control the five individual LEDs in the points of a paper star.
*
* Inspired by and dedicated to Linda Geis.
*
* For this code to work correctly, lfuse = 0x7A. (Disabling CKDIV8)
* Run the command &quot;avrdude -c usbtiny -p t13 -U lfuse:w:0x7A:m&quot;
*/

#define F_CPU 9.6E6L /* CPU Freq. Must come before delay.h include. 9.6MHz */

#include  /* For data types */
#include  /* Register and port definitions */
#include  /* Busy-wait delay functions */
#include  /* Exposes timers, counters and ISR functions */

#define CH1_PIN PB0 /* Bind output channels to specific PortB pins. This depends on schematic. */
#define CH2_PIN PB1
#define CH3_PIN PB2
#define CH4_PIN PB3
#define CH5_PIN PB4

#define TIME_OFFSET 50
#define DELAY_MS 3

uint8_t ch1, ch2, ch3, ch4, ch5; /* The one-byte PWM level of each channel */
uint8_t directions = 0xFF;
/*
This one-byte flag holds five channel direction bit flags
0x [nothing] [nothing] [nothing] [ch5] [ch4] [ch3] [ch2] [ch1]
*/

volatile uint8_t ISRcounter = 0; /* Count the number of times the ISR has run */
uint8_t timeCount;

int main(void);

/*
* int main(void):
*
* The main function runs automatically when the AVR powers up.
* It never returns, and so dispatches all other actions for the
* microcontroller.
*
* The goal is to make a sinusoidal light intensity with time.
*
*/

int main(void)
{
	/* Setup */
	ch1 = 0;
	ch2 = TIME_OFFSET;
	ch3 = 2 * TIME_OFFSET;
	ch4 = 3 * TIME_OFFSET;
	ch5 = 4 * TIME_OFFSET;

	DDRB = 0xFF; //Every PORTB pin is output
	PORTB = 0x00; //Start with every pin low

	TCCR0B |= (1 &lt;&lt; CS00); // disable timer prescale (=clock rate)
	TIMSK0 |= (1 &lt;&lt; TOIE0); // enable timer overflow interrupt specifically 	 	sei(); // enable interrupts in general 	 	/* Loop */ 	while(1){ 		if(directions &amp; 1) ch1++; 		else ch1--; 		if(directions &amp; 0B00000010) ch2++; 		else ch2--; 		if(directions &amp; 0B00000100) ch3++; 		else ch3--; 		if(directions &amp; 0B00001000) ch4++; 		else ch4--; 		if(directions &amp; 0B00010000) ch5++; 		else ch5--; 		if(ch1 &gt; 254) directions &amp;= ~0B00000001;
		else if(ch1 &lt; 1) directions |= 0B00000001; 		if(ch2 &gt; 254) directions &amp;= ~0B00000010;
		else if(ch2 &lt; 1) directions |= 0B00000010; 		if(ch3 &gt; 254) directions &amp;= ~0B00000100;
		else if(ch3 &lt; 1) directions |= 0B00000100; 		if(ch4 &gt; 254) directions &amp;= ~0B00001000;
		else if(ch4 &lt; 1) directions |= 0B00001000; 		if(ch5 &gt; 254) directions &amp;= ~0B00010000;
		else if(ch5 &lt; 1) directions |= 0B00010000;

		_delay_ms(DELAY_MS);
	}
	return 0;
}
/*
* The ISR is responsible for toggling the states of the five output channels
* based on the current global variables for the desired brightness levels.
* Because the brightnesses (ch1 ... ch5) are single-byte values, the range
* of values is 0 to 255. Thus the ISR needs to restart its counting cycle every
* 256th time it is called.
*
* To avoid undesired wiggle on the PWM, the ISR updates evey channel's pin
* every time it runs. It should take the same number of cycles every time.
* The duty period of the PWM is the first section. Thus the LED goes ON then OFF.
*/
ISR(TIM0_OVF_vect)
{
	if(ISRcounter &lt; ch1) PORTB |= (1 &lt;&lt; CH1_PIN); //Write the ch1 pin high
	else PORTB &amp;= ~(1 &lt;&lt; CH1_PIN); //Write the ch1 pin low

	if(ISRcounter &lt; ch2) PORTB |= (1 &lt;&lt; CH2_PIN);
	else PORTB &amp;= ~(1 &lt;&lt; CH2_PIN);

	if(ISRcounter &lt; ch3) PORTB |= (1 &lt;&lt; CH3_PIN);
	else PORTB &amp;= ~(1 &lt;&lt; CH3_PIN);

	if(ISRcounter &lt; ch4) PORTB |= (1 &lt;&lt; CH4_PIN);
	else PORTB &amp;= ~(1 &lt;&lt; CH4_PIN);

	if(ISRcounter &lt; ch5) PORTB |= (1 &lt;&lt; CH5_PIN);
	else PORTB &amp;= ~(1 &lt;&lt; CH5_PIN);

	ISRcounter++;
}
</pre>
<p>Feel free to use the code any way you want. Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2012/01/11/software-pwm-on-the-attiny13/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More Portable Power</title>
		<link>http://zenlogic.org/2011/11/23/more-portable-power/</link>
		<comments>http://zenlogic.org/2011/11/23/more-portable-power/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 05:00:07 +0000</pubDate>
		<dc:creator>Travis ("ottobonn")</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://zenlogic.org/?p=370</guid>
		<description><![CDATA[I&#8217;m working right now on a more portable ATX power...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working right now on a more portable ATX power supply, hopefully one that can survive a rough plane ride in the cargo hold without any special attention. I&#8217;d like to inset the terminals and switch, to keep them out of harm&#8217;s way and to allow me to stack stuff on the supply.</p>
<p>I think while I&#8217;m at it I will add a LM317 variable regulator and an Adafruit <a title="Adafruit's Panel Volt Meter" href="http://www.adafruit.com/products/575">Panel Volt Meter</a> to keep an eye on the voltage of the regulator. I could even add a current-sensing resistor, though I probably won&#8217;t need it.</p>
<p>I started off intending to roll my own supply, but it turns out they don&#8217;t get much smaller than the ATXs for what those do. I like having all the separate power lines, and the overcurrent protection is priceless.</p>
]]></content:encoded>
			<wfw:commentRss>http://zenlogic.org/2011/11/23/more-portable-power/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

