<?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>work in progress &#187; Electronics</title>
	<atom:link href="http://www.workinprogress.ca/category/electronics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.workinprogress.ca</link>
	<description>of patrick sébastien coulombe</description>
	<lastBuildDate>Mon, 26 Jul 2010 02:37:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>cheap avr intervalometer</title>
		<link>http://www.workinprogress.ca/avr-intervalometer/</link>
		<comments>http://www.workinprogress.ca/avr-intervalometer/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 08:38:21 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Blender]]></category>
		<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=755</guid>
		<description><![CDATA[now that i have a digital camera (but my heart will always belong to film-based photography) i can do time lapse photography. sadly the firmware of my camera isn&#8217;t supporting this feature, so i had to build an intervalometer. i didn&#8217;t want to use an arduino (overkill &#38; pricy), so i went with an attiny45, [...]]]></description>
			<content:encoded><![CDATA[<p>now that i have a digital camera (but my heart will always belong to film-based photography) i can do time lapse photography. sadly the firmware of my camera isn&#8217;t supporting this feature, so i had to build an <a href="http://en.wikipedia.org/wiki/Intervalomete" target="_blank">intervalometer</a>. i didn&#8217;t want to use an arduino (overkill &amp; pricy), so i went with an attiny45, a generic optocoupler, a voltage regulator and a potentiometer for adjusting the timer from 1 second to 1 minute.</p>

<a href='http://www.workinprogress.ca/avr-intervalometer/intervalometer_1/' title='intervalometer_1'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/intervalometer_1-150x150.jpg" class="attachment-thumbnail" alt="intervalometer_1" title="intervalometer_1" /></a>
<a href='http://www.workinprogress.ca/avr-intervalometer/intervalometer_3/' title='intervalometer_3'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/intervalometer_3-150x150.jpg" class="attachment-thumbnail" alt="intervalometer_3" title="intervalometer_3" /></a>
<a href='http://www.workinprogress.ca/avr-intervalometer/avr_intervalometer_schematic/' title='avr_intervalometer_schematic'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/avr_intervalometer_schematic-150x150.png" class="attachment-thumbnail" alt="avr_intervalometer_schematic" title="avr_intervalometer_schematic" /></a>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Intervalometer from 1 second to 1 minute</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Author: Patrick Sebastien Coulombe</span>
<span style="color: #666666; font-style: italic;">//Website: www.workinprogress.ca</span>
<span style="color: #666666; font-style: italic;">//Date: 2010-07-24</span>
&nbsp;
<span style="color: #339933;">#define F_CPU 8000000</span>
<span style="color: #339933;">#include &lt;avr/io.h&gt;</span>
<span style="color: #339933;">#include &lt;util/delay.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// use PB2 for led, pin 7</span>
<span style="color: #339933;">#define LED_BIT 2</span>
<span style="color: #666666; font-style: italic;">// select ADC2, PB4, pin 3</span>
<span style="color: #339933;">#define CHANNEL 2</span>
<span style="color: #666666; font-style: italic;">// shutter on (in ms)</span>
<span style="color: #339933;">#define HOLD 300 </span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Return the 10bit value of the selected adc channel.</span>
uint16_t get_adc<span style="color: #009900;">&#40;</span>uint8_t channel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// ADC setup</span>
	ADCSRA <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADEN<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADPS1<span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADPS0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// select channel</span>
	ADMUX <span style="color: #339933;">=</span> channel<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// warm up the ADC, discard the first conversion</span>
	ADCSRA <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADSC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>ADCSRA <span style="color: #339933;">&amp;</span><span style="color: #339933;">#038; (1 &lt;&lt; ADSC)); </span>
&nbsp;
	ADCSRA <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> ADSC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// start single conversion</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>ADCSRA <span style="color: #339933;">&amp;</span><span style="color: #339933;">#038; (1 &lt;&lt; ADSC)); // wait until conversion is done</span>
&nbsp;
	<span style="color: #b1b100;">return</span> ADCW<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Scale</span>
<span style="color: #993333;">long</span> map<span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> x<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> in_min<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> in_max<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> out_min<span style="color: #339933;">,</span> <span style="color: #993333;">long</span> out_max<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">-</span> in_min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>out_max <span style="color: #339933;">-</span> out_min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>in_max <span style="color: #339933;">-</span> in_min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> out_min<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Main program</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// vars</span>
	uint16_t adcvalue <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	uint16_t i<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// define LED as outputs</span>
	DDRB <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> LED_BIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
&nbsp;
		<span style="color: #666666; font-style: italic;">//release the shutter</span>
		PORTB <span style="color: #339933;">|=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> LED_BIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//exposure length</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>HOLD<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			_delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
		PORTB <span style="color: #339933;">&amp;</span><span style="color: #339933;">#038;= ~(1 &lt;&lt; LED_BIT);</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//interval time (using a potentiometer to adjust)</span>
		adcvalue <span style="color: #339933;">=</span> map<span style="color: #009900;">&#40;</span>get_adc<span style="color: #009900;">&#40;</span>CHANNEL<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1023</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		adcvalue <span style="color: #339933;">=</span> adcvalue <span style="color: #339933;">*</span> <span style="color: #0000dd;">1000</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//one way to achieve long delay</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> adcvalue<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			_delay_ms<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></code></p>
<p>A short time lapse test (4 hours) from my balcony. I used Blender for making the tilt / shift effect. Here's the <a href="http://www.workinprogress.ca/wp-content/uploads/blendertiltshift.tar.gz">source</a> of the Blender file + the png mask.</p>
<p>
<object width="540" height="405"><param name="movie" value="http://www.youtube.com/v/8nQMBAMxHys&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/8nQMBAMxHys&amp;hl=en_US&amp;fs=1?rel=0&amp;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="540" height="405"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/avr-intervalometer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>singing birds</title>
		<link>http://www.workinprogress.ca/singing-birds/</link>
		<comments>http://www.workinprogress.ca/singing-birds/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 04:36:59 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=706</guid>
		<description><![CDATA[10 watts amplifier with built-in 16-bit / 48kHz RIFF-WAVE player (music on a SD-CARD). 2 servos for controlling the beaks. I did this project mostly to learn stuff. The result is a bit stupid, i do agree. VIDEO: &#160; PHOTOS:]]></description>
			<content:encoded><![CDATA[<p>10 watts amplifier with built-in 16-bit / 48kHz RIFF-WAVE player (music on a SD-CARD). 2 servos for controlling the beaks. I did this project mostly to learn stuff. The result is a bit stupid, i do agree.</p>
<p><strong>VIDEO:</strong><br />
<img src="http://www.workinprogress.ca/wp-content/plugins/flash-video-player/default_video_player.gif" /></p>
<p>&nbsp;</p>
<p><strong>PHOTOS:</strong><br />

<a href='http://www.workinprogress.ca/singing-birds/p4120089/' title='passive crossover'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4120089-150x150.jpg" class="attachment-thumbnail" alt="passive crossover" title="passive crossover" /></a>
<a href='http://www.workinprogress.ca/singing-birds/p4130093/' title='back - 2 mini servo'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4130093-150x150.jpg" class="attachment-thumbnail" alt="back - 2 mini servo" title="back - 2 mini servo" /></a>
<a href='http://www.workinprogress.ca/singing-birds/p4130094/' title='single-side homemade PCB'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4130094-150x150.jpg" class="attachment-thumbnail" alt="single-side homemade PCB" title="single-side homemade PCB" /></a>
<a href='http://www.workinprogress.ca/singing-birds/p4130095/' title='front'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4130095-150x150.jpg" class="attachment-thumbnail" alt="front" title="front" /></a>
<a href='http://www.workinprogress.ca/singing-birds/blender/' title='i used blender like a CAD software'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/blender-150x150.jpg" class="attachment-thumbnail" alt="i used blender like a CAD software" title="i used blender like a CAD software" /></a>
<a href='http://www.workinprogress.ca/singing-birds/board/' title='attiny85 - attiny24 - tpa1517ne - pwm filter - opamp'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/board-150x150.jpg" class="attachment-thumbnail" alt="attiny85 - attiny24 - tpa1517ne - pwm filter - opamp" title="attiny85 - attiny24 - tpa1517ne - pwm filter - opamp" /></a>
<a href='http://www.workinprogress.ca/singing-birds/schematic-2/' title='schematic - done in kicad'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/schematic1-150x150.jpg" class="attachment-thumbnail" alt="schematic - done in kicad" title="schematic - done in kicad" /></a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/singing-birds/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>biscuit box computer</title>
		<link>http://www.workinprogress.ca/biscuit-box-computer/</link>
		<comments>http://www.workinprogress.ca/biscuit-box-computer/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 23:06:04 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=674</guid>
		<description><![CDATA[i am sure there&#8217;s plenty of projects like this one. the idea is to get a &#8220;cheap&#8221; and &#8220;small&#8221; full featured linux box. a good keyword to start with: itx motherboard cpu combo. this one have hdmi 1080p, wifi, dual-core 1.6 ghz. i paid 147$ used. got also 1 gig of used ram for 20$. [...]]]></description>
			<content:encoded><![CDATA[<p>i am sure there&#8217;s plenty of projects like this one. the idea is to get a &#8220;cheap&#8221; and &#8220;small&#8221; full featured linux box. a good keyword to start with: itx motherboard cpu combo. this one have hdmi 1080p, wifi, dual-core 1.6 ghz. i paid 147$ used. got also 1 gig of used ram for 20$. total of 167$ CAD. weight is 0.8 kg for the box and 0.3 kg for the supply. Just 18W at idle, and 23W full load (someone measured it with a Kill-a-watt device). the power supply is 90W. for the storage, i went with a laptop hard-drive (it&#8217;s smaller). i paid 100$ for a 500 gig, 7200 rpm, sata.</p>
<p>all this information will be outdated, now.</p>

<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020066/' title='P4020066'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020066-150x150.jpg" class="attachment-thumbnail" alt="P4020066" title="P4020066" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020069/' title='itx motherboard cpu combo with the external supply'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020069-150x150.jpg" class="attachment-thumbnail" alt="itx motherboard cpu combo with the external supply" title="itx motherboard cpu combo with the external supply" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020072/' title='P4020072'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020072-150x150.jpg" class="attachment-thumbnail" alt="P4020072" title="P4020072" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020073/' title='P4020073'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020073-150x150.jpg" class="attachment-thumbnail" alt="P4020073" title="P4020073" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4020074/' title='P4020074'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4020074-150x150.jpg" class="attachment-thumbnail" alt="P4020074" title="P4020074" /></a>
<a href='http://www.workinprogress.ca/biscuit-box-computer/p4300098/' title='laptop hard-drive fixed on top'><img width="150" height="150" src="http://www.workinprogress.ca/wp-content/uploads/P4300098-150x150.jpg" class="attachment-thumbnail" alt="laptop hard-drive fixed on top" title="laptop hard-drive fixed on top" /></a>

<p>running a realtime kernel with enlightenment and blender:</p>
<p><object width="400" height="320"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=11384664&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=11384664&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="320"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/biscuit-box-computer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>kicad &#8211; video tutorial</title>
		<link>http://www.workinprogress.ca/kicad-video-tutorial/</link>
		<comments>http://www.workinprogress.ca/kicad-video-tutorial/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 07:49:01 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=622</guid>
		<description><![CDATA[Kicad is an open source (GPL) software for the creation of electronic schematic diagrams and printed circuit board artwork. schematic editor &#38; cvpcb (transcript): pcbnew (transcript): V-USB kicad project (clean): http://www.workinprogress.ca/wp-content/uploads/kicad_vusb.zip Kicad: http://kicad.sourceforge.net/wiki/index.php/Main_Page Update: http://kicad.1301.cz/ Libraries: http://kicadlib.org/ http://per.launay.free.fr/kicad/kicad_php/composant.php]]></description>
			<content:encoded><![CDATA[<p><strong>Kicad</strong> is an open source (GPL) software for the creation of electronic schematic diagrams and printed circuit board artwork.</p>
<p>schematic editor &amp; cvpcb (<a href="http://www.workinprogress.ca/wp-content/uploads/eeschema.txt">transcript</a>):</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="540" height="405" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/rkQ0nVX1q1k&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="540" height="405" src="http://www.youtube.com/v/rkQ0nVX1q1k&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>pcbnew (<a href="http://www.workinprogress.ca/wp-content/uploads/pcbnew.txt">transcript</a>):</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="540" height="405" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/8HNMihqa844&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="540" height="405" src="http://www.youtube.com/v/8HNMihqa844&amp;hl=en_US&amp;fs=1&amp;rel=0&amp;hd=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>V-USB kicad project (clean):<br />
<a href="http://www.workinprogress.ca/wp-content/uploads/kicad_vusb.zip">http://www.workinprogress.ca/wp-content/uploads/kicad_vusb.zip</a></p>
<p>Kicad:<br />
<a href="http://kicad.sourceforge.net/wiki/index.php/Main_Page">http://kicad.sourceforge.net/wiki/index.php/Main_Page</a></p>
<p>Update:<br />
<a href="http://kicad.1301.cz/">http://kicad.1301.cz/</a></p>
<p>Libraries:<br />
<a href="http://kicadlib.org/">http://kicadlib.org/</a><br />
<a href="http://per.launay.free.fr/kicad/kicad_php/composant.php">http://per.launay.free.fr/kicad/kicad_php/composant.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/kicad-video-tutorial/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>filtering pwm for music</title>
		<link>http://www.workinprogress.ca/filtering-pwm-for-music/</link>
		<comments>http://www.workinprogress.ca/filtering-pwm-for-music/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 06:37:58 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=581</guid>
		<description><![CDATA[i would like to start by saying that this solution might not be the best&#8230; if any analog guru read this, please leave a comment. for 2.75$ you can have a chip that is able to run at 64 mhz (phase-locked loop) and output a pulse width modulation at 250 khz. attiny85 is your friend [...]]]></description>
			<content:encoded><![CDATA[<p><em>i would like to start by saying that this solution might not be the best&#8230; if any analog guru read this, please leave a comment.</em></p>
<p>for 2.75$ you can have a chip that is able to run at 64 mhz (phase-locked loop) and output a pulse width modulation at 250 khz. attiny85 is your friend here. i didn&#8217;t found any atmega with this option (pll)&#8230; the good news is that it&#8217;s fast enough to output a stereo WAV at 16 bits / 48 khz. if you are interested in this project, take a look here: <a href="http://elm-chan.org/works/sd8p/report.html" target="_blank">http://elm-chan.org/works/sd8p/report.html</a></p>
<p>since i want to connect the pwm output in a power amplifier, i need to filter the signal. here&#8217;s the waveform of the pulse width modulation @ 440 hz:</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/pwm_signal.jpg"><img class="alignnone size-medium wp-image-587" title="pwm_signal" src="http://www.workinprogress.ca/wp-content/uploads/pwm_signal-300x242.jpg" alt="pwm_signal" width="300" height="242" /></a></p>
<p>now let&#8217;s see if we use a simple <a href="http://en.wikipedia.org/wiki/Low-pass_filter#Passive_electronic_realization" target="_blank">RC low pass</a>:</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_rc_osc.jpg"><img class="alignnone size-medium wp-image-589" title="pwm_filtered_rc_osc" src="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_rc_osc-300x241.jpg" alt="pwm_filtered_rc_osc" width="300" height="241" /></a></p>
<p>looks good to me, but then testing with a triangle instead of an oscillator revealed this:</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_rc_tri.jpg"><img class="alignnone size-medium wp-image-590" title="pwm_filtered_rc_tri" src="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_rc_tri-300x242.jpg" alt="pwm_filtered_rc_tri" width="300" height="242" /></a></p>
<p>that&#8217;s not beautiful&#8230; here&#8217;s a close-up:</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_closeup_rc.jpg"><img class="alignnone size-medium wp-image-592" title="pwm_filtered_closeup_rc" src="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_closeup_rc-300x240.jpg" alt="pwm_filtered_closeup_rc" width="300" height="240" /></a></p>
<p>maybe using more passive filter could help, but since you need to use an op-amp as a buffer (so that your load doesn&#8217;t affect the RC filter), why not use a <a href="http://en.wikipedia.org/wiki/Sallen%E2%80%93Key_topology#Example:_Low-pass_filter" target="_blank">sallen-key topology</a>. this will act as an active low pass filter and a buffer. let&#8217;s look at the results:</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_sk_tri.jpg"><img class="alignnone size-medium wp-image-594" title="pwm_filtered_sk_tri" src="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_sk_tri-300x240.jpg" alt="pwm_filtered_sk_tri" width="300" height="240" /></a></p>
<p>close-up:</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_closeup_sk.jpg"><img class="alignnone size-medium wp-image-595" title="pwm_filtered_closeup_sk" src="http://www.workinprogress.ca/wp-content/uploads/pwm_filtered_closeup_sk-300x240.jpg" alt="pwm_filtered_closeup_sk" width="300" height="240" /></a></p>
<p>not perfect, but better!</p>
<p><strong>SIMULATIONS<br />
<span style="font-weight: normal;">simple RC (250khz = -22db)<br />
<a href="http://www.workinprogress.ca/wp-content/uploads/rc.jpg"><img class="alignnone size-full wp-image-608" title="rc" src="http://www.workinprogress.ca/wp-content/uploads/rc.jpg" alt="" width="331" height="309" /></a></span></strong></p>
<p>sallen-key second-order (250khz = -44db)<br />
<a href="http://www.workinprogress.ca/wp-content/uploads/skso.jpg"><img class="alignnone size-full wp-image-609" title="skso" src="http://www.workinprogress.ca/wp-content/uploads/skso.jpg" alt="" width="339" height="306" /></a></p>
<p>sallen-key third-order (250khz = -67db)<br />
<a href="http://www.workinprogress.ca/wp-content/uploads/skto.jpg"><img class="alignnone size-full wp-image-610" title="skto" src="http://www.workinprogress.ca/wp-content/uploads/skto.jpg" alt="" width="347" height="306" /></a></p>
<p>third-order is the best and using <a href="http://www.beis.de/Elektronik/Filter/Act3PoleLP.html" target="_blank">this method</a> only 1 stage is needed.</p>
<p>when choosing the op-amp, consider this:<br />
100 * highest Q * GBW = Gain Bandwidth Product (read about it <a href="http://www.beis.de/Elektronik/Filter/Filter.html" target="_blank">here</a>)<a title="Volt" href="http://en.wikipedia.org/wiki/Volt"><br />
</a>slew rate =&gt; 2V/µs<br />
i am using a rail-to-rail input / output op-amp.</p>
<p>now simply add an electrolytic capacitor (100 uf) and you can feed an amplifier with the original pwm signal (hopefully).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/filtering-pwm-for-music/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>V-USB tutorial (software-only usb for mega &amp; tiny)</title>
		<link>http://www.workinprogress.ca/v-usb-tutorial-software-only-usb-for-mega-tiny/</link>
		<comments>http://www.workinprogress.ca/v-usb-tutorial-software-only-usb-for-mega-tiny/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 23:31:07 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=430</guid>
		<description><![CDATA[Arduino use the FTDI chip for usb communication. This chip is expensive and only surface mount. To save money and be able to make a PCB at home, i found a software-only implementation of USB for AVR (attiny, atmega): http://www.obdev.at/products/vusb/index.html. You don&#8217;t need the 2 LEDs. It&#8217;s a visual feedback (debug, bootloader). I am using [...]]]></description>
			<content:encoded><![CDATA[<p>Arduino use the FTDI chip for usb communication. This chip is expensive and only surface mount. To save money and be able to make a PCB at home, i found a software-only implementation of USB for AVR (attiny, atmega): <a href="http://www.obdev.at/products/vusb/index.html">http://www.obdev.at/products/vusb/index.html</a>.</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/vusb_schematic.jpg"><img class="alignnone size-medium wp-image-487" title="vusb_schematic" src="http://www.workinprogress.ca/wp-content/uploads/vusb_schematic-300x225.jpg" alt="vusb_schematic" width="300" height="225" /></a></p>
<p>You don&#8217;t need the 2 LEDs.<br />
It&#8217;s a visual feedback (debug, bootloader).</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/vusb_breadboard.jpg"><img class="alignnone size-medium wp-image-473" title="vusb_breadboard" src="http://www.workinprogress.ca/wp-content/uploads/vusb_breadboard-300x147.jpg" alt="vusb_breadboard" width="300" height="147" /></a></p>
<p><span style="color: #800000;">I am using an ATMEGA164p.<br />
The example code need to be modify to fit your device (bootloader address, registers, EEPROM functions).</span></p>
<p><em>This tutorial is for people who have some experience or are patient. Please pardon my english.</em></p>
<p><strong>1)</strong> <strong>breadboard</strong> your avr for programmation (SPI / JTAG)</p>
<p><strong>2)</strong> download <strong>vusb</strong> (<a href="http://www.obdev.at/products/vusb/download.html" target="_blank">last version</a>)</p>
<p><strong>BOOTLOADERHID</strong><em> (optional)</em><br />
<strong>3)</strong> download <strong>bootloadhid</strong> (<a href="http://www.obdev.at/products/vusb/bootloadhid.html" target="_blank">last version</a>)<br />
This bootloader doesn&#8217;t require a driver (it&#8217;s HID). With it, you will be able to program your firmware without your programmer.</p>
<p><strong>4)</strong> <strong>delete</strong> usbdrv, <strong>cp</strong> the usbdrv from vusb<br />
<strong>5)</strong> open <strong>usbconfig.h</strong> &#8211; change the VENDOR and DEVICE name if you want<br />
<strong>6)</strong> open <strong>bootloaderconfig.h</strong> &#8211; set the pin for usb (USB_CFG_DMINUS_BIT &#8211; USB_CFG_DPLUS_BIT) and if you want to be able to reset via usb (USB_CFG_PULLUP_IOPORTNAME). Change the bootloadcondition to suit your needs, i am using the EEPROM to write (from the firmware) and read (from the bootloader) for the condition +  2 leds (so i know that i am in the bootloader).</p>
<p><a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1118339235'), this, 'show code &#9660;', 'hide code &#9650;');">show code &#9660;</a></p>
<div id='SID1118339235' style='display:none;'>
<pre class="brush:c">#define JUMPER_BIT  5
#define BOOTLED_BIT  6
#define BOOTLED_BITB  7

static inline void  bootLoaderInit(void)
{
	DDRD |= (1 &lt;&lt; BOOTLED_BIT);     // turn bootloader led on
	DDRD |= (1 &lt;&lt; BOOTLED_BITB);     // turn bootloader led on 2
	PORTD |= (1 &lt;&lt; JUMPER_BIT);     /* activate pull-up */
	_delay_us(10);  /* wait for levels to stabilize */
}

static inline void  bootLoaderExit(void)
{
    PORTD = (1 &lt;&lt; BOOTLED_BIT);                 // turn bootloader led off
    PORTD = (1 &lt;&lt; BOOTLED_BITB);                 // turn bootloader led off
}</pre>
</div>
<p><strong>7)</strong> main.c: Edit your condition, mine looks like this:<br />
<a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1664278856'), this, 'show code &#9660;', 'hide code &#9650;');">show code &#9660;</a></p>
<div id='SID1664278856' style='display:none;'>
<pre class="brush:c">...
static void leaveBootloader()
{
 DBG1(0x01, 0, 0);
 bootLoaderExit();
 cli();
...

// - Write to EEPROM
void eepromWrite(unsigned int uiAddress, unsigned char ucData)
{
 /* Wait for completion of previous write */
 while(EECR &amp; (1&lt;&lt;EEPE));
 /* Set up address and Data Registers */
 EEAR = uiAddress;
 EEDR = ucData;
 cli();
 /* Write logical one to EEMPE */
 EECR |= (1&lt;&lt;EEMPE);
 /* Start eeprom write by setting EEPE */
 EECR |= (1&lt;&lt;EEPE);
 sei();
}

// - Read EEPROM
unsigned char eepromRead(unsigned int uiAddress)
{
 /* Wait for completion of previous write */
 while(EECR &amp; (1&lt;&lt;EEPE));
 /* Set up address register */
 EEAR = uiAddress;
 /* Start eeprom read by writing EERE */
 EECR |= (1&lt;&lt;EERE);
 /* Return data from Data Register */
 return EEDR;
}

int main(void)
{
 /* initialize hardware */
 bootLoaderInit();
 odDebugInit();
 DBG1(0x00, 0, 0);

 unsigned char do_boot_load;
 unsigned char do_boot_load_via_eeprom;

 do_boot_load = ~PIND &amp; (1 &lt;&lt; JUMPER_BIT);  // see if jumper is set (= 0)
 do_boot_load_via_eeprom = eepromRead(0); // bootloader bit in eeprom address 0

 /* jump to application if jumper is set */
 if(do_boot_load || do_boot_load_via_eeprom){
 eepromWrite(0, 0); // reset bit in eeprom
 PORTD &amp;= ~(1 &lt;&lt; BOOTLED_BIT);  /// Light led
 PORTD &amp;= ~(1 &lt;&lt; BOOTLED_BITB);  /// Light second led

 uchar i = 0, j = 0;
#ifndef TEST_MODE
 GICR = (1 &lt;&lt; IVCE);  /* enable change of interrupt vectors */
 GICR = (1 &lt;&lt; IVSEL); /* move interrupts to boot flash section */
#endif
 initForUsbConnectivity();
 do{ /* main event loop */
 wdt_reset();
 usbPoll();
#if BOOTLOADER_CAN_EXIT
 if(exitMainloop){
#if F_CPU == 12800000
 break;  /* memory is tight at 12.8 MHz, save exit delay below */
#endif
 if(--i == 0){
 if(--j == 0)
 break;
 }
 }
#endif
 }while(1);
 }
 leaveBootloader();
 return 0;
}</pre>
</div>
<p><strong>8)</strong> edit the Makefile</p>
<p>You need to know the BOOTLOADER_ADDRESS of your device (<a href="http://hubbard.engr.scu.edu/embedded/avr/bootloader/index.html" target="_blank">learn</a> <a href="http://blog.schicks.net/wp-content/uploads/2009/09/bootloader_faq.pdf" target="_blank">more</a> about bootloader). Basically your datasheet will tell you the Start Bootloader section (look for Boot Size Configuration) in word address. You need to multiply it by 2 (the toolchain works on BYTE ADDRESS). For example, the atmega164p for 1024 words, the address is: 1C00 * 2 = 3800.</p>
<p>I am using a 20mhz clock, V-USB can be clocked with 12 Mhz, 15 MHz, 16 MHz or 20 MHz crystal or from a 12.8 MHz or 16.5 MHz internal RC oscillator.</p>
<p>Finally, you need to set the <a href="http://www.engbedded.com/fusecalc/" target="_blank">fuse correctly</a>:</p>
<ul>
<li>Boot Flash section size = <strong>1024 words</strong></li>
<li><strong>Uncheck </strong>Divide clock by 8 internally</li>
</ul>
<pre class="brush:bash">DEVICE = atmega164p
BOOTLOADER_ADDRESS = 3800
F_CPU = 20000000
FUSEH = 0xd8
FUSEL = 0xff
PROGRAMMER = avrispmkII
PORT = usb
...

make fuse
make flash</pre>
<p>Now that you have the bootloaderhid, let&#8217;s write a simple firmware to test it.</p>
<p>test.c</p>
<pre class="brush:c">#define F_CPU 20000000

#include &lt;avr/io.h&gt;
#include &lt;util/delay.h&gt;

int main(void) {

	// Set Port B pins as all outputs
	DDRB = 0xff;

  while(1) {

    PORTB = 0xFF;
    _delay_ms(100);

    PORTB = 0x00;
    _delay_ms(200);

  }

  return 1;
}</pre>
<p>then:<br />
avr-gcc -mmcu=atmega164p -Os test.c<br />
avr-objcopy -j .text -j .data -O ihex a.out a.hex</p>
<p>cd bootloader/commandline<br />
edit main.c if you changed the VENDOR and PRODUCT string<br />
make</p>
<p>You need to connect the usb cable <strong>while holding</strong> the reset button. 2 LEDs should light up and you should see in dmesg something like:</p>
<p>[ 1727.956432] usb 3-2: new low speed USB device using uhci_hcd<br />
[ 1728.119279] usb 3-2: configuration #1 chosen from 1 choice<br />
[ 1728.142142] generic-usb 0003:16C0:05DF.000A: hiddev97,hidraw4: USB HID v1.01 Device [YOURVENDOR YOURPRODUCT] on usb-0000:00:1a.0-2/input0</p>
<p>Do:<br />
./bootloadHID -r a.hex</p>
<p><strong>FIRMWARE</strong></p>
<p>Now what you want in your custom firmware is a way to tell your device to go in the bootloader (so you don&#8217;t have to hold the reset button anymore). With this method in place, adding the reset button is optional, but recommanded (in case you break something in the firmware, you need a way to go back in the bootloader).</p>
<p>Remember, in the bootloader we are reading the EEPROM to see if we need to stay in the bootloader section, if not we load the firmware. So in the firmware we will write the EEPROM if we want to go in the bootloader.<br />
<a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1870813795'), this, 'show code &#9660;', 'hide code &#9650;');">show code &#9660;</a></p>
<div id='SID1870813795' style='display:none;'>
<pre class="brush:c">// - Write to EEPROM
void eepromWrite(unsigned int uiAddress, unsigned char ucData) {
  while(EECR &amp; (1&lt;&lt;EEPE));
  EEAR = uiAddress;
  EEDR = ucData;
  cli();
  EECR |= (1&lt;&lt;EEMPE);
  EECR |= (1&lt;&lt;EEPE);
  sei();
}

/* BOOTLOADER  */
void (*jump_to_bootloader)(void) = 0x1C00; __attribute__ ((unused))

void startBootloader(void) {

		eepromWrite(0 , 1);				// stay in bootloader

		TIMSK0 &amp;= ~(1&lt;&lt;TOIE0);			// disable timer overflow

		cli();							// turn off interrupts
		wdt_disable();					// disable watchdog timer
		usbDeviceDisconnect(); 			// disconnect from USB bus

		cbi(ADCSRA, ADIE);				// disable ADC interrupts
		cbi(ADCSRA, ADEN);				// disable ADC (turn off ADC power)

		PORTA = 0;						// pull all pins low
		PORTB = 0;
		PORTC = 0;						

		jump_to_bootloader();
}

// - main
int main(void)
{

	while(1) {

		//jump to bootloader if jumper is HIGH
		if(bit_is_clear(PIND, 5)) {
			startBootloader();
		}
	}
	return 0;
}</pre>
</div>
<p>You are ready to write the firmware for your application. Since you are using V-USB not only it let you upgrade your firmware very easily, but you can of course send and receive message between your computer and the device. Here&#8217;s an example of sending the value of a potentiometer to your computer and telling your device to blink a led at a certain speed. This example is for my device, Atmega164p.</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/vusbtut.tar.gz"><strong>vusbtut.tar.gz</strong></a></p>
<p><strong>WINDOWS</strong><br />
You can trick Windows so it doesn&#8217;t popup the driver installation when you plug your device. Your need to use a HID descriptor (Vendor type requests sent to custom HID class device).</p>
<p>hiddescriptor.h<br />
<a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID965343062'), this, 'show code &#9660;', 'hide code &#9650;');">show code &#9660;</a></p>
<div id='SID965343062' style='display:none;'>
<pre class="brush:c">// This HidReportDescriptor is not used, it's only here for avoiding a driver popup install on Windows
// See: Vendor type requests sent to custom HID class device
// http://vusb.wikidot.com/usb-device-classes

PROGMEM char usbHidReportDescriptor[33] = {
0x06, 0x00, 0xff,              // USAGE_PAGE (Generic Desktop)
0x09, 0x01,                    // USAGE (Vendor Usage 1)
0xa1, 0x01,                    // COLLECTION (Application)
0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
0x75, 0x08,                    //   REPORT_SIZE (8)

0x85, 0x01,                    //   REPORT_ID (1)
0x95, 0x06,                    //   REPORT_COUNT (6)
0x09, 0x00,                    //   USAGE (Undefined)
0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)

0x85, 0x02,                    //   REPORT_ID (2)
0x95, 0x83,                    //   REPORT_COUNT (131)
0x09, 0x00,                    //   USAGE (Undefined)
0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)
0xc0                           // END_COLLECTION
};</pre>
</div>
<p>usbconfig.h<br />
<a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID583228670'), this, 'show code &#9660;', 'hide code &#9650;');">show code &#9660;</a></p>
<div id='SID583228670' style='display:none;'>
<pre class="brush:c">#define USB_CFG_DEVICE_CLASS        0    /* set to 0 if deferred to interface */
#define USB_CFG_DEVICE_SUBCLASS     0
/* See USB specification if you want to conform to an existing device class.
* Class 0xff is "vendor specific".
*/
#define USB_CFG_INTERFACE_CLASS     0x03   /* define class here if not at device level */
#define USB_CFG_INTERFACE_SUBCLASS  0
#define USB_CFG_INTERFACE_PROTOCOL  0
/* See USB specification if you want to conform to an existing device class or
* protocol. The following classes must be set at interface level:
* HID class is 3, no subclass and protocol required (but may be useful!)
* CDC class is 2, use subclass 2 and protocol 1 for ACM
*/
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH    33</pre>
<p>main.c</p>
<pre class="brush:c">#include &lt;avr/io.h&gt;
#include &lt;avr/interrupt.h&gt;
#include &lt;avr/pgmspace.h&gt;
#include &lt;avr/wdt.h&gt;
#include "usbdrv.h"
#include "hiddescriptor.h"</pre>
</div>
<p>Here&#8217;s an example for installing the software &amp; driver:<br />
<a href="http://www.workinprogress.ca/wp-content/uploads/edubeat.zip"><strong>edubeat.zip</strong></a></p>
<p><strong>HOST SOFTWARE<br />
</strong></p>
<p>Here&#8217;s the most basic host software written in python.<br />
<a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID124346941'), this, 'show code &#9660;', 'hide code &#9650;');">show code &#9660;</a></p>
<div id='SID124346941' style='display:none;'>
<pre class="brush:python">
import usb

def findDevice(vendor_id):
	buses = usb.busses()
	for bus in buses :
		for device in bus.devices :
			print 'idVendor: %x' % device.idVendor
			if device.idVendor == vendor_id:
				print 'Found'
				return device
	return None

class VUSB:
	USB_VENDOR_ID = 0x16C0
	REQUEST_TYPE = usb.TYPE_VENDOR | usb.RECIP_DEVICE | usb.ENDPOINT_IN

	USB_BUFFER_SIZE = 2
	CMD_ZERO = 0

	def __init__(self):
		device = findDevice(self.USB_VENDOR_ID)
		if not device:
			raise Exception('Device not available')
		self.handle = device.open()

	def getBufferSize(self):
		return self.send_cmd(self.CMD_ZERO)

	def send_cmd(self, cmd, param=0):
		val = self.handle.controlMsg(requestType = self.REQUEST_TYPE, request = cmd, value = param, buffer = self.USB_BUFFER_SIZE)
		return val

def main():
	client = VUSB()
	print client.getBufferSize()

if __name__ == '__main__':
	main()
</pre>
</div>
<p><strong>HARDWARE</strong></p>
<p>V-USB runs on any AVR microcontroller with at least 2 kB of Flash memory, 128 bytes RAM and a clock rate of at least 12 MHz. For example the ATTINY25 can do the job. The price of this chip is 1.66 USD!</p>
<p><strong>TEMPLATE</strong></p>
<p>Here&#8217;s my template for the Atmega164p. This firmware is ready for ADC free-running mode, SPI master (you need to +5V PB4), external interrupts (PORTC), EEPROM read / write, jump to bootloader.<br />
<a href="javascript:void(null);" onclick="s_toggleDisplay(document.getElementById('SID1842023317'), this, 'show code &#9660;', 'hide code &#9650;');">show code &#9660;</a></p>
<div id='SID1842023317' style='display:none;'>
<pre class="brush:c">#include &lt;avr/io.h&gt;
#include &lt;avr/interrupt.h&gt;
#include &lt;avr/pgmspace.h&gt;
#include &lt;avr/wdt.h&gt;
#include &lt;util/delay.h&gt;

#include "usbdrv.h"
#include "hiddescriptor.h"
#include "utils.h"

// - Define
#define DD_MOSI     PINB5
#define DD_SCK      PINB7
#define ADC_PINS 8

// - Global
static uint8_t usb_reply[10];

// - Write to EEPROM
void eepromWrite(unsigned int uiAddress, unsigned char ucData) {
while(EECR &amp; (1&lt;&lt;EEPE));
EEAR = uiAddress;
EEDR = ucData;
cli();
EECR |= (1&lt;&lt;EEMPE);
EECR |= (1&lt;&lt;EEPE);
sei();
}

// - Read EEPROM
unsigned char eepromRead(unsigned int uiAddress) {
while(EECR &amp; (1&lt;&lt;EEPE));
EEAR = uiAddress;
EECR |= (1&lt;&lt;EERE);
return EEDR;
}

// - Bootloader
void (*jump_to_bootloader)(void) = 0x1C00; __attribute__ ((unused))

void startBootloader(void) {
eepromWrite(0 , 1);                // stay in bootloader
TIMSK0 &amp;= ~(1&lt;&lt;TOIE0);            // disable timer overflow
cli();                            // turn off interrupts
wdt_disable();                    // disable watchdog timer
usbDeviceDisconnect();             // disconnect from USB bus
cbi(ADCSRA, ADIE);                // disable ADC interrupts
cbi(ADCSRA, ADEN);                // disable ADC (turn off ADC power)
jump_to_bootloader();
}

// - usbFunctionSetup
USB_PUBLIC uchar usbFunctionSetup(uchar data[8])
{
usbRequest_t    *rq = (void *)data;
static uchar    replyBuf[10];

usbMsgPtr = replyBuf;
if(rq-&gt;bRequest == 0) { //POST

replyBuf[0] = usb_reply[0];
replyBuf[1] = usb_reply[1];
replyBuf[2] = usb_reply[2];
replyBuf[3] = usb_reply[3];
replyBuf[4] = usb_reply[4];
replyBuf[5] = usb_reply[5];
replyBuf[6] = usb_reply[6];
replyBuf[7] = usb_reply[7];
replyBuf[8] = usb_reply[8];
replyBuf[9] = usb_reply[9];
return 10;

} else if(rq-&gt;bRequest == 1) { //GET
//rq-&gt;wIndex.bytes[0];
//rq-&gt;wValue.bytes[0];
}
return 0;
}

// - InterruptInit
void InterruptInit() {
PCICR |= (1 &lt;&lt; PCIE2);
PCMSK2 |= (1 &lt;&lt; PCINT23) | (1 &lt;&lt; PCINT22) | (1 &lt;&lt; PCINT21) | (1 &lt;&lt; PCINT20) | (1 &lt;&lt; PCINT19) | (1 &lt;&lt; PCINT18) | (1 &lt;&lt; PCINT17) | (1 &lt;&lt; PCINT16);
}

// - InterruptTrigged
SIGNAL (SIG_PIN_CHANGE2)
{
//CODE
}

// - SPI_MasterInit
void SPI_MasterInit(void)
{
/* Set MOSI and SCK output, all others input */
DDRB = (1&lt;&lt;DD_MOSI)|(1&lt;&lt;DD_SCK);

/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1&lt;&lt;SPE)|(1&lt;&lt;MSTR);
SPSR = (1&lt;&lt;SPI2X);
}

// - SPI_MasterTransmit
void SPI_MasterTransmit(char cData)
{
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR &amp; (1&lt;&lt;SPIF)))
;
}

// - ADC_setPint
void ADC_setPin (int8_t pin) {
pin %= ADC_PINS;
pin   |= ADMUX &amp; -8;
ADMUX  = pin;
}

// - hardwareInit
static void hardwareInit(void)
{
//USB

uchar i, j;

/* activate pull-ups except on USB lines */
USB_CFG_IOPORT = (uchar) ~ ((1 &lt;&lt; USB_CFG_DMINUS_BIT) | (1 &lt;&lt; USB_CFG_DPLUS_BIT));

/* all pins input except USB (-&gt; USB reset) */
#ifdef USB_CFG_PULLUP_IOPORT    /* use usbDeviceConnect()/usbDeviceDisconnect() if available */
USBDDR = 0;        /* we do RESET by deactivating pullup */
usbDeviceDisconnect();
#else
USBDDR = (1 &lt;&lt; USB_CFG_DMINUS_BIT) | (1 &lt;&lt; USB_CFG_DPLUS_BIT);
#endif

j = 0;
while (--j) {        /* USB Reset by device only required on Watchdog Reset */
i = 0;
while (--i);    /* delay &gt;10ms for USB reset */
}

#ifdef USB_CFG_PULLUP_IOPORT
usbDeviceConnect();
#else
USBDDR = 0;        /*  remove USB reset condition */
#endif

// ADC SETUP :: FREE RUNNING MODE

// PRESCALER 64
ADCSRA |= (1 &lt;&lt; ADPS2) | (1 &lt;&lt; ADPS1) | (0 &lt;&lt; ADPS0);
// AUTO TRIGGER ENABLE
ADCSRA |= (1 &lt;&lt; ADATE);
// AVCC with external capacitor at AREF pin
ADMUX |= (0 &lt;&lt; REFS1) | (1 &lt;&lt; REFS0);
// RIGHT ADJUST
ADMUX |= (0 &lt;&lt; ADLAR);
// CHANNEL 0
ADMUX |= (0 &lt;&lt; MUX4) | (0 &lt;&lt; MUX3) | (0 &lt;&lt; MUX2) | (0 &lt;&lt; MUX1) | (0 &lt;&lt; MUX0);
// FREE RUNNING MODE
ADCSRB |= (0 &lt;&lt; ADTS2) | (0 &lt;&lt; ADTS1) | (0 &lt;&lt; ADTS0);
// ENABLE ADC
ADCSRA |= (1 &lt;&lt; ADEN);

// PORT A: INPUT
DDRA = 0x00;
PORTA = 0x00;

// PORT B: OUTPUT
DDRB = 0xFF;

// PORT C: INPUT
DDRC = 0x00;

//POWER LED
DDRD |= (1 &lt;&lt; 6);
PORTD &amp;= ~(1 &lt;&lt; 6);

//SPI init
SPI_MasterInit();

//Interrupt init
InterruptInit();
}

// - Main
int main(void)
{
wdt_enable(WDTO_1S);
hardwareInit();
usbInit();
sei();

ADCSRA |= (1 &lt;&lt; ADSC); //Start Free Running Mode

while(1) {
wdt_reset();
usbPoll();

//BOOTLOADER
if(bit_is_clear(PIND, 5)) {
startBootloader();
}

//SPI CODE
SPI_MasterTransmit('A');

//YOUR CODE

//USB TEST
usb_reply[0] = 1;
usb_reply[1] = 2;
usb_reply[2] = 3;
usb_reply[3] = 4;
usb_reply[4] = 5;
usb_reply[5] = 6;
usb_reply[6] = 7;
usb_reply[7] = 8;
usb_reply[8] = 0;
usb_reply[9] = 0;

}
return 0;
}</pre>
</div>
<p><strong>MORE INFORMATION</strong></p>
<p>You can find more information about the API / USB Device Class / Host Software on the <a href="http://vusb.wikidot.com/" target="_blank">wiki of V-USB</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/v-usb-tutorial-software-only-usb-for-mega-tiny/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>speech recognition &amp; arduino</title>
		<link>http://www.workinprogress.ca/speech-recognition-arduino/</link>
		<comments>http://www.workinprogress.ca/speech-recognition-arduino/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 22:36:28 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=428</guid>
		<description><![CDATA[Speech recognition done with Simon]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=6276108&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="300" src="http://vimeo.com/moogaloop.swf?clip_id=6276108&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Speech recognition done with Simon</p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/speech-recognition-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>4 bits / 4 channels</title>
		<link>http://www.workinprogress.ca/4-bits-4-channels/</link>
		<comments>http://www.workinprogress.ca/4-bits-4-channels/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 18:50:57 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=415</guid>
		<description><![CDATA[Based on: http://code.google.com/p/4bitsynth/ Atmega48 / pwm: square, triangle, noise. Aphex Twin in 4 bits / 4 channels: http://www.workinprogress.ca/wp-content/uploads/4bitsaphex.mp3]]></description>
			<content:encoded><![CDATA[<p>Based on:<br />
<a href="http://code.google.com/p/4bitsynth/">http://code.google.com/p/4bitsynth/</a></p>
<p>Atmega48 / pwm: square, triangle, noise.</p>
<p><a href="http://www.workinprogress.ca/wp-content/uploads/4bitspcb.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-416" title="4bitspcb" src="http://www.workinprogress.ca/wp-content/uploads/4bitspcb-300x224.jpg" alt="4bitspcb" width="401" height="299" /></a></p>
<p>Aphex Twin in 4 bits / 4 channels:<br />
<!-- Dewplayer Begin--><object type="application/x-shockwave-flash" data="http://www.workinprogress.ca/wp-content/plugins/dewplayer-flash-mp3-player/dewplayer.swf?mp3=http://www.workinprogress.ca/wp-content/uploads/4bitsaphex.mp3&amp;showtime=1&amp;bgcolor=FFFFFF" width="200" height="20"><param name="bgcolor" value="FFFFFF" /><param name="movie" value="http://www.workinprogress.ca/wp-content/plugins/dewplayer-flash-mp3-player/dewplayer.swf?mp3=http://www.workinprogress.ca/wp-content/uploads/4bitsaphex.mp3&amp;showtime=1&amp;bgcolor=FFFFFF" /></object><!-- Dewplayer End--><a href="http://www.workinprogress.ca/wp-content/uploads/4bitsaphex.mp3">http://www.workinprogress.ca/wp-content/uploads/4bitsaphex.mp3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/4-bits-4-channels/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.workinprogress.ca/wp-content/uploads/4bitsaphex.mp3" length="3348688" type="audio/mpeg" />
		</item>
		<item>
		<title>electret microphone amplifier</title>
		<link>http://www.workinprogress.ca/electret-microphone-amplifier/</link>
		<comments>http://www.workinprogress.ca/electret-microphone-amplifier/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 04:09:28 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=246</guid>
		<description><![CDATA[What is the difference between MIC and LINE level? Level refers to the relative strength of the signal and is measured in decibels. LINE level sources are much-amplified signals over MIC (microphone) level signals. Line level is usually between -10 to +4 dbm in strength while MIC levels are normally -60 dbm. Line OUT signal [...]]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://www.workinprogress.ca/wp-content/uploads/P5260103.jpg"><img src="http://www.workinprogress.ca/wp-content/uploads/P5260103-300x224.jpg" alt="" width="300" height="224" /></a><br />
</strong></p>
<p><strong>What is the difference between MIC and LINE level?</strong><br />
Level refers to the relative strength of the signal and is measured in decibels. LINE level sources are much-amplified signals over MIC (microphone) level signals. Line level is usually between -10 to +4 dbm in strength while MIC levels are normally -60 dbm.</p>
<p><strong>Line OUT signal voltage and impedance levels?</strong><br />
The line output &#8220;standard&#8221; designed to drive a load of 600 ohms or greater, at a mean signal level of 0.775V RMS. An exception exists in respect of compact disc players, where the output level is most commonly 2V RMS.</p>
<p><strong>Preamplifier schematic</strong><br />
<em>Thanks to Andy Collinson for sharing his circuit design.</em></p>
<p style="text-align: center;"><a href="http://www.workinprogress.ca/wp-content/uploads/bc549_schematic.jpg"><img class="aligncenter size-full wp-image-181" title="bc549_schematic" src="http://www.workinprogress.ca/wp-content/uploads/bc549_schematic.jpg" alt="bc549_schematic" width="490" height="309" /></a></p>
<p><strong>How does it sound?</strong><br />
Electret microphone<br />
Sensitivity: -35 to +4dB<br />
Signal to noise ratio: 62dB<br />
Recorded at 96000 hertz @ 24 bits</p>
<p><a href="../wp-content/uploads/emc_kalimba.wav" target="_blank">emc_kalimba.wav</a> (right click and save)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/electret-microphone-amplifier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>theremin 2 pure data</title>
		<link>http://www.workinprogress.ca/theremin-2-pure-data/</link>
		<comments>http://www.workinprogress.ca/theremin-2-pure-data/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 17:38:47 +0000</pubDate>
		<dc:creator>psc</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Pure Data]]></category>

		<guid isPermaLink="false">http://www.workinprogress.ca/?p=235</guid>
		<description><![CDATA[My first electronic project (2005):]]></description>
			<content:encoded><![CDATA[<p>My first electronic project (2005):</p>
<p><object width="400" height="267"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5426041&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5426041&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="267"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.workinprogress.ca/theremin-2-pure-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
