<?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>Doswa</title>
	<atom:link href="http://doswa.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://doswa.com/blog</link>
	<description>Programming, physics, mathematics</description>
	<lastBuildDate>Sat, 10 Jul 2010 09:04:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Quantum lolcats</title>
		<link>http://doswa.com/blog/2010/07/02/quantum-lolcats/</link>
		<comments>http://doswa.com/blog/2010/07/02/quantum-lolcats/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 04:25:48 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/2010/07/02/quantum-lolcats/</guid>
		<description><![CDATA[&#8220;Funny fact: lolcats cannot be put in a Schroedinger state, because quantum rules don&#8217;t work on a macro level.&#8221; &#8211; qvantamon on MetaFilter]]></description>
			<content:encoded><![CDATA[<p>&#8220;Funny fact: lolcats cannot be put in a Schroedinger state, because quantum rules don&#8217;t work on a macro level.&#8221; &#8211; <a href="http://www.metafilter.com/90216/Quantum-weirdness-at-the-large-scale#3000515">qvantamon on MetaFilter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2010/07/02/quantum-lolcats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kaoss Guitar &#8211; Day 1</title>
		<link>http://doswa.com/blog/2010/04/18/kaoss-guitar-day-1/</link>
		<comments>http://doswa.com/blog/2010/04/18/kaoss-guitar-day-1/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 10:32:47 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/?p=402</guid>
		<description><![CDATA[For a while, a friend and I have been planning to build a specialized MIDI controller into a guitar to control a Korg Kaoss Pad KP2. The idea came from the guitar used by Matt Bellamy of Muse (check out &#8230; <a href="http://doswa.com/blog/2010/04/18/kaoss-guitar-day-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For a while, a friend and I have been planning to build a specialized MIDI controller into a guitar to control a Korg <a href="http://en.wikipedia.org/wiki/Kaoss_Pad">Kaoss Pad</a> KP2. The idea came from the guitar used by Matt Bellamy of Muse (check out <a href="http://www.youtube.com/watch?v=h1cZDQFgHH8">a video of it</a>).</p>
<p>We ordered the electronics for the guitar from <a href="http://sparkfun.com">SparkFun Electronics</a> and <a href="http://digikey.com">Digi-Key</a>. When the project is over, I plan to add up the total cost and post a bill of materials. I suspect it will total to around $100.</p>
<p>Today we tested out <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8448">the 4.3&#8243; touchpad from SparkFun</a> using an Arduino. I have just finished setting up an ATmega328P on a breadboard and got a basic blink program running. The final product will be running on a plain AVR without the Arduino libraries/bootloader.</p>
<p>One problem I ran into using my <a href="http://doswa.com/blog/2009/12/20/sparkfuns-ftdi-basic-breakout-as-an-avr-programmer/">FTDI programmer</a> was the clock rate. A fresh ATmega328P comes running at 1 MHz, significantly lower than the default 16 MHz on Arduino-prepared ATmegas. As a result, I kept getting errors like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">david<span style="color: #000000; font-weight: bold;">@</span>second:~$ avrdude <span style="color: #660033;">-c</span> ftdi <span style="color: #660033;">-p</span> atmega168 <span style="color: #660033;">-P</span> ft0
avrdude: BitBang OK 
avrdude: pin assign miso <span style="color: #000000;">1</span> sck <span style="color: #000000;">3</span> mosi <span style="color: #000000;">0</span> reset <span style="color: #000000;">4</span>
avrdude: drain OK 
&nbsp;
 ft245r:  bitclk <span style="color: #000000;">230400</span> -<span style="color: #000000; font-weight: bold;">&gt;</span> ft baud <span style="color: #000000;">115200</span>
avrdude: ft245r_program_enable: failed
avrdude: initialization failed, <span style="color: #007800;">rc</span>=-<span style="color: #000000;">1</span>
         Double check connections and try again, or use <span style="color: #660033;">-F</span> to override
         this check.
&nbsp;
&nbsp;
avrdude done.  Thank you.</pre></div></div>

<p>Eventually I found AVRDUDE&#8217;s <code>-B</code> option. It adjusts the clock rate that&#8217;s fed into the SCK pin on the AVR. I found that a value of <code>-B 76800</code> works well, but if you&#8217;re running into this problem, I recommend starting with <code>-B 1</code> and going up until it stops working. To be explicit, this is the command that I found works:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">david<span style="color: #000000; font-weight: bold;">@</span>second:~$ avrdude <span style="color: #660033;">-c</span> ftdi <span style="color: #660033;">-p</span> atmega168 <span style="color: #660033;">-P</span> ft0 <span style="color: #660033;">-B</span> <span style="color: #000000;">76800</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2010/04/18/kaoss-guitar-day-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Client-side Prediction</title>
		<link>http://doswa.com/blog/2010/04/03/client-side-prediction/</link>
		<comments>http://doswa.com/blog/2010/04/03/client-side-prediction/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 22:44:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Silly Ideas]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/?p=397</guid>
		<description><![CDATA[I was reading about client-side prediction in the context of video game physics today and thought of an idea: client-side prediction on streamed video (e.g. on Skype or similar video chats). Each pixel could be assigned a velocity and &#8220;color &#8230; <a href="http://doswa.com/blog/2010/04/03/client-side-prediction/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was reading about client-side prediction in the context of video game physics today and thought of an idea: client-side prediction on streamed video (e.g. on Skype or similar video chats). Each pixel could be assigned a velocity and &#8220;color velocity&#8221; (<img src="http://doswa.com/blog/wp-content/cache/tex_d9d1eea7f7efec498542fb7921c4031e.png" align="absmiddle" class="tex" alt="\frac{d \, \textnormal{red}}{dt}" />, <img src="http://doswa.com/blog/wp-content/cache/tex_6ebeb3f4b4b6f55cf2d26eb626b772e4.png" align="absmiddle" class="tex" alt="\frac{d \, \textnormal{blue}}{dt}" />, <img src="http://doswa.com/blog/wp-content/cache/tex_6d4d76a3c4b291f4ea716e61824e0ba1.png" align="absmiddle" class="tex" alt="\frac{d \, \textnormal{green}}{dt}" />). A velocity grid method like the one described in <a href="http://www.gamasutra.com/view/feature/1549/practical_fluid_dynamics_part_1.php?print=1">Practical Fluid Dynamics 1</a> and <a href="http://www.gamasutra.com/view/feature/1615/practical_fluid_dynamics_part_2.php?print=1">2</a> comes to mind.</p>
]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2010/04/03/client-side-prediction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Cairo in Pygame</title>
		<link>http://doswa.com/blog/2010/03/29/using-cairo-in-pygame/</link>
		<comments>http://doswa.com/blog/2010/03/29/using-cairo-in-pygame/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 05:17:55 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/?p=389</guid>
		<description><![CDATA[This is a method of using Cairo with Pygame. It works by sharing the same block of memory for the Cairo drawing surface and the Pygame image surface. The only trick to it is making sure that Cairo and Pygame &#8230; <a href="http://doswa.com/blog/2010/03/29/using-cairo-in-pygame/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a method of using Cairo with Pygame. It works by sharing the same block of memory for the Cairo drawing surface and the Pygame image surface. The only trick to it is making sure that Cairo and Pygame use the same format to store the pixel data in.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> cairo
<span style="color: #ff7700;font-weight:bold;">import</span> pygame
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">math</span>
&nbsp;
size = <span style="color: #ff4500;">400</span>, <span style="color: #ff4500;">400</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Initialize pygame with 32-bit colors. This setting stores the pixels</span>
<span style="color: #808080; font-style: italic;"># in the format 0x00rrggbb.</span>
pygame.<span style="color: black;">init</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
screen = pygame.<span style="color: black;">display</span>.<span style="color: black;">set_mode</span><span style="color: black;">&#40;</span>size, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">32</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Get a reference to the memory block storing the pixel data.</span>
pixels = pygame.<span style="color: black;">surfarray</span>.<span style="color: black;">pixels2d</span><span style="color: black;">&#40;</span>screen<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set up a Cairo surface using the same memory block and the same pixel</span>
<span style="color: #808080; font-style: italic;"># format (Cairo's RGB24 format means that the pixels are stored as</span>
<span style="color: #808080; font-style: italic;"># 0x00rrggbb; i.e. only 24 bits are used and the upper 16 are 0).</span>
cairo_surface = cairo.<span style="color: black;">ImageSurface</span>.<span style="color: black;">create_for_data</span><span style="color: black;">&#40;</span>
	pixels.<span style="color: black;">data</span>, cairo.<span style="color: black;">FORMAT_RGB24</span>, size<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, size<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw a white circle to the screen using pygame.</span>
radius = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">min</span><span style="color: black;">&#40;</span>size<span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">0.7</span><span style="color: black;">&#41;</span>
pos = <span style="color: black;">&#91;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>a/<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> a <span style="color: #ff7700;font-weight:bold;">in</span> size<span style="color: black;">&#93;</span>
pygame.<span style="color: black;">draw</span>.<span style="color: black;">circle</span><span style="color: black;">&#40;</span>screen, <span style="color: black;">&#40;</span><span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span>, pos, radius<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw a smaller black circle to the screen using Cairo.</span>
context = cairo.<span style="color: black;">Context</span><span style="color: black;">&#40;</span>cairo_surface<span style="color: black;">&#41;</span>
context.<span style="color: black;">set_source_rgb</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
context.<span style="color: black;">arc</span><span style="color: black;">&#40;</span>size<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>/<span style="color: #ff4500;">2</span>, size<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>/<span style="color: #ff4500;">2</span>, <span style="color: #008000;">min</span><span style="color: black;">&#40;</span>size<span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">0.5</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">2</span><span style="color: #66cc66;">*</span><span style="color: #dc143c;">math</span>.<span style="color: black;">pi</span><span style="color: black;">&#41;</span>
context.<span style="color: black;">fill</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Flip the changes into view.</span>
pygame.<span style="color: black;">display</span>.<span style="color: black;">flip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Wait for the user to quit.</span>
<span style="color: #ff7700;font-weight:bold;">while</span> pygame.<span style="color: black;">QUIT</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#91;</span>e.<span style="color: #008000;">type</span> <span style="color: #ff7700;font-weight:bold;">for</span> e <span style="color: #ff7700;font-weight:bold;">in</span> pygame.<span style="color: black;">event</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>:
	<span style="color: #ff7700;font-weight:bold;">pass</span></pre></div></div>

<p>Tested on Python 2.6.4, pycairo 1.8.6, Cairo 1.8.8, pygame 1.8.1, numpy 1.3.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2010/03/29/using-cairo-in-pygame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Relation between motor&#8217;s torque/speed and its voltage/current.</title>
		<link>http://doswa.com/blog/2010/01/23/relation-between-motors-torquespeed-and-its-voltagecurrent/</link>
		<comments>http://doswa.com/blog/2010/01/23/relation-between-motors-torquespeed-and-its-voltagecurrent/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 17:18:47 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Physics]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/2010/01/23/relation-between-motors-torquespeed-and-its-voltagecurrent/</guid>
		<description><![CDATA[The torque of a motor is proportional to the current flowing through it (). The angular velocity of a motor is proportional to the voltage across it (). Details and derivation here: motor.pdf.]]></description>
			<content:encoded><![CDATA[<ol>
<li>The <strong>torque</strong> of a motor is proportional to the <strong>current</strong> flowing through it (<img src="http://doswa.com/blog/wp-content/cache/tex_d27da2b4f2d4739eb17c39193b862401.png" align="absmiddle" class="tex" alt="\tau \propto i" />).</li>
<li>The <strong>angular velocity</strong> of a motor is proportional to the <strong>voltage</strong> across it (<img src="http://doswa.com/blog/wp-content/cache/tex_04ec16e4ae1ed7f25751dbb2258811b8.png" align="absmiddle" class="tex" alt="\omega \propto v" />).</li>
</ol>
<p>Details and derivation here: <a href="http://doswa.com/projects/motor_torque_speed/motor.pdf">motor.pdf</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2010/01/23/relation-between-motors-torquespeed-and-its-voltagecurrent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wacom Jitter Fix (for Linux)</title>
		<link>http://doswa.com/blog/2010/01/01/wacom-jitter-fix-for-linux/</link>
		<comments>http://doswa.com/blog/2010/01/01/wacom-jitter-fix-for-linux/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 03:07:14 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/?p=351</guid>
		<description><![CDATA[My Wacom Bamboo Fun tablet has been exceptionally jittery on my Lenovo ThinkPad. I assume this is probably caused by EM noise from the computer (though I&#8217;m not sure). Today I decided I should try to fix that. Here&#8217;s an &#8230; <a href="http://doswa.com/blog/2010/01/01/wacom-jitter-fix-for-linux/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My Wacom Bamboo Fun tablet has been exceptionally jittery on my Lenovo ThinkPad. I assume this is probably caused by EM noise from the computer (though I&#8217;m not sure). Today I decided I should try to fix that.</p>
<p>Here&#8217;s an image to demonstrate the problem (click to enlarge):<br />
<a href="http://doswa.com/blog/wp-content/uploads/2010/01/lines1.png"><img src="http://doswa.com/blog/wp-content/uploads/2010/01/lines1.png" alt="lines1" title="lines1" width="472" height="302" class="aligncenter size-full wp-image-359" /></a></p>
<p>On Ubuntu, there&#8217;s a package called <code>wacom-tools</code> that includes a configuration utility named <code>xsetwacom</code>. The <code>xsetwacom</code> utility has a couple parameters to help against noise: <code>RawSample</code> and <code>Suppress</code>. <code>RawSample</code> allows you to adjust the number of samples taken from the tablet before the coordinates are committed to the mouse pointer on screen. <code>Suppress</code> prevents the mouse pointer from moving unless it has been moved by a given amount. So, all you need to do is tune those parameters to something that works well for your setup. I found the following to be acceptable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xsetwacom <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #ff0000;">&quot;Wacom BambooFun 4x5&quot;</span> RawSample <span style="color: #000000;">9</span>
xsetwacom <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #ff0000;">&quot;Wacom BambooFun 4x5&quot;</span> Suppress <span style="color: #000000;">10</span></pre></div></div>

<p><em>Note that those commands are specifically for the Wacom BambooFun 4&#215;5 tablet. You will probably need to replace that part with something else. You can find out what you should replace it with by executing this command and looking over its output:</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xidump <span style="color: #660033;">--list</span></pre></div></div>

<p>Now, I wanted these commands to be run automatically every time I logged in, so I created a small script at <code>~/.local/bin/wacom_init</code> and put the following in it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
xsetwacom <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #ff0000;">&quot;Wacom BambooFun 4x5&quot;</span> RawSample <span style="color: #000000;">9</span>
xsetwacom <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #ff0000;">&quot;Wacom BambooFun 4x5&quot;</span> Suppress <span style="color: #000000;">10</span></pre></div></div>

<p>Finally, I went in my menu to System &gt; Preferences &gt; Startup Applications and created an entry to automatically run the command <code>/home/david/.local/bin/wacom_init</code>.</p>
<p>All done!</p>
]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2010/01/01/wacom-jitter-fix-for-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Python/Unix Calculator</title>
		<link>http://doswa.com/blog/2010/01/01/calculator/</link>
		<comments>http://doswa.com/blog/2010/01/01/calculator/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 02:50:38 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/?p=343</guid>
		<description><![CDATA[david@second:~$ cat /home/david/.local/bin/= #!/usr/bin/env python __import__&#40;&#34;sys&#34;&#41;.argv&#91;1:&#93; and __import__&#40;&#34;subprocess&#34;&#41;.Popen&#40;&#40;&#34;bc&#34;,&#34;-lq&#34;&#41;,? stdin=__import__&#40;&#34;subprocess&#34;&#41;.PIPE&#41;.communicate&#40;&#34; &#34;.join&#40;__import__&#40;&#34;sys&#34;&#41;? .argv&#91;1:&#93;+&#91;&#34;\n&#34;&#93;&#41;&#41; or __import__&#40;&#34;os&#34;&#41;.waitpid&#40;__import__&#40;&#34;subprocess&#34;&#41;? .Popen&#40;&#40;&#34;bc&#34;,&#34;-lq&#34;&#41;&#41;.pid,0&#41; david@second:~$ = '5*5 + 5' 30 david@second:~$ = 3+1 4 last*2 8 david@second:~$]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">david@second:~$ cat /home/david/.<span style="color: black;">local</span>/bin/=
<span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;sys&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;subprocess&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;bc&quot;</span>,<span style="color: #483d8b;">&quot;-lq&quot;</span><span style="color: black;">&#41;</span>,<span style="color: #66cc66;">?</span>
stdin=<span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;subprocess&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">PIPE</span><span style="color: black;">&#41;</span>.<span style="color: black;">communicate</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; &quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;sys&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span>
.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>+<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;os&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">waitpid</span><span style="color: black;">&#40;</span><span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;subprocess&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">?</span>
.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;bc&quot;</span>,<span style="color: #483d8b;">&quot;-lq&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">pid</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
david@second:~$ = <span style="color: #483d8b;">'5*5 + 5'</span>
<span style="color: #ff4500;">30</span>
david@second:~$ =
<span style="color: #ff4500;">3</span>+<span style="color: #ff4500;">1</span>
<span style="color: #ff4500;">4</span>
last<span style="color: #66cc66;">*</span><span style="color: #ff4500;">2</span>
<span style="color: #ff4500;">8</span>
david@second:~$</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2010/01/01/calculator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DIY aux input on Alpine car stereo (M-BUS)</title>
		<link>http://doswa.com/blog/2010/01/01/diy-aux-input-on-alpine-car-stereo-m-bus/</link>
		<comments>http://doswa.com/blog/2010/01/01/diy-aux-input-on-alpine-car-stereo-m-bus/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 07:51:31 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/?p=324</guid>
		<description><![CDATA[If anything in this article is unclear or confusing, please let me know in the comments and I&#8217;ll do my best to clarify. Disclaimer: by following the instructions below, you may end up destroying your stereo, car, MP3 player, interpersonal &#8230; <a href="http://doswa.com/blog/2010/01/01/diy-aux-input-on-alpine-car-stereo-m-bus/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>If anything in this article is unclear or confusing, please let me know in the comments and I&#8217;ll do my best to clarify.</strong></p>
<p><em>Disclaimer: by following the instructions below, you may end up destroying your stereo, car, MP3 player, interpersonal relationships, and everything else you hold dear. I am not responsible for any of this. That being said, it worked fine for me.</em></p>
<p>This method will work on any Alpine stereos with an 8-pin M-BUS connector in the back. (The stereo I performed this on was an Alpine CDM-9821.) The connector itself should look something like this:<br />
<a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&#038;name=275-1027-ND"><img src="http://doswa.com/blog/wp-content/uploads/2010/01/2dj-0108psa2.jpg" alt="2dj-0108psa2" title="2dj-0108psa2" width="166" height="200" class="aligncenter size-full wp-image-328" /></a></p>
<p>After some searching around, I located the functions of each pin on this connector at <a href="http://pinouts.ru/Home/alpine_cdchanger_pinout.shtml">pinouts.ru</a>. The pins on interest are the bottom three:<br />
<img src="http://doswa.com/blog/wp-content/uploads/2010/01/2dj-0108psa2asdfasdf.jpg" alt="2dj-0108psa2asdfasdf" title="2dj-0108psa2asdfasdf" width="282" height="200" class="aligncenter size-full wp-image-330" /></p>
<p>This corresponds perfectly with the contacts on a 3.5mm headphone plug:<br />
<img src="http://doswa.com/blog/wp-content/uploads/2010/01/ak203mm.jpg" alt="ak203mm" title="ak203mm" width="348" height="250" class="aligncenter size-full wp-image-332" /></p>
<p>So all that&#8217;s left to do is make an adapter between the two. I ordered these parts from Digi-Key: <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&#038;name=CP-1080-ND">CP-1080-ND</a>, <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&#038;name=AE9918-ND">AE9918-ND</a>, and <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?WT.z_header=search_go&#038;lang=en&#038;site=us&#038;keywords=CP1-3513-ND&#038;x=0&#038;y=0">CP1-3513-ND</a>.</p>
<p>Gather up some solder, a soldering iron, and wire. Make the following connections:</p>
<ol>
<li>&#8220;Audio Ground&#8221; pin from the M-BUS connector goes to the pin closest to the hole on the 3.5mm audio jack</li>
<li>&#8220;Right Audio Input&#8221; goes to the pin farthest from the hole</li>
<li>&#8220;Left Audio Input&#8221; goes to the only remaining pin.</li>
</ol>
<p>You should end up with an adapter cable like this:<br />
<img src="http://doswa.com/blog/wp-content/uploads/2010/01/sj1-3513.jpg" alt="sj1-3513" title="sj1-3513" width="476" height="250" class="aligncenter size-full wp-image-335" /></p>
<p>Plug the M-BUS connector into the back of your stereo and mount the audio jack somewhere on the dash.</p>
<p>Now turn on your car. If all went well, nothing will start on fire. Hold the &#8220;Setup&#8221; button on the stereo and enable aux input in the menu. Now hit the &#8220;Source&#8221; button until you get to AUX. At this point, you should be able to plug in an MP3 player and have the audio routed to your car&#8217;s speakers.</p>
]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2010/01/01/diy-aux-input-on-alpine-car-stereo-m-bus/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SparkFun&#8217;s FTDI Basic Breakout as an AVR programmer</title>
		<link>http://doswa.com/blog/2009/12/20/sparkfuns-ftdi-basic-breakout-as-an-avr-programmer/</link>
		<comments>http://doswa.com/blog/2009/12/20/sparkfuns-ftdi-basic-breakout-as-an-avr-programmer/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 18:28:13 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/?p=308</guid>
		<description><![CDATA[Start by following my instructions for setting up AVRDUDE 5.8 with FTDI bitbanging support. Now open up avrdude.conf in a text editor. Add this entry by the other programmers: # FTDI basic breakout programmer id = "ftdi"; desc = "FTDI &#8230; <a href="http://doswa.com/blog/2009/12/20/sparkfuns-ftdi-basic-breakout-as-an-avr-programmer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://doswa.com/blog/wp-content/uploads/2009/12/screenshot1.jpg"><img src="http://doswa.com/blog/wp-content/uploads/2009/12/screenshot1.jpg" alt="screenshot1" title="screenshot1" width="384" height="320" class="aligncenter size-full wp-image-310" /></a></p>
<p>Start by following my instructions for setting up <a href="http://doswa.com/blog/2009/12/20/avrdude-58-with-ftdi-bitbang-patch-on-linux/">AVRDUDE 5.8 with FTDI bitbanging support</a>.</p>
<p>Now open up <code>avrdude.conf</code> in a text editor. Add this entry by the other programmers:</p>
<pre># FTDI basic breakout
programmer
  id = "ftdi";
  desc = "FTDI Basic Breakout";
  type = ft245r;
  miso = 1; # RxD
  sck = 3; # CTS
  mosi = 0; # TxD
  reset = 4; # DTR
;</pre>
<p>Now you can attach your FTDI Breakout to the target AVR like this:<br />
<u>FTDI -> MCU (ATmega168 PDIP pin)</u><br />
DTR -> RESET (1)<br />
RXI -> MISO (18)<br />
TXO -> MOSI (17)<br />
5V -> VCC (7 &#038; 20)<br />
CTS -> SCK (19)<br />
GND -> GND (8 &#038; 22)</p>
<p>With the 3&#215;2 ISCP header on the Arduino, that would look like this:</p>
<pre>        +----------------+
[RXI]--o| 1 MISO   +5V 2 |o--[5V]
[CTS]--o| 3 SCK   MOSI 4 |o--[TXO]
[DTR]--o| 5 RESET  GND 6 |o--[GND]
        +----------------+</pre>
<p>Note that may need to supply the AVR with an external oscillator or clock source. For virgin ATmega168s, you won&#8217;t need to (because it initially uses the internal oscillator), but you&#8217;ll need an external crystal oscillator if you&#8217;re using one that came out of an Arduino.</p>
<p>From there you can use AVRDUDE like normal using the `-c ftdi` switch. For example, to read fuse bytes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>avrdude <span style="color: #660033;">-C</span> avrdude.conf <span style="color: #660033;">-c</span> ftdi <span style="color: #660033;">-p</span> m168 <span style="color: #660033;">-P</span> ft0 <span style="color: #660033;">-U</span> hfuse:r:-:h <span style="color: #660033;">-U</span> lfuse:r:-:h <span style="color: #660033;">-U</span> efuse:r:-:h</pre></div></div>

<p><strong>Edit 2010-04-18:</strong></p>
<p>I just found out that new AVRs need to have the clock rate adjusted before this will work. This is because AVRs come with the internal clock set to 1 MHz (actually, 8 MHz with the CKDIV8 fuse bit set) instead of the Arduino default 16 MHz. This can be done with AVRDUDE&#8217;s <code>-B</code> option. This option determines what clock is fed into the AVR&#8217;s SCK pin. I recommend starting with a value of <code>-B 1</code> and working your way up to a reasonable clock speed. Here is the adjusted command for new AVRs:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>avrdude <span style="color: #660033;">-C</span> avrdude.conf <span style="color: #660033;">-c</span> ftdi <span style="color: #660033;">-p</span> m168 <span style="color: #660033;">-P</span> ft0 <span style="color: #660033;">-U</span> hfuse:r:-:h <span style="color: #660033;">-U</span> lfuse:r:-:h <span style="color: #660033;">-U</span> efuse:r:-:h <span style="color: #660033;">-B</span> <span style="color: #000000;">1</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2009/12/20/sparkfuns-ftdi-basic-breakout-as-an-avr-programmer/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AVRDUDE 5.8 with FTDI bitbang patch on Linux</title>
		<link>http://doswa.com/blog/2009/12/20/avrdude-58-with-ftdi-bitbang-patch-on-linux/</link>
		<comments>http://doswa.com/blog/2009/12/20/avrdude-58-with-ftdi-bitbang-patch-on-linux/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 18:16:23 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://doswa.com/blog/?p=292</guid>
		<description><![CDATA[Description: This is an adaptation of the work by Kimio Kosaka, Nate Phillips, and Massimo. It allows you to use AVRDUDE with an FTDI chip (like the one on the Arduino boards or SparkFun&#8217;s FTDI Basic Breakout). This can be &#8230; <a href="http://doswa.com/blog/2009/12/20/avrdude-58-with-ftdi-bitbang-patch-on-linux/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Description:</strong> <em>This is an adaptation of the work by <a href="http://www.geocities.jp/arduino_diecimila/bootloader/index_old_en.html">Kimio Kosaka</a>, <a href="http://labs.coffeebot.net/content/ftdi-drivers-avrdude-linux">Nate Phillips</a>, and <a href="http://savannah.nongnu.org/users/runaway">Massimo</a>. It allows you to use AVRDUDE with an FTDI chip (like the one on the Arduino boards or SparkFun&#8217;s FTDI Basic Breakout). This can be useful if you manage to brick your Arduino and you have no programmer.</em></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>If you&#8217;re on Ubuntu or Debian, install the prerequisites with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">patch</span> build-essential libreadline-dev libncurses-dev libusb-dev
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> build-dep avrdude avrdude-doc</pre></div></div>

<p>&#8212;</p>
<p>Start by grabbing a copy of AVRDUDE 5.8, untarring it in the directory, and switching to that directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>download.savannah.gnu.org<span style="color: #000000; font-weight: bold;">/</span>releases-noredirect<span style="color: #000000; font-weight: bold;">/</span>avrdude<span style="color: #000000; font-weight: bold;">/</span>avrdude-5.8.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xzf avrdude-5.8.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> avrdude-<span style="color: #000000;">5.8</span></pre></div></div>

<p>&#8212;</p>
<p>Now get a copy of the FTDI bitbang patch files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">8</span> <span style="color: #000000;">7</span> <span style="color: #000000;">6</span> <span style="color: #000000;">5</span> <span style="color: #000000;">4</span> <span style="color: #000000;">3</span> <span style="color: #000000;">2</span> <span style="color: #000000;">1</span> <span style="color: #000000;">0</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-O</span> patch-<span style="color: #007800;">$i</span>.diff http:<span style="color: #000000; font-weight: bold;">//</span>savannah.nongnu.org<span style="color: #000000; font-weight: bold;">/</span>patch<span style="color: #000000; font-weight: bold;">/</span>download.php?<span style="color: #007800;">file_id</span>=<span style="color: #000000;">1851</span><span style="color: #007800;">$i</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>&#8212;</p>
<p>Apply the patches:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> patch-<span style="color: #000000; font-weight: bold;">*</span>.diff; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">patch</span> <span style="color: #660033;">-p0</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$file</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>&#8212;</p>
<p>Also get a copy of the FTDI driver. For 32-bit:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.ftdichip.com<span style="color: #000000; font-weight: bold;">/</span>Drivers<span style="color: #000000; font-weight: bold;">/</span>D2XX<span style="color: #000000; font-weight: bold;">/</span>Linux<span style="color: #000000; font-weight: bold;">/</span>libftd2xx0.4.16.tar.gz</pre></div></div>

<p>For 64-bit:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.ftdichip.com<span style="color: #000000; font-weight: bold;">/</span>Drivers<span style="color: #000000; font-weight: bold;">/</span>D2XX<span style="color: #000000; font-weight: bold;">/</span>Linux<span style="color: #000000; font-weight: bold;">/</span>libftd2xx0.4.16_x86_64.tar.gz</pre></div></div>

<p>&#8212;</p>
<p>Extract the FTDI driver and copy over the needed files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> xzf libftd2xx<span style="color: #000000; font-weight: bold;">*</span>.tar.gz
<span style="color: #c20cb9; font-weight: bold;">cp</span> libftd2xx<span style="color: #000000; font-weight: bold;">*/</span>static_lib<span style="color: #000000; font-weight: bold;">/*</span> .
<span style="color: #c20cb9; font-weight: bold;">cp</span> libftd2xx<span style="color: #000000; font-weight: bold;">*/*</span>.h .
<span style="color: #c20cb9; font-weight: bold;">cp</span> libftd2xx<span style="color: #000000; font-weight: bold;">*/*</span>.cfg .</pre></div></div>

<p>&#8212;</p>
<p>Generate your makefile:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure</pre></div></div>

<p>&#8212;</p>
<p>Open <code>Makefile</code> in a text editor and perform the following operations:</p>
<ol>
<li>Find the line <code>CFLAGS = -g -O2</code> and replace it with <code>CFLAGS = -g -O2 -DHAVE_LIBUSB -DSUPPORT_FT245R</code>.</li>
<li>Find the line <code>LIBS = -lreadline -lncurses -ltermcap</code> and replace it with <code>LIBS = -lreadline -lncurses -ltermcap ./libftd2xx.a.0.4.16 -lrt</code>.</li>
</ol>
<p>&#8212;</p>
<p>Now to actually compile it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<p>&#8212;</p>
<p>From here, you can follow the instructions at <a href="http://www.geocities.jp/arduino_diecimila/bootloader/index_old_en.html">http://www.geocities.jp/arduino_diecimila/bootloader/index_old_en.html</a> starting at step 5. Note that you&#8217;ll need to modify the commands a little bit. Instead of:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">avrdude <span style="color: #660033;">-c</span> diecimila <span style="color: #660033;">-P</span> ft0 <span style="color: #660033;">-p</span> m168</pre></div></div>

<p>you should write:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>avrdude <span style="color: #660033;">-C</span> avrdude.conf <span style="color: #660033;">-c</span> duemilanove <span style="color: #660033;">-P</span> ft0 <span style="color: #660033;">-p</span> m168</pre></div></div>

<p>(Note: you can still use it on a Diecimila, just specify the programmer as `-c duemilanove` and it should work.)</p>
<p>If you&#8217;d like to use SparkFun&#8217;s FTDI Basic Breakout as a programmer, try <a href="http://doswa.com/blog/2009/12/20/sparkfuns-ftdi-basic-breakout-as-an-avr-programmer/">these instructions</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://doswa.com/blog/2009/12/20/avrdude-58-with-ftdi-bitbang-patch-on-linux/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
