<?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>MightyOhm &#187; Streaming Radio</title>
	<atom:link href="http://mightyohm.com/blog/tag/streaming-radio/feed/" rel="self" type="application/rss+xml" />
	<link>http://mightyohm.com/blog</link>
	<description>Join the resistance.</description>
	<lastBuildDate>Wed, 16 May 2012 17:02:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Building a Wifi Radio &#8211; Part 8, Adding a Tuning Control</title>
		<link>http://mightyohm.com/blog/2009/02/building-a-wifi-radio-part-8-adding-a-tuning-control/</link>
		<comments>http://mightyohm.com/blog/2009/02/building-a-wifi-radio-part-8-adding-a-tuning-control/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 15:27:46 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[lcd]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[noisebridge]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[Streaming Radio]]></category>
		<category><![CDATA[wifiradio]]></category>

		<guid isPermaLink="false">http://mightyohm.com/blog/?p=1148</guid>
		<description><![CDATA[This is the eighth part of an ongoing series about building a low cost, open source streaming internet radio based on the ASUS WL-520gU Wireless Router.  If you haven’t already, check out the previous parts (see the links at the end of this article) for some background about the project. In part seven, we added [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the eighth part of an ongoing series about building a low cost, open source streaming internet radio based on the <a href="http://www.dpbolvw.net/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16833320023%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Network%2B-%2BWireless%2BRouters-_-ASUS-_-33320023&amp;cjsku=N82E16833320023" target="_top">ASUS WL-520gU Wireless Router</a><img src="http://www.ftjcfx.com/image-3238164-10440897" border="0" alt="" width="1" height="1" />.  If you haven’t already, check out the previous parts (see the links at the end of this article) for some background about the project.</em></p>
<p>In <a href="http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-7-building-an-lcd-display/">part seven</a>, we added an LCD status display for the radio that shows the stream name as well as the artist and title of the current track.  In this part, we&#8217;ll add a tuning knob that lets us change stations without using a computer.</p>
<p>It turns out that this is mostly a software exercise, made simple by taking advantage of the analog to digital converter function of the Atmel ATmega168 AVR that is controlling the LCD display.  The addition of the tuner control turns the display circuit into a very simple user interface.  Turn the knob and the station changes.  The position of the knob determines what station the radio is &#8220;tuned&#8221; to, and when combined with a calibrated scale it will make it easy to change to any one of the several streaming radio stations stored as presets (favorites?) in the router.</p>
<p>To give you an idea of how this works, here is a demo of the tuner control changing between ten preset stations I have set on the router.  The tuner control is in the upper right hand corner of the breadboard.  As I adjust the control, the music changes and LCD display updates to show the name of each new station.</p>
<p><object width="500" height="375" data="http://www.flickr.com/apps/video/stewart.swf?v=67090" type="application/x-shockwave-flash"><param name="flashvars" value="intl_lang=en-us&amp;photo_secret=4181c97c88&amp;photo_id=3238566442" /><param name="bgcolor" value="#000000" /><param name="allowFullScreen" value="true" /><param name="src" value="http://www.flickr.com/apps/video/stewart.swf?v=67090" /><param name="allowfullscreen" value="true" /></object></p>
<p>Is that cool or what?</p>
<p>If you are interested in adding this functionality to the radio, keep reading and I&#8217;ll show you how.</p>
<h3>Changes to the hardware:</h3>
<h4>You will need:</h4>
<ul>
<li>The completed AVR-based LCD display from part seven</li>
<li>A 1k-10k trimmer or potentiometer, linear taper</li>
<li>Some hookup wire</li>
</ul>
<h4>Schematic:</h4>
<p>Here is an updated schematic of the AVR circuit showing the potentiometer connected to ADC4 (pin 27).</p>
<div id="attachment_1154" class="wp-caption alignnone" style="width: 509px"><a href="http://mightyohm.com/blog/wp-content/uploads/2009/02/interface.png"><img class="size-medium wp-image-1154" title="Wifi Radio User Interface Schematic" src="http://mightyohm.com/blog/wp-content/uploads/2009/02/interface-499x314.png" alt="Wifi Radio User Interface Schematic" width="499" height="314" /></a><p class="wp-caption-text">click to enlarge</p></div>
<h4>Firmware:</h4>
<p>The AVR firmware has been significantly expanded, slightly reworked and cleaned up in some areas.</p>
<p>The most important changes are:</p>
<ul>
<li>The addition of a serial transmit function so the AVR can talk to the router (based on the uart_putchar function)</li>
<li>New code supporting the analog to digital converter (ADC) which reads the value of a potentiometer connected to ADC4.</li>
<li>A new Timer1 overflow interrupt has been added, which occurs roughly every 0.5 seconds.  The interrupt service routine (ISR) checks the position of the tuner control, and if it has changed, sends the value to the router.  The ISR is towards the top of the file, see the SIGNAL (TIMER1_OVF_vect) section.</li>
</ul>
<p>The ADC range of the ATmega is 0 &#8211; 1024 for an input voltage from 0 to 5V.  The AVR sends serial data in the format &#8220;Tuner: Value&#8221; back to the router when the tuner position changes by more than ADC_SENS counts (default is 5).  The AVR waits for an &#8220;AVR Start!&#8221; command from the router before sending any data, this avoids filling up the serial receive buffer on the router before it&#8217;s ready to start processing data.  An important consequence of this is that the AVR must be reset before running the control script on the router.</p>
<p>You can download the source code and compiled .hex file <a href="http://mightyohm.com/files/wifiradio/AVR_wifiradio_interface.zip">here</a>.  Flash it to the AVR using any compatible ISP programmer and you should be good to go.  The source is commented fairly well so if you&#8217;re interested in learning how the interface works, take a look.  You will need a copy of the <a href="http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf">ATmega168 datasheet</a> to understand the register names and other architecture-specific parts of the code.  Feel free to post in the comments with any questions.</p>
<h4>Modifying the circuit:</h4>
<p>This part is pretty simple &#8211; just wire the potentiometer as shown in the schematic.  Most potentiometers have three terminals.  The left terminal goes to ground, the right one to +5V, and the middle terminal to ADC4 on the AVR (pin 27).</p>
<p><a class="tt-flickr tt-flickr-Medium" title="Tuner control on breadboard" href="http://www.flickr.com/photos/mightyohm/3238589400/"><img class="alignnone" src="http://farm4.static.flickr.com/3108/3238589400_3134e598cc.jpg" alt="Tuner control on breadboard" width="500" height="375" /></a></p>
<h3>Tweaks to the OpenWrt configuration:</h3>
<p>To make bidirectional communication with the AVR work, we have to change a couple config files on the router and disable some services that would otherwise get in the way.</p>
<h4>/etc/config/network</h4>
<p>The first change is to modify the /etc/config/network file so that we can always telnet or ssh into the router on a LAN port using the IP 192.168.1.1.  The ability to access the router via ethernet is helpful in case we screw something up and lose the wireless connection or the router loses it&#8217;s IP address, etc.</p>
<p>Modify the LAN section of /etc/config/network to look like this (changes in bold):</p>
<blockquote>
<pre>#### LAN configuration
config interface lan
<strong>#option type     bridge</strong>
option ifname    "eth0.0"
option proto    static
<strong>option ipaddr    192.168.1.1
option netmask    255.255.255.0</strong></pre>
</blockquote>
<p>Save changes, restart the router, and connect an ethernet <a href="http://en.wikipedia.org/wiki/Ethernet_crossover_cable">crossover cable</a> (straight cable might work on some computers) to the router.  Configure your desktop/laptop computer with a static IP, like 192.168.1.185.  Try to open a telnet connection (or ssh if you have set a password on the router) and see if you can log in.  If not, don&#8217;t continue with the next steps until you can get this working.</p>
<h4>/etc/inittab</h4>
<p>We previously used the router&#8217;s serial port to get a login shell.  Now that we&#8217;re trying to receive data from the AVR on the same serial port, we need to disable the login shell or it will capture the data before we can get to it.</p>
<p>Edit /etc/inittab to look like this (changes in bold):</p>
<blockquote>
<pre>::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K stop
<strong>#tts/0::askfirst:/bin/ash --login
#ttyS0::askfirst:/bin/ash --login</strong>
tty1::askfirst:/bin/ash --login</pre>
</blockquote>
<h4>/etc/sysctl.conf</h4>
<p><a href="http://en.wikipedia.org/wiki/System_request">Sysrq</a> is a fascinating and very low level debugging feature of the Linux kernel.  It can be used to perform troubleshooting operations and reboot the system.  Usually it is invoked with a <a href="http://en.wikipedia.org/wiki/Magic_SysRq_key">magic key combination</a> on a desktop computer, but in this case I found that it is easy to accidentally trip over the serial port when using an AVR.  (The &#8220;break&#8221; RS-232 code triggers Sysrq, this probably has something to do with it.)</p>
<p>Fortunately, it&#8217;s easy to disable by editing the /etc/sysctl.conf file and adding these lines:</p>
<blockquote>
<pre><strong># Disables the magic SysRq key
kernel.sysrq = 0</strong></pre>
</blockquote>
<p>Reboot the router to apply the changes.  Now we can get on with the good stuff!</p>
<h3>Shell scripting magic:</h3>
<p>The real action happens on the router, where a shell script waits for input from the router and changes the station accordingly.</p>
<p>This script is called <a href="http://mightyohm.com/files/wifiradio/interface.sh">interface.sh</a> and can be downloaded to the router using wget as shown:</p>
<blockquote>
<pre>root@OpenWrt:~# <strong>cd ~</strong>
root@OpenWrt:~# <strong>wget http://mightyohm.com/files/wifiradio/interface.sh</strong>
...
root@OpenWrt:~# <strong>chmod ugo+x interface.sh</strong></pre>
</blockquote>
<p>The interface script calls an updated version of the display script from part 7, called <a href="http://mightyohm.com/files/wifiradio/display2.sh">display2.sh</a>:</p>
<blockquote>
<pre>root@OpenWrt:~# <strong>wget http://mightyohm.com/files/wifiradio/display2.sh</strong>
...
root@OpenWrt:~# <strong>chmod ugo+x display2.sh</strong></pre>
</blockquote>
<p>Once both scripts are downloaded, executable and located in /root you can launch interface.sh as follows:</p>
<blockquote>
<pre>root@OpenWrt:~# <strong>./interface.sh</strong>
volume: 60%   repeat: on    random: off
volume: 60%   repeat: on    random: off
adding: http://relay3.slayradio.org:8000/
adding: http://scfire-dtc-aa01.stream.aol.com:80/stream/1046
adding: http://208.101.28.234:8004</pre>
<p>&#8230; more stations here &#8230;</p>
<pre>Tuner Position:  0
New station...

http://relay3.slayradio.org:8000/

[playing] #1/10   0:00/0:00 (100%)
volume: 60%   repeat: on    random: off</pre>
</blockquote>
<p>The interface script adds ten presets to the router, shows the playlist, and then waits for valid tuner data from the AVR.  Once it receives a &#8220;Tuner: value&#8221; line (which should occur shortly after the AVR receives a go signal from the script), the script prints the received tuner positon and changes to the requested station.  It will then wait for new tuner data from the AVR and change the station when necessary.</p>
<p>As you can see in the video, this works very well.  Over a fast Wi-Fi connection, the time to change stations is almost instantaneous &#8211; very satisfying!</p>
<p>That&#8217;s it for part eight.  In part nine, I&#8217;ll add some finishing touches to the router configuration and start talking about enclosures.  Stay tuned!</p>
<p><strong>Update:</strong> There is a new <a href="http://mightyohm.com/forum/viewforum.php?f=2">Wifi Radio Discussion Forum</a>, hop over there to ask questions about the project or see what other people are working on!  (<em>4/12/09)</em></p>
<p><strong>Update 2: </strong><a href="http://mightyohm.com/blog/2009/05/building-a-wifi-radio-part-9-a-few-odds-and-ends/">Part nine is now available.</a><em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mightyohm.com/blog/2009/02/building-a-wifi-radio-part-8-adding-a-tuning-control/feed/</wfw:commentRss>
		<slash:comments>68</slash:comments>
		</item>
		<item>
		<title>Building a Wifi Radio &#8211; Part 7, Building an LCD Display</title>
		<link>http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-7-building-an-lcd-display/</link>
		<comments>http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-7-building-an-lcd-display/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 23:20:42 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[avr-gcc]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[lcd]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[Streaming Radio]]></category>
		<category><![CDATA[wifiradio]]></category>

		<guid isPermaLink="false">http://mightyohm.com/blog/?p=822</guid>
		<description><![CDATA[This is the seventh part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven’t already, check out the previous parts (see the links at the end of this article) for some background about the project. In part six, we used OpenWrt&#8217;s UNIX-style shell commands to interface with [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the seventh part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven’t already, check out the previous parts (see the links at the end of this article) for some background about the project.</em></p>
<p>In <a href="http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-6-a-conversation-with-mpd/">part six</a>, we used <a href="http://www.busybox.net/downloads/BusyBox.html">OpenWrt&#8217;s UNIX-style shell commands</a> to interface with mpd, the music player daemon, and redirect song and stream information to our <a href="http://www.anrdoezrs.net/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16833320023%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Network%2B-%2BWireless%2BRouters-_-ASUS-_-33320023&amp;cjsku=N82E16833320023" target="_top">ASUS WL-520gU</a><img src="http://www.lduhtrp.net/image-3238164-10440897" border="0" alt="" width="1" height="1" /> wireless router&#8217;s serial port.  In this part, we&#8217;ll use a Sparkfun 16&#215;2 LCD display and a handful of other components to build an LCD status display for the radio.</p>
<h3>The Atmel AVR Microcontroller:</h3>
<p>After much thought, I decided to use an <a href="http://www.atmel.com/dyn/products/Product_card.asp?part_id=3303">Atmel ATmega168 AVR microcontroller</a> to drive the display.  I realize that this raises the technical level of this project significantly, but I have been wanting to feature an <a href="http://en.wikipedia.org/wiki/Atmel_AVR">AVR</a> project on the site and this is a great opportunity.  The truth is that an <a href="http://www.arduino.cc">Arduino</a> would work just as well and it shouldn&#8217;t be too difficult to port this program to an <a href="http://www.arduino.cc/en/Tutorial/Sketch">Arduino sketch</a>.  (The Arduino is built with the same ATmega168 microcontroller, after all.)  If anyone does this, let me know and I&#8217;ll post a link to your version of the display.</p>
<p>If you&#8217;re an AVR veteran, you can skip over this part and straight to the bill of materials below.</p>
<p>If you are new to the AVR, don&#8217;t be intimidated.  There are a number of tutorials online to help you learn how to use this inexpensive and powerful microcontroller.  I recommend starting with <a href="http://www.ladyada.net/learn/avr/">this one</a> or maybe <a href="http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=93">this one</a>, but see my note about AVR MacPack below if you&#8217;re using a Mac.  If you&#8217;ve never programmed in C before, you&#8217;ll have an additional hurdle to get over, although for this project you won&#8217;t need any actual knowledge of programming or C to burn the code to the AVR and get things working.</p>
<p>You will need to install some software to work with the AVR, I recommend:</p>
<ul>
<li><a href="http://www.obdev.at/products/avrmacpack/index.html">AVR MacPack</a> for OS X (the Adafruit tutorial recommends OSX-AVR, use this instead)</li>
<li><a href="http://winavr.sourceforge.net/">WinAVR</a> for Windows</li>
</ul>
<p>I recommend following a tutorial or two and getting a simple blinking LED example working on your AVR before building the LCD display.  That way you can be sure your programmer, development environment, breadboard, etc are working first.</p>
<h3>Building the display:</h3>
<h4>Bill of Materials:</h4>
<p>You will need:</p>
<ul>
<li>one A-B USB cable (the kind with one flat and one square end)</li>
<li>an AVR programmer, such as the <a href="http://www.adafruit.com/index.php?main_page=product_info&amp;products_id=46&amp;sessid=5f4b1ada86e5cbba0de9c9fb6cf45f10">Adafruit USBTinyISP</a></li>
<li>an <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=7957">Atmel ATmega168 AVR microcontroller</a></li>
<li>a working AVR development suite or at least a way to get a .hex file onto an AVR (see above)</li>
<li>an LCD display like this fancy LED backlit <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=255">Sparkfun 16&#215;2 Character STN</a></li>
<li>a <a href="http://en.wikipedia.org/wiki/Solderless_breadboard">solderless breadboard</a>, like <a href="http://www.amazon.com/gp/product/B0002H4W1E?ie=UTF8&amp;tag=mightyohm-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B0002H4W1E">this one</a> (comes with precut wires!)<img style="border: none !important; margin: 0px !important;" src="http://www.assoc-amazon.com/e/ir?t=mightyohm-20&amp;l=as2&amp;o=1&amp;a=B0002H4W1E" border="0" alt="" width="1" height="1" /> or <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=112">this one</a>.</li>
<li>a 4-pin female 0.1&#8243; header, this <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=115">breakaway header</a> is handy.</li>
<li>two 22pF ceramic capacitors, rated &gt;6V (mine are 25V)</li>
<li>a 0.1uF capacitor, rated &gt;6V</li>
<li>a 10 Ohm resistor</li>
<li>for contrast adjustment, a small 1k or 10k potentiometer</li>
<li>a few feet of 20 to 24 gauge solid hookup wire</li>
</ul>
<p>also nice, but not required:</p>
<ul>
<li>a <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8508">Sparkfun ISP breakout board</a> to simplify connecting the programmer to the breadboard<a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8508"><br />
</a></li>
<li>a normally-open pushbutton switch to reset the circuit</li>
</ul>
<h4>Schematic:</h4>
<p>Here is the schematic of the LCD display (click to enlarge):</p>
<p><a href="http://mightyohm.com/blog/wp-content/uploads/2008/12/avr_wifiradio_display.png"><img class="alignnone size-full wp-image-879" title="Wifi Radio LCD Display Schematic" src="http://mightyohm.com/blog/wp-content/uploads/2008/12/avr_wifiradio_display.png" alt="Wifi Radio LCD Display Schematic" width="500" height="315" /></a></p>
<h4>Firmware:</h4>
<p>You can download the source code and compiled .hex file <a href="http://mightyohm.com/files/wifiradio/AVR_wifiradio_display.zip">here</a>.</p>
<p>Special thanks to <a href="http://jump.to/fleury">Peter Fleury</a> for his excellent <a href="http://homepage.hispeed.ch/peterfleury/group__pfleury__lcd.html">LCD library</a>, which saved me from reinventing the wheel!  He also has another page about <a href="http://homepage.hispeed.ch/peterfleury/avr-lcd44780.html">interfacing LCD displays to an AVR</a>.</p>
<h3>Assembling the circuit:</h3>
<p>Assembling the circuit on the breadboard is pretty straightforward.  Here&#8217;s a photo showing all components of the setup.  The router is shown above with the serial port wired to the breadboard (the RX line is floating as we&#8217;re not using it yet).  The USB AVR programmer is on the right, where it is also functioning as a 5V power supply for the circuit. Make sure the 2-pin jumper on the USBTinyISP is installed, this enables the +5V supply.  The LCD is shown displaying the current stream name (<a href="http://di.fm">DI.fm</a>).</p>
<p><a class="tt-flickr tt-flickr-Medium" title="Wifi Radio LCD Display" href="http://www.flickr.com/photos/mightyohm/3113532375/"><img class="alignnone" src="http://farm4.static.flickr.com/3201/3113532375_f429580226.jpg" alt="Wifi Radio LCD Display" width="500" height="375" /></a></p>
<p>Here is a closeup of the components installed on the breadboard to show how I did things, feel free to experiment with the placement of components.  As long as you follow the schematic the circuit should still work.</p>
<p><a class="tt-flickr tt-flickr-Medium" title="Wifi Radio LCD Display" href="http://www.flickr.com/photos/mightyohm/3114364124/"><img class="alignnone" src="http://farm4.static.flickr.com/3017/3114364124_d4ab638540.jpg" alt="Wifi Radio LCD Display" width="500" height="375" /></a></p>
<p>Here is a closeup of the serial port connection to the router, including the 4-pin female 0.1&#8243; header.  I soldered wires to the pins of the female header (not the pins on the board).</p>
<p><a class="tt-flickr tt-flickr-Medium" title="Wifi Radio LCD Display" href="http://www.flickr.com/photos/mightyohm/3114364910/"><img class="alignnone" src="http://farm4.static.flickr.com/3037/3114364910_c1e27c1bfa.jpg" alt="Wifi Radio LCD Display" width="500" height="375" /></a></p>
<p>Here is a closeup of the AVR, crystal, and the <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8508">Sparkfun ISP breakout board</a> showing the pinout:</p>
<p><a class="tt-flickr tt-flickr-Medium" title="Wifi Radio LCD Display" href="http://www.flickr.com/photos/mightyohm/3114364680/"><img class="alignnone" src="http://farm4.static.flickr.com/3293/3114364680_972485237a.jpg" alt="Wifi Radio LCD Display" width="500" height="375" /></a></p>
<h3>Flashing the AVR:</h3>
<p>Once the circuit is assembled on the breadboard, we need to flash the AVR microcontroller with the main.hex file included with the firmware above.</p>
<p>If you&#8217;re using AVR MacPack and OS X, this should be easy (since that&#8217;s what I&#8217;m using).  PC guys will need to figure this out for themselves but hopefully the process is similar (please let me know if the Makefile works).</p>
<p>Connect the USBTinyISP to your computer with the USB cable and to the breadboard with the ISP cable.  The green light on the programmer should be on, indicating it is ready, and the backlight of the LCD should be lit, indicating that the breadboard is getting power.</p>
<p>Open a terminal window and create a new directory, I used ~/temp.  Unzip the firmware into a directory somewhere, and execute &#8216;make flash&#8217;, as shown:</p>
<blockquote>
<pre>macbook:temp jkeyzer$ unzip ./AVR_wifiradio_display.zip
Archive:  ./AVR_wifiradio_display.zip
  inflating: lcd.c
  inflating: lcd.h
  inflating: main.c
  inflating: main.hex
  inflating: Makefile
macbook:temp jkeyzer$ make flash
avr-gcc -Wall -Os -DF_CPU=16000000 -mmcu=atmega168  -c main.c -o main.o</pre>
<p>a few warnings later &#8230;</p>
<pre>avr-gcc -Wall -Os -DF_CPU=16000000 -mmcu=atmega168  -c lcd.c -o lcd.o
avr-gcc -Wall -Os -DF_CPU=16000000 -mmcu=atmega168  -o main.elf main.o lcd.o
rm -f main.hex
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
avrdude -c usbtiny -p atmega168 -U flash:w:main.hex:i</pre>
<pre>avrdude: AVR device initialized and ready to accept instructions</pre>
<pre>Reading | ################################################## | 100% 0.01s</pre>
<pre>avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "main.hex"
avrdude: writing flash (1326 bytes):</pre>
<pre>Writing | ################################################## | 100% 3.32s</pre>
<pre>avrdude: 1326 bytes of flash written
avrdude: verifying flash memory against main.hex:
avrdude: load data flash data from input file main.hex:
avrdude: input file main.hex contains 1326 bytes
avrdude: reading on-chip flash data:</pre>
<pre>Reading | ################################################## | 100% 0.68s</pre>
<pre>avrdude: verifying ...
avrdude: 1326 bytes of flash verified</pre>
<pre>avrdude: safemode: Fuses OK</pre>
<pre>avrdude done.  Thank you.</pre>
</blockquote>
<p>If everything went well, the LCD display firmware is now loaded into the ATmega168 and the circuit is ready to go.  If not, double check your connections and take a look at the <a href="http://www.ladyada.net/make/usbtinyisp/help.html">help! page for the USBTinyISP</a>.</p>
<h3>Testing the display:</h3>
<p>Telnet or ssh into the router.  Start mpd and connect to a stream using mpc (we covered this in <a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-5-lets-make-some-noise/">part five</a>).</p>
<p>Once the stream starts playing, execute the display.sh script we created in <a href="http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-6-a-conversation-with-mpd/">part six</a>.  Within a few seconds, if everything is working, you should see the stream name on the display, followed by the artist and name of the current song.  Congratulations!</p>
<p>Here is a video of the LCD display in action, including the horizontal scrolling feature to show information that is too wide to fit within the visible area of the display:<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="500" height="375" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="data" value="http://www.flickr.com/apps/video/stewart.swf?v=63881" /><param name="flashvars" value="intl_lang=en-us&amp;photo_secret=88e8f450f5&amp;photo_id=3113563145" /><param name="bgcolor" value="#000000" /><param name="allowFullScreen" value="true" /><param name="src" value="http://www.flickr.com/apps/video/stewart.swf?v=63881" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="500" height="375" src="http://www.flickr.com/apps/video/stewart.swf?v=63881" allowfullscreen="true" bgcolor="#000000" flashvars="intl_lang=en-us&amp;photo_secret=88e8f450f5&amp;photo_id=3113563145" data="http://www.flickr.com/apps/video/stewart.swf?v=63881"></embed></object></p>
<p>That&#8217;s it for part seven!  In part eight, we&#8217;ll start working on the input side of the user interface.</p>
<p>Like what you&#8217;re seeing?  Have suggestions about what could be improved?  Leave a comment or <a href="http://mightyohm.com/blog/contact/">contact me directly</a>.</p>
<p><strong>Update:</strong> <a href="http://mightyohm.com/blog/2009/02/building-a-wifi-radio-part-8-adding-a-tuning-control/">Part eight</a>, in which I add a tuning control to the radio, is now available.</p>
<p><strong>Update 2:</strong> There is a new <a href="http://mightyohm.com/forum/viewforum.php?f=2">Wifi Radio Discussion Forum</a>, hop over there to ask questions about the project or see what other people are working on!  (<em>4/12/09)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-7-building-an-lcd-display/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Building a Wifi Radio &#8211; Part 6, A Conversation with Mpd</title>
		<link>http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-6-a-conversation-with-mpd/</link>
		<comments>http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-6-a-conversation-with-mpd/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 23:28:15 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[busybox]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mpd]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Streaming Radio]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[wifiradio]]></category>

		<guid isPermaLink="false">http://mightyohm.com/blog/?p=712</guid>
		<description><![CDATA[This is the sixth part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven&#8217;t already, check out the previous parts (see the links at the end of this article) for some background about the project. Let&#8217;s review&#8230; It&#8217;s been a few weeks since I posted part five, [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the sixth part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven&#8217;t already, check out the previous parts (see the links at the end of this article) for some background about the project.</em></p>
<h3>Let&#8217;s review&#8230;</h3>
<p>It&#8217;s been a few weeks since I posted <a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-5-lets-make-some-noise/">part five</a>, so let&#8217;s quickly review where we are with this project:</p>
<p>At this point we have a hacked <a href="http://www.kqzyfj.com/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16833320023%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Network%2B-%2BWireless%2BRouters-_-ASUS-_-33320023&amp;cjsku=N82E16833320023" target="_top">ASUS WL-520gU wireless router</a><img src="http://www.awltovhc.com/image-3238164-10440897" border="0" alt="" width="1" height="1" /> running <a href="http://www.openwrt.org">OpenWrt</a> (Linux).   A <a href="http://www.jdoqocy.com/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16812186035%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Adapters%2Band%2Bgender%2Bchangers-_-Syba-_-12186035&amp;cjsku=N82E16812186035" target="_top">cheap USB-audio adapter</a><img src="http://www.awltovhc.com/image-3238164-10440897" border="0" alt="" width="1" height="1" /> is connected to the router&#8217;s single USB port, and in <a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-4-installing-openwrt/">part four</a> we installed kernel drivers for Linux USB and audio support.  In <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/">part three</a> we added a connection to the router&#8217;s internal serial port via a 4-pin header.  Wireless networking worked pretty much out of the box, and in <a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-5-lets-make-some-noise/">part five</a> we used <em>opkg</em>, OpenWrt&#8217;s package manager, to install <em>mpd</em>, the Linux music player daemon, and <em>mpc</em>, a command-line-based mpd client.</p>
<p>This gives us a compact networked device that can wirelessly connect to streaming radio stations and play 16-bit 44kHz stereo audio on a pair of headphones or amplified external speakers.  Pretty impressive, given that this device started as an inexpensive wireless router!</p>
<h3>What&#8217;s missing?</h3>
<p>Something big is missing from the radio.  The original concept for this radio was that it would be a standalone device.  Shell access is cool, and <a href="http://mpd.wikia.com/wiki/Client:MPoD2">iPhone control</a> is even better, but ideally we&#8217;d like to be able to see what song and station are currently playing as well as change stations without the use of another computer or mobile client.</p>
<p>What we need is a user interface!</p>
<p>Based on our requirements, the user interface needs to do two things:</p>
<ol>
<li>Display information about what&#8217;s playing from mpd</li>
<li>Gather input from the user and tell mpd when to change stations.</li>
</ol>
<p>A volume control will be part of our finished user interface as well, but it will be simple enough to do this in hardware when we put the radio into an enclosure.  In this part, we&#8217;ll start work on the first requirement &#8211; the display.</p>
<p><em>Note: The following steps assume you are accessing the OpenWrt shell through a telnet or ssh connection, not using the FTDI USB-serial cable.  The reasons for this will become obvious later, when we start using the router&#8217;s serial port for other purposes!</em></p>
<p>First of all, how do we get information about what&#8217;s currently playing on our radio?</p>
<h3>Chatting with mpd:</h3>
<p>The command-line program mpc that we installed in part five will return information about the current song if we execute it without any options:</p>
<blockquote>
<pre>root@OpenWrt:~# mpc
SLAY Radio: Jogeir Liljedahl - Terra Cresta
[playing] #1/5  22:36/0:00 (100%)
volume: 60%   repeat: on    random: off</pre>
</blockquote>
<p>Mpc obtains playlist, volume, and settings information by sending queries to the <em>mpd</em> server running on the router.  The mpd site includes an overview of the <a href="http://mpd.wikia.com/wiki/MusicPlayerDaemonProtocolOutline">communications protocol</a> and <a href="http://mpd.wikia.com/wiki/MusicPlayerDaemonCommands">command set</a>.  By default, mpd listens for commands on port 6600.  You can access this port remotely by using one of many client programs, or locally by opening a telnet connection to port 6600 locally (the commands are in bold for clarity):</p>
<blockquote>
<pre>root@OpenWrt:~#<strong> telnet localhost:6600</strong>
OK MPD 0.13.0
<strong>status
</strong>volume: 60
repeat: 1
random: 0
playlist: 14
playlistlength: 5x
fade: 0
state: play
song: 4
songid: 4
time: 2348:0
bitrate: 192
audio: 44100:16:2
OK
<strong>currentsong
</strong>file: http://relay3.slayradio.org:8000/
Name: SLAY Radio
Title: Jogeir Liljedahl - Terra Cresta
Pos: 0
Id: 0
OK</pre>
</blockquote>
<p>The connection will timeout in about a minute if left idle.</p>
<p>As you can see, there is a lot of information available, including some of the same information mpc gave us earlier.  The advantage of directly accessing mpd is that we get the stream name (the Name: line) and the artist/title (the Title: line) broken down separately instead of on one continuous line, with handy labels that will make it easy for us to parse the data later.</p>
<p>We can also access mpd by using the <a href="http://en.wikipedia.org/wiki/Netcat"><em>nc</em></a> command, short for &#8220;network cat&#8221;.  Using nc allows us to easily pipe data from other commands to mpd and examine the results.</p>
<blockquote>
<pre>root@OpenWrt:~# <strong>echo "currentsong" | nc localhost 6600</strong>
file: http://relay3.slayradio.org:8000/
Name: SLAY Radio
Title: Jogeir Liljedahl - Terra Cresta
Pos: 0
Id: 0
OK</pre>
</blockquote>
<p>(As an aside, OpenWrt uses a program called <a href="http://www.busybox.net/">busybox</a> to emulate a UNIX-style shell environment &#8211; several common shell commands are included.  There is considerable documentation <a href="http://www.busybox.net/downloads/BusyBox.html">here</a>, but not all commands listed are actually included in the default OpenWrt busybox installation.)</p>
<p>If we just want the name and title of the current song, we can use the UNIX command <a href="http://en.wikipedia.org/wiki/Grep"><em>grep</em></a> to strip out just those two lines:</p>
<blockquote>
<pre>root@OpenWrt:~#<strong> echo "currentsong" | nc localhost 6600 | grep -e "^Title: " -e "^Name: "
</strong>
Name: SLAY Radio
Title: Jogeir Liljedahl - Terra Cresta</pre>
</blockquote>
<h3>Talking to external devices:</h3>
<p>Now that we have a way to get song information from mpd, we need a way to direct this information to an external display.  The router comes with a handy mechanism for doing this &#8211; the builtin serial port.  Linux makes it easy to direct the output of grep to the router&#8217;s serial port, just add a <a href="http://en.wikipedia.org/wiki/Redirection_(computing)">redirect</a> to /dev/tts/0 at the end of the command (all on one line, wrapped here to fit the page):</p>
<blockquote>
<pre>root@OpenWrt:~#<strong> echo "currentsong" | </strong><strong><strong>nc localhost 6600 | grep -e "^Title: "
-e "^Name: "</strong></strong><strong> &gt; /dev/tts/0</strong>
root@OpenWrt:~#</pre>
</blockquote>
<p>However, it turns out that the serial port&#8217;s default speed of 115200 baud is too fast for some external displays.  If we want to be able to talk to an <a href="http://en.wikipedia.org/wiki/Atmel_AVR">AVR microcontroller</a>, for example, we need to change the speed of the serial port from it&#8217;s default value of 115200 to 9600 baud.  This can be done easily with the <a href="http://www.freebsd.org/cgi/man.cgi?query=stty&amp;sektion=1"><em>stty</em></a> command.</p>
<p><em>Note: If you downloaded and installed OpenWrt prior to December 3rd by using the files on this site, stty is most likely missing from your installation.  Unfortunately, the only way I know of to easily fix this is to completely reinstall OpenWrt, since stty is part of busybox and included in the base firmware image.  You can check if you have it by executing &#8216;stty&#8217; from the command line of the router &#8211; if you get an error, you will need to reinstall.</em></p>
<p>You can change the baud rate of the serial port by executing:</p>
<blockquote>
<pre>root@OpenWrt:~#<strong> stty 9600 &lt; /dev/tts/0</strong></pre>
</blockquote>
<p>Connect your FTDI USB-serial cable to the router&#8217;s serial port and open a terminal program set to 9600 baud, 8N1. Execute the last mpd query again, you should see the name and title appear in your terminal window:</p>
<blockquote>
<pre>root@OpenWrt:~#<strong> echo "currentsong" | </strong><strong><strong>nc localhost 6600 | grep -e "^Title: "
-e "^Name: "</strong></strong><strong> &gt; /dev/tts/0</strong></pre>
<p>In the terminal window:</p>
<pre>Name: SLAY Radio
Title: Jogeir Liljedahl - Terra Cresta</pre>
</blockquote>
<p>Now we have a way to get information about the current song and direct it to the serial port.</p>
<p>We can do this is an automated way by using a shell script:</p>
<blockquote>
<pre>#! /bin/sh -
# display.sh - Wifi Radio LCD display routines
# 12/12/08    Jeff Keyzer    http://mightyohm.com
# This shell script queries mpd for current song information and sends
# relevant bits of it to the serial port, where an AVR-based LCD display
# is waiting.
#
# For more information, visit
# http://mightyohm.com/blog/
#
trap 'exit 1' SIGINT    # exit on ctrl-c, useful for debugging
stty 9600 &lt; /dev/tts/0  # set serial port to 9600 baud
                        # so we can talk to the AVR
while true        # loop forever
do
 echo "currentsong" | nc localhost 6600 | grep -e "^Title: " -e "^Name: " &gt; /dev/tts/0
 sleep 1
done</pre>
</blockquote>
<p>You can either copy and paste this script to a file on the router, or download it with <a href="http://en.wikipedia.org/wiki/Wget"><em>wget</em></a>:</p>
<blockquote>
<pre>root@OpenWrt:~# <strong>cd ~</strong>
root@OpenWrt:~# <strong>wget http://mightyohm.com/files/wifiradio/display.sh</strong>
Connecting to mightyohm.com (72.32.209.132:80)
display.sh           100% |*******************************|   668  --:--:-- ETA</pre>
</blockquote>
<p>Be sure to make the script executable by using <a href="http://en.wikipedia.org/wiki/Chmod"><em>chmod</em></a>:</p>
<blockquote>
<pre>root@OpenWrt:~# <strong>chmod ugo+x display.sh</strong></pre>
</blockquote>
<p>If you run the script you should see the name and title information update in the serial terminal once a second.</p>
<blockquote>
<pre>root@OpenWrt:~# ./display.sh</pre>
</blockquote>
<p>The script will loop forever &#8211; hit control-c in the router&#8217;s shell to exit.</p>
<p>That&#8217;s it for part six!  In <a href="http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-7-building-an-lcd-display/">part seven</a>, we&#8217;ll add an AVR-based serial LCD display to the router &#8211; stay tuned!</p>
<p><strong>Update:</strong> <a href="http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-7-building-an-lcd-display/">Part seven is now available.</a></p>
<p><strong>Update 2:</strong> There is a new <a href="http://mightyohm.com/forum/viewforum.php?f=2">Wifi Radio Discussion Forum</a>, hop over there to ask questions about the project or see what other people are working on!  (<em>4/12/09)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-6-a-conversation-with-mpd/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Building a Wifi Radio &#8211; Part 5, Let&#8217;s Make Some Noise!</title>
		<link>http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-5-lets-make-some-noise/</link>
		<comments>http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-5-lets-make-some-noise/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 08:01:31 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mpd]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[Streaming Radio]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[wifiradio]]></category>

		<guid isPermaLink="false">http://mightyohm.com/blog/?p=598</guid>
		<description><![CDATA[This is the fifth part of an ongoing series at mightyOhm about building a low cost, open source streaming internet radio.  If you haven&#8217;t already, check out the previous parts below for some background about the project. Building a Wifi Radio &#8211; Part 1, Introduction Building a Wifi Radio &#8211; Part 2, Choosing an Embedded [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the fifth part of an ongoing series at mightyOhm about building a low cost, open source streaming internet radio.  If you haven&#8217;t already, check out the previous parts below for some background about the project.</em></p>
<p><a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/">Building a Wifi Radio &#8211; Part 1, Introduction</a></p>
<p><a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/">Building a Wifi Radio &#8211; Part 2, Choosing an Embedded Platform</a></p>
<p><a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/">Building a Wifi Radio &#8211; Part 3, Hacking the Asus WL-520GU</a></p>
<p><a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-4-installing-openwrt/">Building a Wifi Radio &#8211; Part 4, Installing OpenWrt</a></p>
<h4>Note:</h4>
<p>The instructions that follow assume that you have an Asus WL-520GU wireless router with the following modifications: an externally accessible serial port, OpenWrt installed and working, and a configured network connection on the router.  If not, check out the previous parts of the series to learn more.</p>
<h3>Using opkg to customize OpenWrt:</h3>
<p><a href="http://openwrt.org">OpenWrt</a> includes a utility called <a href="http://wiki.openwrt.org/OpenWrtDocs/Packages#head-483764faec3e847c48e0794e875a7823eb4fd3aa">opkg</a> that allows the end user to easily add and remove optional software packages.  These packages include functionality that is not a part of the OpenWrt base image, such as hardware drivers (including USB), optional software, and utilities.  Most packages are not installed by default (after all, the router only contains 4MB of flash storage).  The <a href="http://wiki.openwrt.org/OpenWrtDocs">OpenWrt Community Wiki</a> includes a <a href="http://wiki.openwrt.org/OpenWrtDocs/Packages">very helpful page about Packages</a> that contains a lot of useful information about configuring and using opkg.</p>
<p>Before we can use opkg we need to configure it.  The file <em>/etc/opkg.conf</em> contains a few options, including the URL of the server opkg uses to find and download packages.  We need to change this server from the default by modifying the config file:</p>
<blockquote>
<pre>root@OpenWrt:~# vi /etc/opkg.conf</pre>
</blockquote>
<p>Modify the first line to look like this:</p>
<blockquote>
<pre>src/gz snapshots <strong>http://mightyohm.com/files/kamikaze-2.4/packages/mipsel </strong></pre>
<pre>dest root /</pre>
<pre>dest ram /tmp</pre>
<pre>lists_dir ext /var/opkg-lists</pre>
</blockquote>
<p>You can also download the <a href="http://mightyohm.com/files/kamikaze-wl520gu.zip">complete set of packages</a> and set up a server of your own for opkg to access.  I have had great success using the <a href="http://www.apache.org/">apache</a> server included with OS X, but I won&#8217;t cover the setup here.</p>
<p>The following command tells opkg to fetch a list of available packages from the server:</p>
<blockquote>
<pre>root@OpenWrt:~# opkg update</pre>
</blockquote>
<p>You should see the following response:</p>
<blockquote>
<pre>Downloading http://mightyohm.com/files/kamikaze-2.4/packages/mipsel/Packages.gz</pre>
<pre>Connecting to mightyohm.com (72.32.209.132:80)</pre>
<pre>Packages.gz          100% |*******************************|  8326  --:--:-- ETA</pre>
<pre>Inflating http://mightyohm.com/files/kamikaze-2.4/packages/mipsel/Packages.gz</pre>
<pre>Updated list of available packages in /var/opkg-lists/snapshots</pre>
<pre>Signiture check for snapshots skipped because GPG support was not enabled in this build</pre>
</blockquote>
<p>Now we can start installing packages.  To access our <a href="http://mightyohm.com/blog/2008/10/inside-the-syba-sd-cm-uaud-usb-stereo-audio-adapter/">USB-audio converter</a>, we need to install USB 1.1 (OHCI) support and some sound drivers:</p>
<blockquote>
<pre>root@OpenWrt:~# opkg install kmod-usb-audio kmod-usb-ohci</pre>
</blockquote>
<p>This should automatically install <em>kmod-usb-core</em> and <em>kmod-sound-core</em>, but if not you can also install them manually with the <em>opkg install</em> command.</p>
<p>At this point you should insert the USB-audio converter if you haven&#8217;t already.  Then reboot the router:</p>
<blockquote>
<pre>root@OpenWrt:~# reboot</pre>
</blockquote>
<p>As the router is booting again, watch for new status messages like these:</p>
<blockquote>
<pre>...
usb-ohci.c: USB OHCI at membase 0xb8003000, IRQ 6</pre>
<pre>usb-ohci.c: usb-00:03.0, PCI device 14e4:471a</pre>
<pre>usb.c: new USB bus registered, assigned bus number 1</pre>
<pre>usb.c: registered new driver audio</pre>
<pre>audio.c: v1.0.0:USB Audio Class driver</pre>
<pre>usbaudio: device 2 audiocontrol interface 0 has 1 input and 1 output AudioStreaming interfaces</pre>
<pre>usbaudio: device 2 interface 2 altsetting 1 channels 1 framesize 2 configured</pre>
<pre>usbaudio: valid input sample rate 48000</pre>
<pre>usbaudio: valid input sample rate 44100</pre>
<pre>usbaudio: device 2 interface 2 altsetting 1: format 0x00000010 sratelo 44100 sratehi 48000 attributes 0x01</pre>
<pre>...
usbaudio: registered dsp 14,3</pre>
<pre>usbaudio: constructing mixer for Terminal 6 type 0x0301</pre>
<pre>...</pre>
</blockquote>
<p>If you see this, the USB-audio converter is most likely working and the correct drivers have been loaded.  At this point the green LED inside the USB-audio converter should be lit, another sign that everything is working correctly.</p>
<h3>Installing mpd:</h3>
<p>To actually play some tunes we need to install some additional software.  We can use opkg to do this, as follows:</p>
<blockquote>
<pre>root@OpenWrt:~# opkg update

root@OpenWrt:~# opkg install mpd mpc</pre>
</blockquote>
<p>This command installs <a href="http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki">mpd</a>, the music player daemon.  mpd is an open source music server that can be accessed locally or across a network by using a variety of <a href="http://mpd.wikia.com/wiki/Clients">clients</a>, which are available for many different platforms.  This includes the command line client <a href="http://mpd.wikia.com/wiki/Client:Mpc">mpc</a> which is also now installed on the router.</p>
<p>mpd requires some setup before we can use it:</p>
<blockquote>
<pre>root@OpenWrt:~# cd ~</pre>
<pre>root@OpenWrt:~# mkdir .mpd</pre>
<pre>root@OpenWrt:~# mkdir music</pre>
<pre>root@OpenWrt:~# mkdir .mpd/playlists</pre>
<pre>root@OpenWrt:~# vi /etc/mpd.conf</pre>
</blockquote>
<p>Scroll down and look for the audio_output section of the mpd configuration file, and change the reference to <em>/dev/dsp</em> to make it look like this:</p>
<blockquote>
<pre># An example of an OSS output:
#
audio_output {
        type                    "oss"
        name                    "My OSS Device"
        device                  <strong>"/dev/sound/dsp"</strong>
        format                  "44100:16:2"
}</pre>
</blockquote>
<p>There are many other options you can play with; mpd is very powerful.  There is a list of features <a href="http://mpd.wikia.com/wiki/Features">here</a> and a lot more information on the <a href="http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki">mpd wiki</a>.</p>
<p>Exit vi, saving the changes to mpd.conf.  Now launch mpd with the following command:</p>
<blockquote>
<pre>root@OpenWrt:~# mpd</pre>
</blockquote>
<p>The player should start silently, without errors.  Run mpc and verify that it can talk to the server:</p>
<blockquote>
<pre>root@OpenWrt:~# mpc
volume:100%   repeat: off   random: off</pre>
</blockquote>
<p>If you see this, good news, the server is running and we have the ability to control it with mpc!</p>
<p>Now would be a good time to connect speakers or headphones to the USB-audio adapter&#8217;s headphone output.  <strong>Warning &#8211; the initial volume can be </strong><strong>VERY LOUD.</strong> Don&#8217;t wear headphones during testing!  PC speakers with a volume control are best.  Start at a low volume.  (My ears are still ringing!)</p>
<p>We can add a streaming radio server to the playlist by executing</p>
<blockquote>
<pre>root@OpenWrt:~# mpc add http://relay3.slayradio.org:8000/
adding: http://relay3.slayradio.org:8000/</pre>
</blockquote>
<h3><strong>And finally, the moment of truth:</strong></h3>
<blockquote>
<pre>root@OpenWrt:~# mpc play</pre>
<pre>http://relay3.slayradio.org:8000/</pre>
<pre>[playing] #1/1   0:00/0:00 (100%)</pre>
<pre>volume:100%   repeat: off   random: off</pre>
<pre>root@OpenWrt:~#</pre>
</blockquote>
<p>If all goes well, within a few seconds you should hear <a href="http://slayradio.org/">Slay Radio</a> playing on your headphones or speakers.  The Air light on the router should flicker as traffic crosses the WiFi interface, and the green light on the USB-audio converter should flash repeatedly to indicate that audio is being sent to the device.</p>
<p>If you&#8217;ve made it this far, I recommend celebrating with your <a href="http://www.flickr.com/photos/mightyohm/2680813515/">favorite beverage</a> and enjoying some tunes!  Congratulations!</p>
<p>You can add other servers to the playlist by executing the <em>mpc add</em> command again, and then play them with the <em>mpc play n </em>command, where <em>n</em> is the position of the server in the playlist.  <em>mpc playlist</em> will display the current playlist. <em>mpc help</em> will give you a list of available commands.</p>
<p>One very powerful feature of mpd is that it operates as a server on port 6600 of the router, so it can be controlled from any other device on your local network.  If you download an mpd client such as <a href="https://theremin.sigterm.eu/cgi-bin/trac.cgi">Theramin</a>, you can control the router remotely from your desktop computer.  There is an excellent <a href="http://www.katoemba.net/makesnosenseatall/mpod/">client for the iPhone</a> too.</p>
<p>That&#8217;s it for part five.   I hope you have enjoyed the series thus far.  In part six, we&#8217;ll start writing some scripts to control mpd and talk about options for a user interface.  If you are building a Wifi Radio of your own, I&#8217;d love to hear about it &#8211; leave a comment below!</p>
<p><strong>Update:</strong> <a href="http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-6-a-conversation-with-mpd/">Part six</a> is now available.</p>
]]></content:encoded>
			<wfw:commentRss>http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-5-lets-make-some-noise/feed/</wfw:commentRss>
		<slash:comments>83</slash:comments>
		</item>
		<item>
		<title>Building a Wifi Radio &#8211; Part 4, Installing OpenWrt</title>
		<link>http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-4-installing-openwrt/</link>
		<comments>http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-4-installing-openwrt/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 18:08:43 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenWRT]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[Streaming Radio]]></category>
		<category><![CDATA[wifiradio]]></category>

		<guid isPermaLink="false">http://mightyohm.com/blog/?p=516</guid>
		<description><![CDATA[This is the fourth part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven’t already, check out parts one, two, and three for some background about the project. At this point you should have an Asus WL-520GU wireless router with a serial port header installed and some [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the fourth part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven’t already, check out parts <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/">one</a>, <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/">two</a>, and <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/">three</a> for some background about the project.</em></p>
<p>At this point you should have an <a href="http://www.asus.com/products.aspx?l1=12&amp;l2=43&amp;l3=0&amp;l4=0&amp;model=1671&amp;modelmenu=1">Asus WL-520GU</a> wireless router with a <a href="http://flickr.com/photos/mightyohm/2980057918/in/set-72157607903511625/">serial port header installed</a> and some way of communicating with the serial port from your PC.  If not, go back to <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/">part three</a>.</p>
<h3><strong>What is OpenWrt?</strong></h3>
<p>According to <a href="http://openwrt.org">openwrt.org</a>:</p>
<blockquote><p>OpenWrt is described as a Linux distribution for embedded devices.</p></blockquote>
<p><a href="http://openwrt.org/"><img class="alignnone size-full wp-image-2989" title="OpenWrt" src="http://mightyohm.com/blog/wp-content/uploads/2008/11/openwrt_logo.png" alt="" width="320" height="81" /></a></p>
<p>OpenWrt replaces the stock firmware on the WL-520GU with an open source <a href="http://www.kernel.org/">Linux</a> distribution that aims to be extremely powerful and flexible.  This is important for us because in turning a wireless router into a Wifi radio, we using the device in a way that the manufacturer never intended for it to be used.  In addition to including a stripped down version of the Linux operating system, drivers for wireless networking and all the basic functionality of a residential network gateway, a package manager called <a href="http://wiki.openmoko.org/wiki/Opkg">opkg</a> allows you to install a wide variety of add-on modules to extend the functionality even further.</p>
<h3><strong>Setup:</strong></h3>
<p>To install OpenWrt on the WL-520GU you will need a few things:</p>
<ul>
<li>Your Asus WL-520GU wireless router, modified to allow access to the internal serial port</li>
<li>A 3.3V USB-serial cable like the <a href="http://www.ftdichip.com/Products/EvaluationKits/TTL-232R-3V3.htm">FTDI-232-3V3</a></li>
<li>A short ethernet cable (a crossover cable is not required)</li>
<li>A desktop or laptop computer with an open USB and ethernet port</li>
<li>A terminal program such as <a href="http://homepage.mac.com/dalverson/zterm/">ZTerm</a> or Hyperterminal</li>
<li>A <a href="http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol">TFTP client</a>, (surprisingly) included with most operating systems.  I&#8217;ll be using the one included with OS X.</li>
<li>A WiFi network with a reasonably simple encryption scheme (ie. none, WEP, WPA)</li>
</ul>
<p>If you want to compile your own OpenWrt image and optional packages, you&#8217;ll also need</p>
<ul>
<li>A machine running <a href="http://www.debian.org/">Debian</a> or similar Linux operating system, or if you are really ambitious, a Mac running OS X.  I won&#8217;t cover compiling OpenWrt using OS X here, but there are several issues that prevent it from being straightfoward, the first of which is that <a href="http://developer.apple.com/technotes/tn/tn1150.html">OS X does not use a case-sensitive filesystem by default</a>.</li>
</ul>
<p><strong>Note:</strong> If for any reason you need to go back to the stock firmware, you can download it from Asus <a href="http://support.asus.com/download/download.aspx?SLanguage=en-us">here</a> (enter WL-520GU into the search field on the left).</p>
<h3>Getting OpenWrt:</h3>
<p>There are two ways to do this:</p>
<h4>The hard way:</h4>
<p>Visit the <a href="http://wiki.openwrt.org/">OpenWrt Wiki</a> and read the instructions on <a href="http://wiki.openwrt.org/OpenWrtDocs/Installation">Installation</a>.  Follow <a href="http://wiki.openwrt.org/OpenWrtDocs/BuildingKamikazeHowTo">these instructions</a> to build Kamikaze (<a href="http://downloads.openwrt.org/kamikaze/release.txt">Kamikaze</a> is the current OpenWrt distribution).  Download the source with subversion (<a href="http://subversion.tigris.org/">svn</a>), and compile it yourself.  This method requires a moderate level of skill with Linux, but if you can compile your own kernel you should be able to compile OpenWrt.  You will need to link to the feeds for madplay, mpc, and mpd (as well as any other 3rd party packages you want) before executing <em>make menuconfig</em>, by using the <em>scripts/feeds</em> command.  Here is the sequence of commands I used, yours may differ slightly:</p>
<blockquote>
<pre>svn co https://svn.openwrt.org/openwrt/trunk/ ~/kamikaze
cd ~/kamikaze
./scripts/feeds update -a
./scripts/feeds install madplay mpc mpd
make prereq</pre>
</blockquote>
<p>If make fails, you may need to install some optional Linux tools, such as gawk, bison, or gcc.  On Debian I used the apt-get command to do this</p>
<blockquote>
<pre>apt-get install gawk bison gcc</pre>
</blockquote>
<p>Once you have all necessary prerequisites installed, you can configure the build with</p>
<blockquote>
<pre>make menuconfig</pre>
</blockquote>
<p>You&#8217;ll need to set the following options:</p>
<ul>
<blockquote>
<li>Target System (Broadcom BCM947xx/953xx [2.4])</li>
<li>Target Profile (Generic, Broadcom WiFi (default))</li>
<li>Select all packages by default</li>
<li>Image configuration &#8212;&gt;
<ul>
<li>Base system<em><strong> (Added 12/18/08 to support <a href="http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-6-a-conversation-with-mpd/">part six</a>)</strong></em>
<ul>
<li>busybox (press enter to open hidden menu)
<ul>
<li>Configuration
<ul>
<li>Coreutils
<ul>
<li>stty</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>Kernel modules
<ul>
<li>Sound support
<ul>
<li>kmod-sound-core</li>
</ul>
</li>
<li>USB support
<ul>
<li>kmod-usb-core</li>
<li>kmod-usb-ohci</li>
<li>kmod-usb-audio</li>
</ul>
</li>
</ul>
</li>
<li>Sound
<ul>
<li>mpd</li>
<li>mpc</li>
<li>madplay</li>
</ul>
</li>
</ul>
</li>
</blockquote>
</ul>
<p>Once you&#8217;re done, exit, saving the configuration.  Then execute</p>
<blockquote>
<pre>make world</pre>
</blockquote>
<p>This will take quite a while.  If the build fails, you will be prompted to run make again</p>
<blockquote>
<pre>make world V=99</pre>
</blockquote>
<p>and fix any problems that occur, based on the error messages.  The <a href="http://forum.openwrt.org/">OpenWrt forums</a> are a good place to get help, but do a quick search before you post to avoid asking a question that has already been answered.</p>
<p>If the build completes successfully, you should be left with a bunch of files in the kamikaze/bin directory, including <em>openwrt-brcm-2.4-squashfs.trx</em>, the main image file, and a bunch of packages in the <em>bin/packages/mipsel</em> directory.</p>
<h4>The easy way:</h4>
<p>I&#8217;ve already done the hard work for you.</p>
<p>Download my precompiled <a href="http://mightyohm.com/files/kamikaze-2.4/openwrt-brcm-2.4-squashfs.trx">openwrt-brcm-2.4-squashfs.trx </a>image.</p>
<p>Addon packages (you&#8217;ll need a few of these when we configure the router later) are located <a href="http://mightyohm.com/files/kamikaze-2.4/packages/mipsel/">here</a>.</p>
<h3>Installing OpenWrt:</h3>
<p>Connect your FTDI cable to the serial port on the router that you added in <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/">part three</a>.  Launch your favorite terminal program and connect to the router at 115200 baud, 8N1.</p>
<p>Connect the LAN1 port of the router to your computer using a short ethernet cable.  The router is hardcoded to be 192.168.1.1 on boot, and we need to configure our computer to talk to that address.  I set my Macbook to use a static IP of 192.168.1.185.  You may need to set a gateway to 192.168.1.1.  If your home network is also on the 192.168.1.x subnet, you will need to disconnect/disable it.  On my Macbook, this meant disabling the internal wireless and losing internet access while the router was connected.  (Eventually I got tired of this and moved my home network to 192.168.24.x, but that is outside the scope of this tutorial.)</p>
<p>Press and hold the Restore button on the back of the router and plug in the power cable.  The Restore button is shown just to the right of the red EZSetup button here:</p>
<p><a class="tt-flickr tt-flickr-Medium" title="WL-520GU Restore Button Closeup" href="http://www.flickr.com/photos/mightyohm/2998014649/"><img class="alignnone" src="http://farm4.static.flickr.com/3250/2998014649_4fb634f372.jpg" alt="WL-520GU Restore Button Closeup" width="500" height="399" /></a></p>
<p>Continue holding the Restore button until the power LED starts flashing once a second.  Release the restore button.  In your terminal window, you should see some boot messages and then</p>
<blockquote>
<pre>Reading :: TFTP Server.
Failed.: Timeout occured
Reading :: TFTP Server.
Failed.: Timeout occured</pre>
</blockquote>
<p>and so on (the messages will repeat forever).</p>
<p>Now it&#8217;s time to transfer our .trx file to the router.  These instructions are for OS X.  Instructions for other operating systems are <a href="http://wiki.openwrt.org/OpenWrtDocs/Installing/TFTP">here</a>.</p>
<blockquote>
<pre>cd ~/kamikaze/bin
tftp
trace
timeout 1
mode binary
connect 192.168.1.1
put openwrt-brcm-2.4-squashfs.trx</pre>
</blockquote>
<p>On the serial console you should see (exact numbers may vary):</p>
<blockquote>
<pre>Reading :: TFTP Server.
TFTP_BLKLEN!!
break!! last block!!
Done. 1918724 bytes read
Download of 0x1d4704 bytes completed
Write kernel and filesystem binary to FLASH (0xbfc20000)
Programming...
copysize=1918724, amtcopy=1918724</pre>
</blockquote>
<p>If you don&#8217;t see this, chances are your computer is not talking to the router.  Most likely this is a configuration problem with your ethernet port or you don&#8217;t have the cable connected to a LAN port of the router.</p>
<p>If it worked,<strong> wait a couple minutes</strong> (don&#8217;t touch anything, unplugging the router at this point could <a href="http://en.wikipedia.org/wiki/Brick_(electronics)">brick the router</a>!)  Eventually you should see the message</p>
<blockquote>
<pre>done. 1918724 bytes written</pre>
</blockquote>
<p>After this message appears (it typically takes 3-5 minutes for the whole process) unplug the router, wait a few seconds, and then plug it back in again.  In your serial terminal window, you should see the Linux boot messages again, but the process will pause briefly while the jffs file system is created.  Once the router has finished booting, you&#8217;ll see a couple messages like this</p>
<blockquote>
<pre>mini_fo: using base directory: /
mini_fo: using storage directory: /jffs</pre>
</blockquote>
<p>Press enter and you should now see the OpenWrt banner and a shell prompt</p>
<blockquote>
<pre>BusyBox v1.11.2 (2008-10-02 20:59:06 PDT) built-in shell (ash)</pre>
<pre>Enter 'help' for a list of built-in commands.</pre>
<pre>  _______                     ________        __</pre>
<pre> |       |.-----.-----.-----.|  |  |  |.----.|  |_</pre>
<pre> |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|</pre>
<pre> |_______||   __|_____|__|__||________||__|  |____|</pre>
<pre>          |__| W I R E L E S S   F R E E D O M</pre>
<pre> KAMIKAZE (bleeding edge, r12831) -------------------</pre>
<pre>  * 10 oz Vodka       Shake well with ice and strain</pre>
<pre>  * 10 oz Triple sec  mixture into 10 shot glasses.</pre>
<pre>  * 10 oz lime juice  Salute!</pre>
<pre> ---------------------------------------------------</pre>
<pre>root@OpenWrt:/#</pre>
</blockquote>
<p>Congratulations!  You have successfully installed OpenWrt!</p>
<p>A complete log of the first boot is available <a href="http://mightyohm.com/blog/wp-content/uploads/2008/11/wl-520gu_flash_log_stripped.txt">here</a>.</p>
<h3>Configuring OpenWRT:</h3>
<p>There is a lot of information on the <a href="http://wiki.openwrt.org/OpenWrtDocs">OpenWRT Wiki </a>with regard to <a href="http://wiki.openwrt.org/OpenWrtDocs/KamikazeConfiguration">Configuring Kamikaze</a>, but I will walk through the fairly basic configuration I am using here.  To follow along, you will need to be comfortable using <a href="http://en.wikipedia.org/wiki/Vi">vi</a> (if not, check out this <a href="http://tnerual.eriogerg.free.fr/vim.html">quick reference card</a>.)</p>
<p>You should be able to use your serial terminal to execute the following commands.  I had issues using the arrow keys to navigate in vi and had to use the basic movement keys instead (h=left, l=right, k=up, j=down).</p>
<p>Before we can get the router on a WiFi network we need to modify a couple files.</p>
<blockquote>
<pre>root@OpenWrt:~# vi /etc/config/wireless</pre>
</blockquote>
<p>You should edit this file to look like this (changes are in <strong>bold</strong>)</p>
<blockquote>
<pre>config wifi-device  wl0
	option type     broadcom
	option channel  <strong>2  # the channel your wireless network is on</strong>

	# REMOVE THIS LINE TO ENABLE WIFI:
	<strong># option disabled 1 (comment out or remove this line entirely)

</strong>config wifi-iface
	option device   wl0
	option network	lan
	option mode     <strong>sta</strong>  <strong># configures the router to connect to your network</strong>
	option ssid     <strong>MyNetwork</strong> <strong># the SSID of your network</strong>
	option encryption <strong>wep  # the encryption mode of your network</strong>
	<strong>option key	XXXXXXXXXX  # add this line with your WEP key in place of X...X</strong></pre>
</blockquote>
<p>Now we need to modify the networking configuration to use DHCP (this should apply for most people):</p>
<blockquote>
<pre>root@OpenWrt:~# vi /etc/config/network</pre>
</blockquote>
<p>Scroll down and look for the LAN configuration section, and edit it to look like this (note the dhcp option in bold, also comment out the last two lines as shown):</p>
<blockquote>
<pre>#### LAN configuration
config interface lan
      option type     bridge
      option ifname   "eth0.0"
      option proto    <strong>dhcp
      #</strong>option ipaddr   192.168.1.1<strong>
      #</strong>option netmask  255.255.255.0
<strong></strong><strong></strong></pre>
</blockquote>
<p>Lastly, verify that resolv.conf is set correctly.</p>
<blockquote>
<pre>root@OpenWrt:~# vi /etc/resolv.conf</pre>
</blockquote>
<p>You should see the following line (this assumes the router will get a valid DNS server address via DHCP, if not, you can set it manually here):</p>
<blockquote>
<pre>nameserver 127.0.0.1</pre>
</blockquote>
<p>Then execute the following command:</p>
<blockquote>
<pre>root@OpenWrt:/# /etc/init.d/network restart</pre>
</blockquote>
<p>After a moment, if everything is working, the AIR light on the router should turn on and you should be able to ping some servers by name.</p>
<blockquote>
<pre>root@OpenWrt:/# ping www.google.com
PING www.google.com (74.125.19.104): 56 data bytes
64 bytes from 74.125.19.104: seq=0 ttl=240 time=20.113 ms</pre>
</blockquote>
<p>If you made it this far, congratulations!   You now have a working embedded Linux device on your WiFi network!</p>
<p>That concludes part four of this series.  In <a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-5-lets-make-some-noise/">part five</a>, I&#8217;ll cover installing addon packages using opkg.  If we&#8217;re lucky, we&#8217;ll get the router to play some tunes!</p>
<p><strong>Update:</strong> <a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-5-lets-make-some-noise/">Part five is now available.</a></p>
<p><strong>Update 2:</strong> There is a new <a href="http://mightyohm.com/forum/viewforum.php?f=2">Wifi Radio Discussion Forum</a>, hop over there to ask questions about the project or see what other people are working on!  (<em>4/12/09)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-4-installing-openwrt/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
		<item>
		<title>Building a Wifi Radio &#8211; Part 3, Hacking the Asus WL-520GU</title>
		<link>http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/</link>
		<comments>http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 17:06:55 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Asus]]></category>
		<category><![CDATA[FTDI]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[serial]]></category>
		<category><![CDATA[Streaming Radio]]></category>
		<category><![CDATA[Wifi]]></category>
		<category><![CDATA[wifiradio]]></category>

		<guid isPermaLink="false">http://mightyohm.com/blog/?p=480</guid>
		<description><![CDATA[This is the third part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven’t already, check out part one and part two for some background about the project. Hacking the Asus WL-520GU Wireless Router: In the last part of this series, I selected the Asus WL-520GU wireless [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the third part of an ongoing series about building a low cost, open source streaming internet radio.  If you haven’t already, check out <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/">part one</a> and <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/">part two</a> for some background about the project.</em></p>
<h3><strong>Hacking the Asus WL-520GU Wireless Router:</strong></h3>
<p>In the <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/">last part of this series</a>, I selected the <a href="http://www.asus.com/products.aspx?l1=12&amp;l2=43&amp;l3=0&amp;l4=0&amp;model=1671&amp;modelmenu=1">Asus WL-520GU</a> wireless router as a suitable embedded platform for my Wifi Radio project.  I have since posted <a href="http://mightyohm.com/blog/2008/10/detailed-specs-for-the-asus-wl-520gu-uber-hacking-platform/">some detailed specs</a> on this impressive low-cost router, revealing it&#8217;s powerful <a href="http://www.broadcom.com/collateral/pb/5354-PB01-R.pdf">Broadcom BCM5354 core</a>, 4MB flash, and 16MB SRAM.  Granted, there are many more powerful routers out there that have USB support, will run Linux in various forms, and have built-in WiFi.  However, the WL-520GU does almost everything we need to build a streaming internet radio and costs under $50 (I have seen them for <a href="http://www.tkqlhce.com/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16833320023%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Network%2B-%2BWireless%2BRouters-_-ASUS-_-33320023&amp;cjsku=N82E16833320023" target="_top">as little as $26 after rebate</a><img src="http://www.awltovhc.com/image-3238164-10440897" border="0" alt="" width="1" height="1" />), which is very impressive indeed.</p>
<p>To convert this router into a powerful <a href="http://en.wikipedia.org/wiki/Embedded_system">embedded system</a>, we need to make a couple modifications.  First, we need to throw out the stock <a href="http://en.wikipedia.org/wiki/Firmware">firmware</a>. It turns out that this router, like many others, <a href="http://mightyohm.com/blog/wp-content/uploads/2008/10/wl520gu-stock-firmware-boot.txt">runs Linux from the factory</a>.  However, because it was designed to be a wireless router and not much else, the stock firmware doesn&#8217;t include a very wide set of features (and certainly was not intended to be accessed by the customer).  Thankfully, there are several open source Linux distributions available that support this router, including my favorite, <a href="http://www.openwrt.org">OpenWrt</a>.  In addition, <a href="http://www.asus.com">Asus</a> has made it fairly straightforward replace the stock firmware with our own custom Linux build which can include all the programs, drivers, and utilities we can cram into 4MB of flash.</p>
<h3><strong>Warning:</strong></h3>
<p>Before we start hacking the router, there are a couple things I should mention:</p>
<ul>
<li><strong>From this point onward, your warranty is toast. </strong> Don&#8217;t even <strong>THINK </strong>about trying to send a modified router back to Asus for warranty service.  In the end it hurts people like us, because Asus will try to make it harder for people to perform the same modifications in future products.</li>
<li><strong>You may inadvertently destroy your router.</strong> If you are not comfortable with the fact that a misstep during the reflash or a stray solder bridge could ruin your hardware, stop now.  Sorry.  If you really take a wrong turn, you could damage your PC as well, but this is extremely unlikely.  <em>If you do somehow damage your router or PC doing these modifications, I assume no responsibility for any damages! </em></li>
</ul>
<p>This tutorial assumes that you have already established the router is basically working by assembling it, plugging it in and checking for it&#8217;s wireless signal and internal webserver.  The user manual does a good job of leading you through this process, but don&#8217;t use the supplied CD &#8211; follow the advanced/manual instructions instead.</p>
<h3><strong>Accessing the internal serial port:</strong></h3>
<p>The <a href="http://www.openwrt.org">OpenWrt</a> install will be easier if we can find a way to access the internal serial port of the router.  The built-in serial port gives us a way to view Linux boot and status messages and get <a href="http://en.wikipedia.org/wiki/Shell_access">shell access</a> as well.  The serial port will also come in handy later when we want to add a user interface to the radio.</p>
<h4><strong>You will need:</strong></h4>
<ul>
<li>A desktop or laptop computer with an open USB and Ethernet port. <em><br />
</em></li>
<li>Your shiny new ASUS WL-520GU wireless router (R1.02)</li>
<li>A strip of <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=116">breakaway 0.1&#8243; male header</a></li>
<li>A <a href="http://www.ftdichip.com/Products/EvaluationKits/TTL-232R-3V3.htm">FTDI-232-3V3</a> USB to serial adapter cable ($20 @ <a href="http://www.adafruit.com/index.php?main_page=product_info&amp;products_id=70&amp;sessid=6248f75fb3ff275fdfa9bacf419ca4e5">Adafruit</a>) or some other means of connecting a 3.3V level serial port to your PC</li>
<li>A small scrap of <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8814">perfboard</a> and a strip of <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=115">female 0.1&#8243; header</a> (not strictly necessary, see below)</li>
</ul>
<p style="padding-left: 30px;">-and-</p>
<ul>
<li>A basic electronics workbench with ample light, a temperature controlled soldering iron, a solder sucker, solderbraid, wirecutters, and pliers.  <a href="http://www.servomagazine.com/">Servo Magazine</a> recently held a contest to see who could build the best electronics workbench for under $100, <a href="http://forum.servomagazine.com/viewtopic.php?t=8370">the results</a> should be helpful for anyone just starting out.  If you&#8217;re uncomfortable soldering, find someone else to help you with this part at your local <a href="http://hackerspaces.org/wiki/Hacker_Spaces">hackerspace</a>.</li>
</ul>
<h4><strong>Step 1 &#8211; Open the router</strong></h4>
<p>Remove the power cord and antenna (the base unscrews).  Flip the router over and look at the bottom.  You should see something like this:</p>
<p><a class="tt-flickr tt-flickr-Medium" title="Asus WL-520GU" href="http://www.flickr.com/photos/mightyohm/2980057258/"><img class="alignnone" src="http://farm4.static.flickr.com/3051/2980057258_b14b4fbd5b.jpg" alt="Asus WL-520GU" width="500" height="375" /></a></p>
<p>Note there are four screws that hold the router together, two are hidden underneath the rubber feet.  The feet are stuck on really well, but persistent prying with a fingernail will get them off eventually.  Remove the four screws and set them aside.  The top cover should come off without too much trouble.</p>
<p>Now that the router is open, you should see something like this:</p>
<p><a class="tt-flickr tt-flickr-Medium" title="Asus WL-520GU Wireless Router" href="http://www.flickr.com/photos/mightyohm/2950280015/"><img class="alignnone" src="http://farm4.static.flickr.com/3203/2950280015_910ea93e73.jpg" alt="Asus WL-520GU Wireless Router" width="500" height="375" /></a></p>
<h4><strong>Step 2 &#8211; Add a serial port header</strong></h4>
<p>Remove the PCB from the plastic enclosure by gently pulling it up and towards you (ethernet ports facing away).</p>
<p>Just to the left of the ASUS logo in the photo below, you will see a 4-pin header that I have installed to access the internal serial port of the router, the router ships without this header.  Instead, you will see four solder filled vias in a row in the same spot.</p>
<p>You will need to use your soldering iron and a solder sucker to remove most of the solder so that the header can be installed.  A higher power soldering iron will help with removing solder from the first via on the left (mine is a 60W <a href="javascript:OnClick=self.openwindow('037103001146')">Weller WTCPT</a>).  This via connects to a <a href="http://en.wikipedia.org/wiki/Ground_plane#Printed_circuit_boards">ground plane</a> which sucks heat away from the iron and makes the job more difficult.  Be patient and persistent and you should be able to wick any remaining solder away with some soldering braid if necessary.</p>
<p>Break a 4-pin chunk of male header off the strip.  Pop the header into the board and carefully solder it into place.  If it doesn&#8217;t fit, chances are there is still some solder left in the vias.  You should end up with something like this:</p>
<p><a class="tt-flickr tt-flickr-Medium" title="WL-520GU serial port" href="http://www.flickr.com/photos/mightyohm/2980058214/"><img class="alignnone" src="http://farm4.static.flickr.com/3145/2980058214_09a5945b38.jpg" alt="WL-520GU serial port" width="500" height="375" /></a></p>
<p>The pin functions are, from left to right in the photo:</p>
<blockquote><p>GND   TX   RX   3.3V</p></blockquote>
<h4>Step 3 &#8211; Connect your PC</h4>
<p>The <a href="http://www.ftdichip.com/Products/EvaluationKits/TTL-232R-3V3.htm">FTDI-232-3V3</a> USB to serial adapter cable provides a handy way to add a 3.3V TTL level serial port to a PC or laptop.  The cable has a flat connector on the serial end that can plug directly onto 0.1&#8243; male headers like the one we are using on the router.  Unfortunately, the pinout of the FTDI cable (<a href="http://www.ftdichip.com/Documents/DataSheets/Modules/DS_TTL-232R_CABLES_V201.pdf">given in the datasheet</a>) does not match that of the router.  To resolve this, you have two options:</p>
<ul>
<li>Use a tiny screwdriver to pull out the pins from the housing at the cable and rearrange them.  Do not connect anything to the 3.3V pin on the router, and swap the TX/RX so that the TX on the router feeds RX on the cable, and vice-versa.  Don&#8217;t forget to connect the grounds!  The downside of this is that now you can&#8217;t use the FTDI cable for things like the <a href="http://www.ladyada.net/make/boarduino/">Boarduino</a> without swapping the pins back.</li>
</ul>
<p style="padding-left: 30px;">-or-</p>
<ul>
<li>Fabricate an adapter board using a small piece of perfboard and some headers, shown below (click for a larger version):</li>
</ul>
<p><a class="tt-flickr tt-flickr-Small" title="Asus wireless router serial port adapter" href="http://www.flickr.com/photos/mightyohm/2979200785/"><img class="alignnone" src="http://farm4.static.flickr.com/3284/2979200785_01c8d3c294_m.jpg" alt="Asus wireless router serial port adapter" width="240" height="180" /></a> <a class="tt-flickr tt-flickr-Small" title="Asus wireless router serial port adapter" href="http://www.flickr.com/photos/mightyohm/2980057458/"><img class="alignnone" src="http://farm4.static.flickr.com/3278/2980057458_e364b3857d_m.jpg" alt="Asus wireless router serial port adapter" width="240" height="180" /></a></p>
<p>Here is a schematic of the adapter board:</p>
<p><a href="http://mightyohm.com/blog/wp-content/uploads/2008/10/asus-serial-port-adapter.png"><img class="alignnone size-full wp-image-481" title="Asus Serial Port Adapter" src="http://mightyohm.com/blog/wp-content/uploads/2008/10/asus-serial-port-adapter.png" alt="" width="500" height="372" /></a></p>
<p>Shown here are the cable and adapter installed on the router.  Make sure the ground side of the cable is connected to the pin on the header that is <strong>opposite</strong> from the fat angled trace (the 3.3V line).  Ground is the black wire, on my adapter I marked this with a black dot so I won&#8217;t forget and plug it in backwards.</p>
<p><a class="tt-flickr tt-flickr-Medium" title="WL-520GU with serial cable installed" href="http://www.flickr.com/photos/mightyohm/2980057918/"><img class="alignnone" src="http://farm4.static.flickr.com/3241/2980057918_e1b12e577a.jpg" alt="WL-520GU with serial cable installed" width="500" height="375" /></a></p>
<h4>Step 4 &#8211; Test the connection</h4>
<p>Plug the cable into your PC (you may need some <a href="http://www.ftdichip.com/Drivers/VCP.htm">drivers</a>) and open your favorite terminal program.  (I like <a href="http://homepage.mac.com/dalverson/zterm/">Zterm</a> for the Mac or Hyperterminal on the PC.)   Using the terminal program, open the serial port corresponding to the FTDI cable (something like <em>usbserial-FTDQ23LB</em> on the Mac or <em>COM3</em> on the PC, but your setup may be different.)   Set the port options to 115200 baud, 8N1.</p>
<p>Connect the antenna and power supply to the router and plug it in.  You should see something like this appear in your terminal program:</p>
<blockquote>
<pre>Decompressing..........done</pre>
<pre>CFE version 1.0.37 for BCM947XX (32bit,SP,LE)</pre>
<pre>Build Date: Thu Mar  6 10:05:04 CST 2008 (root@localhost.localdomain)</pre>
<pre>Copyright (C) 2000,2001,2002,2003 Broadcom Corporation.</pre>
<pre>Initializing Arena</pre>
<pre>Initializing Devices.</pre>
<pre>Boot partition size = 131072(0x20000)</pre>
<pre>et0: Broadcom BCM47xx 10/100 Mbps Ethernet Controller 4.130.31.0</pre>
<pre>
<pre>Total memory: 16384 KBytes</pre>
</pre>
<pre>CPU type 0x29029: 240MHz
...</pre>
</blockquote>
<p>If you do, congratulations, your serial port is working!</p>
<p>The lines that scroll by are boot messages from the Linux <a href="http://en.wikipedia.org/wiki/Linux_kernel">kernel</a> of the stock firmware on the router.  These messages give you a lot of information about the hardware in addition to information about the operating system and software drivers.  Here is a <a href="http://mightyohm.com/blog/wp-content/uploads/2008/10/wl520gu-stock-firmware-boot.txt">complete transcript of the boot log</a> from my router.  If you wait a couple minutes for the router to finish booting and hit enter, you should see a command prompt.  From here you can explore and play around with the stock firmware, there is really not much to do here until we reflash the router with OpenWrt.</p>
<p>That&#8217;s it for part three.  In <a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-4-installing-openwrt/">part four</a>, I&#8217;ll talk about installing OpenWrt and connecting the router to your wireless network.</p>
<p><strong>Update: </strong><a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-4-installing-openwrt/">Part four is now available.</a></p>
<p><strong>Update 2:</strong> There is a new <a href="http://mightyohm.com/forum/viewforum.php?f=2">Wifi Radio Discussion Forum</a>, hop over there to ask questions about the project or see what other people are working on!  (<em>4/12/09)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/feed/</wfw:commentRss>
		<slash:comments>53</slash:comments>
		</item>
		<item>
		<title>Inside the SYBA SD-CM-UAUD USB Stereo Audio Adapter</title>
		<link>http://mightyohm.com/blog/2008/10/inside-the-syba-sd-cm-uaud-usb-stereo-audio-adapter/</link>
		<comments>http://mightyohm.com/blog/2008/10/inside-the-syba-sd-cm-uaud-usb-stereo-audio-adapter/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 15:21:36 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Audio]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[pcb]]></category>
		<category><![CDATA[Streaming Radio]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[wifiradio]]></category>

		<guid isPermaLink="false">http://mightyohm.com/blog/?p=464</guid>
		<description><![CDATA[I am using this tiny USB-audio adapter as part of my Wifi Radio project.  It&#8217;s a ridiculously cheap $8 at Newegg.com and contains a C-Media CM119 chip targeted at VoIP applications.  I have no idea why they chose to use a VoIP chip for this application because it contains a lot of bells and whistles [...]]]></description>
			<content:encoded><![CDATA[<p><a class="tt-flickr tt-flickr-Medium" title="SYBA SD-CM-UAUD USB Stereo Audio Adapter" href="http://www.flickr.com/photos/mightyohm/2979795890/"><img class="alignnone" src="http://farm4.static.flickr.com/3286/2979795890_b29ce48e3e.jpg" alt="SYBA SD-CM-UAUD USB Stereo Audio Adapter" width="500" height="375" /></a></p>
<p>I am using this tiny USB-audio adapter as part of my <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/">Wifi Radio project</a>.  It&#8217;s a ridiculously cheap <a href="http://www.jdoqocy.com/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16812186035%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Adapters%2Band%2Bgender%2Bchangers-_-Syba-_-12186035&#038;cjsku=N82E16812186035" target="_top">$8 at Newegg.com</a><img src="http://www.awltovhc.com/image-3238164-10440897" width="1" height="1" border="0"/> and contains a <a href="http://www.cmedia.com.tw/?q=en/USB/cm119">C-Media CM119 chip</a> targeted at <a href="http://en.wikipedia.org/wiki/Voip">VoIP</a> applications.  I have no idea why they chose to use a VoIP chip for this application because it contains a lot of bells and whistles that are not being used in this device, such as support for a matrix keypad!</p>
<p><a class="tt-flickr tt-flickr-Medium" title="SYBA SD-CM-UAUD USB Stereo Audio Adapter" href="http://www.flickr.com/photos/mightyohm/2979796540/"><img class="alignnone" src="http://farm4.static.flickr.com/3006/2979796540_a07d6c17aa.jpg" alt="SYBA SD-CM-UAUD USB Stereo Audio Adapter" width="500" height="375" /></a></p>
<p>Unfortunately, I have not been able to locate a datasheet for the CM119 so for now I will be using it only for it&#8217;s intended application &#8211; adding an audio output to a wireless router with USB.  Come to think of it, that is probably not it&#8217;s intended application, but it&#8217;s close enough.  Hooray for <a href="http://www.openwrt.org">embedded Linux</a>!</p>
<p><a class="tt-flickr tt-flickr-Medium" title="SYBA SD-CM-UAUD USB Stereo Audio Adapter" href="http://www.flickr.com/photos/mightyohm/2978939643/"><img class="alignnone" src="http://farm4.static.flickr.com/3277/2978939643_056d1d8d3f.jpg" alt="SYBA SD-CM-UAUD USB Stereo Audio Adapter" width="500" height="375" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://mightyohm.com/blog/2008/10/inside-the-syba-sd-cm-uaud-usb-stereo-audio-adapter/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Building a Wifi Radio &#8211; Part 2, Choosing an Embedded Platform</title>
		<link>http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/</link>
		<comments>http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 06:44:26 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[Streaming Radio]]></category>
		<category><![CDATA[wifiradio]]></category>

		<guid isPermaLink="false">http://mightyohm.com/blog/?p=367</guid>
		<description><![CDATA[This is the second part of an ongoing series about building a low cost, open source streaming internet radio.  if you haven&#8217;t already, check out part one for some background about the project. Onward&#8230; In part one, I discussed the merits of streaming internet radio and the motivations for my Wifi Radio project.  Now it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><em> This is the second part of an ongoing series about building a low cost, open source streaming internet radio.  if you haven&#8217;t already, <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/">check out part one</a> for some background about the project.</em></p>
<h3><strong>Onward&#8230;</strong></h3>
<p>In <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/">part one</a>, I discussed the merits of streaming internet radio and the motivations for my Wifi Radio project.  Now it&#8217;s time to start looking at what hardware can make this project a reality.  Before we get started, let&#8217;s review the requirements list from last time.</p>
<p><em>Requirements:</em></p>
<ul>
<li>Wireless connectivity through existing Wifi network</li>
<li>Audio output (preferably 44kHz, 16 bit stereo)</li>
<li>An integrated amplifier and speaker(s)</li>
<li><a href="http://www.shoutcast.com">Shoutcast</a>/MP3 streaming audio decode</li>
<li>Several builtin station presets</li>
<li>A display to indicate the station and currently playing song</li>
<li>Simple user interface, using standard radio controls (volume, tune, etc)</li>
<li>110VAC operation</li>
</ul>
<p>There are two additional requirements that I implied in the first post but forgot to include explicitly:</p>
<ul>
<li>Cheap, priced below a commercial streaming radio &#8211; target &lt; $100.</li>
<li>Small size so it can be portable (no desktop PC&#8217;s allowed!)</li>
</ul>
<h3><strong>Selecting the hardware:</strong></h3>
<p>How do these requirements translate into hardware?  Let&#8217;s take a stab at what features we&#8217;d like in an embedded platform.</p>
<ul>
<li>A wireless interface</li>
<li>Audio output</li>
<li>Sufficient system resources (CPU, memory, etc.) to decode MP3s</li>
<li>Some extra IO for a control panel and display</li>
<li>Low cost</li>
<li>Small size</li>
<li>Ease of development</li>
</ul>
<p>The size and cost aspects pushed me towards an <a href="http://en.wikipedia.org/wiki/Embedded_system">embedded system</a> instead of a small form factor PC like any of <a href="http://us.shuttle.com/Home.aspx">Shuttle&#8217;s XPC</a> offerings or a <a href="http://en.wikipedia.org/wiki/Nano-ITX">nano-ITX </a>board.  To me, &#8220;Ease of development&#8221; equals <a href="http://en.wikipedia.org/wiki/Linux">Linux</a>, so I wanted something well supported by Linux and an active <a href="http://en.wikipedia.org/wiki/Open_source">open source</a> development community.</p>
<p>There are quite a few <a href="http://www.linuxdevices.com/">embedded Linux</a> platforms out there, with a wide variety of prices and features.  I looked at a few of them, including:</p>
<p><a href="http://mightyohm.com/blog/wp-content/uploads/2008/10/hammer_01-large.jpg"><img class="alignright" title="Image courtesy Tin Can Tools" src="http://mightyohm.com/blog/wp-content/uploads/2008/10/hammer_01-large-150x150.jpg" alt="" width="90" height="90" /></a></p>
<ul>
<li>The <a href="http://www.tincantools.com/">Tin Can Tools</a> <a href="http://www.tincantools.com/product.php?productid=16133&amp;cat=0&amp;page=1&amp;featured">Hammer</a> &#8211; very impressive <a href="http://www.arm.com/products/CPUs/families/ARM9Family.html">ARM9</a>-based board with USB, lots of RAM and flash, lots of IO, and best of all the footprint of a 40-pin DIP package (breadboard compatible!).  No wireless and relatively steep pricetag ($160).</li>
</ul>
<p><code><br />
</code></p>
<ul> <a href="http://mightyohm.com/blog/wp-content/uploads/2008/10/ti_beagle_board_top2.jpg"><img class="alignright" title="Image courtesy linuxdevices.com" src="http://mightyohm.com/blog/wp-content/uploads/2008/10/ti_beagle_board_top2-150x150.jpg" alt="" width="90" height="90" /></a></p>
<li><a href="http://www.ti.com/">TI</a>&#8216;s <a href="http://beagleboard.org/">Beagle Board</a> &#8211; Incredible featureset including DVI output and a 600MHz <a href="http://www.arm.com/products/CPUs/ARM_Cortex-A8.html">ARM Cortex</a> core.  No wireless and price is stunning for what you get, but overkill for this project ($150).  (Must keep in mind for future projects!)</li>
</ul>
<p><code><br />
</code></p>
<ul> <a href="http://www.jdoqocy.com/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16833320023%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Network%2B-%2BWireless%2BRouters-_-ASUS-_-33320023&amp;cjsku=N82E16833320023" target="_top"><img class="alignright" src="http://images10.newegg.com/ProductImageCompressAll200/33-320-023-01.jpg" border="0" alt="ASUS WL-520gU Wireless Router" width="100" height="100" /></a><br />
<img src="http://www.awltovhc.com/image-3238164-10440897" border="0" alt="" width="1" height="1" /></p>
<li>Consumer wireless routers like the <a href="http://www.asus.com/products.aspx?l1=12&amp;l2=43&amp;l3=0&amp;l4=0&amp;model=1712&amp;modelmenu=1">Asus WL-500gP v2</a> and <a href="http://www.asus.com/products.aspx?l1=12&amp;l2=43&amp;l3=0&amp;l4=0&amp;model=1671&amp;modelmenu=1">WL-520GU</a> &#8211; builtin wireless (yay!), USB, 240MHz <a href="http://www.broadcom.com/products/Wireless-LAN/802.11-Wireless-LAN-Solutions/BCM5354">Broadcom 5354</a> core, decent RAM and flash, cheap.  Newegg has the WL-520GU for an incredible <a href="http://www.tkqlhce.com/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16833320023%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Network%2B-%2BWireless%2BRouters-_-ASUS-_-33320023&amp;cjsku=N82E16833320023" target="_top">$26 after rebate</a><img src="http://www.ftjcfx.com/image-3238164-10440897" border="0" alt="" width="1" height="1" /> (normally $50).  The higher end WL-500g has more memory and flash and an integrated USB 2.0 hub (2 external ports).  Newegg has the <a href="http://www.kqzyfj.com/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16833320030%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Network%2B-%2BWireless%2BRouters-_-ASUS-_-33320030&amp;cjsku=N82E16833320030" target="_top">WL-500g Premium V2</a><img src="http://www.ftjcfx.com/image-3238164-10440897" border="0" alt="" width="1" height="1" /> for $50 after rebate (normally $80).  Both versions are a steal for what you get.</li>
</ul>
<p>Tiny, under $50 and with built-in wireless, the <a href="http://www.asus.com/products.aspx?l1=12&amp;l2=43&amp;l3=0&amp;l4=0&amp;model=1671&amp;modelmenu=1">Asus WL-520GU</a> is the clear winner for this project.  The downside?  Since this router was never intended to do anything other than, well, route, we&#8217;re going to have to crack it open, modify it, and void the warranty.  In addition, there is no tech support and we&#8217;re going to have to spend some extra time hacking around to get it to do what we want.</p>
<p>Here it is in all it&#8217;s glory:</p>
<p><a class="tt-flickr tt-flickr-Small" title="Asus WL-520GU Wireless Router" href="http://www.flickr.com/photos/mightyohm/2951133344/"><img class="alignnone" src="http://farm4.static.flickr.com/3051/2951133344_9ecc66f9f0_m.jpg" alt="Asus WL-520GU Wireless Router" width="240" height="180" /></a> <a class="tt-flickr tt-flickr-Small" title="Asus WL-520GU Wireless Router" href="http://www.flickr.com/photos/mightyohm/2951133192/"><img class="alignnone" src="http://farm4.static.flickr.com/3036/2951133192_3405735333_m.jpg" alt="Asus WL-520GU Wireless Router" width="240" height="180" /></a></p>
<p>Here&#8217;s a sneak peak of the inside:</p>
<p><a class="tt-flickr tt-flickr-Small" title="Asus WL-520GU Wireless Router" href="http://www.flickr.com/photos/mightyohm/2950280015/"><img class="alignnone" src="http://farm4.static.flickr.com/3203/2950280015_910ea93e73_m.jpg" alt="Asus WL-520GU Wireless Router" width="240" height="180" /></a><a class="tt-flickr tt-flickr-Small" title="Asus WL-520GU Wireless Router" href="http://www.flickr.com/photos/mightyohm/2951132866/"><img class="alignnone" src="http://farm4.static.flickr.com/3275/2951132866_6d8d72ebc8_m.jpg" alt="Asus WL-520GU Wireless Router" width="240" height="180" /></a></p>
<p>This router is <a href="http://wiki.openwrt.org/Hardware/Asus">supported</a> by <a href="http://openwrt.org/">OpenWRT</a>, an open source Linux distribution for small embedded devices.  Ignore the work-in-progress designation, it works, trust me!</p>
<p>Although the router lacks builtin audio, that is easily solved with an $8 <a href="http://www.jdoqocy.com/click-3238164-10440897?url=http%3A%2F%2Fwww.newegg.com%2FProduct%2FProduct.aspx%3FItem%3DN82E16812186035%26nm_mc%3DAFC-C8Junction%26cm_mmc%3DAFC-C8Junction-_-Adapters%2Band%2Bgender%2Bchangers-_-Syba-_-12186035&amp;cjsku=N82E16812186035" target="_top"> SYBA SD-CM-UAUD USB Stereo Audio Adapter</a><img src="http://www.awltovhc.com/image-3238164-10440897" border="0" alt="" width="1" height="1" />.  There have been <a href="http://wiki.openwrt.org/OpenWrtDocs/Hardware/Asus/WL520GU">reports</a> that the WL-520GU only supports USB 1.1 reliably, but USB audio doesn&#8217;t require USB 2.0 so it&#8217;s not an issue for us.  For full USB 2.0 support, look at the WL-500gP v2 instead.</p>
<p>So far we have $58 into the project ($38 if you are lucky enough to get the rebate) and we have an embedded Linux computer, a wireless interface, and an audio output.  Not bad!</p>
<p>That&#8217;s it for part two!  In <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/">part three</a> I&#8217;ll install a serial port on the router and get ready to reflash the stock firmware with OpenWrt.  At that point we&#8217;ll be able to start listening to some tunes!</p>
<p><strong>Update:</strong> I posted <a href="http://mightyohm.com/blog/2008/10/detailed-specs-for-the-asus-wl-520gu-uber-hacking-platform/">detailed specs</a> for the WL-520GU and a couple more photos <a href="http://mightyohm.com/blog/2008/10/detailed-specs-for-the-asus-wl-520gu-uber-hacking-platform/">here</a>.</p>
<p><strong>Update 2:</strong> I posted some images of the <a href="http://mightyohm.com/blog/2008/10/inside-the-syba-sd-cm-uaud-usb-stereo-audio-adapter/">$8 USB-Audio Adapter</a> I am using as well.</p>
<p><strong>Update 3: </strong><a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/">Part three</a> is now available.</p>
<p><strong>Update 4:</strong> There is a new <a href="http://mightyohm.com/forum/viewforum.php?f=2">Wifi Radio Discussion Forum</a>, hop over there to ask questions about the project or see what other people are working on!  (<em>4/12/09)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Building a Wifi Radio &#8211; Part 1, Introduction</title>
		<link>http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/</link>
		<comments>http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 01:16:01 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[Streaming Radio]]></category>
		<category><![CDATA[wifiradio]]></category>
		<category><![CDATA[Wireless]]></category>

		<guid isPermaLink="false">http://mightyohm.com/blog/?p=333</guid>
		<description><![CDATA[This article is the first of a series that will document the development of a low cost, open source wireless streaming internet radio receiver.  All construction details, including schematics, source code, and even the design process itself will be documented on this blog. Comments and (constructive) criticism are welcome. Click here to post a comment. [...]]]></description>
			<content:encoded><![CDATA[<p><em>This article is the first of a series that will document the development of a low cost, open source wireless streaming internet radio receiver.  All construction details, including schematics, source code, and even the design process itself will be documented on this blog.</em></p>
<p><em>Comments and (constructive) criticism are welcome. </em> <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/#respond"><em>Click here to post a comment.</em></a></p>
<h3>Table of Contents:</h3>
<ol>
<li><a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/">Building a Wifi Radio &#8211; Part 1, Introduction</a> (you are here)<a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/"><br />
</a></li>
<li><a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/">Building a Wifi Radio &#8211; Part 2, Choosing an Embedded Platform</a></li>
<li><a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-3-hacking-the-asus-wl-520gu/">Building a Wifi Radio &#8211; Part 3, Hacking the Asus WL-520GU</a></li>
<li><a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-4-installing-openwrt/">Building a Wifi Radio &#8211; Part 4, Installing OpenWrt</a></li>
<li><a href="http://mightyohm.com/blog/2008/11/building-a-wifi-radio-part-5-lets-make-some-noise/">Building a Wifi Radio &#8211; Part 5, Let’s Make Some Noise!</a></li>
<li><a href="http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-6-a-conversation-with-mpd/">Building a Wifi Radio &#8211; Part 6, A Conversation with Mpd</a></li>
<li><a href="http://mightyohm.com/blog/2008/12/building-a-wifi-radio-part-7-building-an-lcd-display/">Building a Wifi Radio &#8211; Part 7, Building an LCD Display</a></li>
<li><a href="http://mightyohm.com/blog/2009/02/building-a-wifi-radio-part-8-adding-a-tuning-control/">Building a Wifi Radio &#8211; Part 8, Adding a Tuning Control</a></li>
<li><a href="http://mightyohm.com/blog/2009/05/building-a-wifi-radio-part-9-a-few-odds-and-ends/">Building a Wifi Radio &#8211; Part 9, A Few Odds and Ends</a></li>
<li><a href="http://mightyohm.com/blog/2009/05/building-a-wifi-radio-part-10-building-the-box/">Building a Wifi Radio &#8211; Part 10, Building the Box</a></li>
</ol>
<h3>Some background:</h3>
<p><a href="http://en.wikipedia.org/wiki/Streaming_radio">According to Wikipedia</a>, in 1993 the first internet radio program began distribution.  At that time, radio programs were manually downloaded to be played later on the user&#8217;s home computer; the user experience was far from that of listening to a <a href="http://en.wikipedia.org/wiki/Radio">traditional</a> broadcast radio receiver.  It was not until several years later that <a href="http://en.wikipedia.org/wiki/Streaming_radio#Streaming">streaming radio</a> became common, giving birth to <a href="http://www.di.fm/">internet radio stations</a> that could be listened to much like traditional radio, but with several advantages.  Most notably, internet radio stations were (and still are for the most part) largely devoid of on-air advertising, and stations anywhere on the globe could be received by anyone with access to the internet.  Over time, improvements in audio compression (such as <a href="http://en.wikipedia.org/wiki/MP3">MP3</a>) and larger end user bandwidth improved the fidelity and reliability of internet radio.  The birth of common standards like <a href="http://www.shoutcast.com/">Shoutcast</a> made it possible to listen to many stations with a single player program, like <a href="http://www.winamp.com/">Winamp</a>.</p>
<p>Today, most music playback software supports streaming radio in some way.  <a href="http://www.apple.com/itunes/">iTunes</a> features thousands of streaming radio stations and <a href="http://en.wikipedia.org/wiki/ITunes#Internet_radio">even supports Shoutcast streams</a> so that users can easily add additional stations of their own.</p>
<p>The beautiful thing about streaming radio is the huge diversity in programming that is available.  Many college radio stations have a streaming server, like <a href="http://www.kdvs.org/listen/">KDVS</a>.  <a href="http://www.di.fm/">Digitally Imported</a> hosts many electronic and dance music streams that give the listener the choice to listen to specific genres like <a href="http://www.di.fm/mp3/ambient.pls">ambient</a> or <a href="http://www.di.fm/mp3/gabber.pls">gabber hardcore</a> <em>(whoa)</em>.  Broadcast radio usually lumps all electronic dance music into one category, much to the dismay of their listeners (who probably tuned out during the commercial break, anyway).  Gems like <a href="http://www.slayradio.org">Slay Radio</a> specialize in music you would never hear on broadcast FM, like <a href="http://en.wikipedia.org/wiki/C64">Commodore 64</a> <a href="http://remix.kwed.org/">remixes</a>.</p>
<p>In the past couple years, products have started to appear that mimic the form and function of a traditional radio, but play internet radio instead.  Good examples of these are the <a href="http://www.roku.com/products_soundbridgeradio.php">Roku SoundbridgeRadio</a> and the <a href="http://www.amazon.com/Asus-INTERNET-RADIO-AIR-WOOD/dp/B000Y9TRFQ/ref=sr_1_2?ie=UTF8&amp;s=electronics&amp;qid=1223601330&amp;sr=8-2">ASUS Internet Air</a>.  Remote speaker devices, such as the <a href="http://www.apple.com/airportexpress/">Apple Airport Express</a>, require a PC to receive and relay streaming radio but achieve a similar end result (but don&#8217;t really look much like a radio).</p>
<h3><strong>The Wifi Radio project:<br />
</strong></h3>
<p>I have been wanting to build a streaming radio for some time.  I frequently work in my garage, where I occasionally use my <a href="http://www.apple.com/macbook/">Macbook</a> to play music through a small amplifier and bookshelf speakers.  The problem is that my laptop is not always set up in the garage, and greasy fingers are not a good thing to have around a white laptop, period.  I could simply <a href="http://www.amazon.com/s?ie=UTF8&amp;tag=mozilla-20&amp;index=blended&amp;link_code=qs&amp;field-keywords=internet%20radio">buy</a> an internet radio, but I couldn&#8217;t stomach the $150-$300 price tag on most players for such a luxury.</p>
<p>So I decided to build one instead.</p>
<p>I started the design process by drafting an outline of desired features, and then breaking them down into wants and needs, while trying to keep the project scope under control.</p>
<p><em>Requirements:</em></p>
<ul>
<li>Wireless connectivity through existing Wifi network</li>
<li>Audio output (preferably 44kHz, 16 bit stereo)</li>
<li>An integrated amplifier and speaker(s)</li>
<li>Shoutcast/MP3 streaming audio decode</li>
<li>Several builtin station presets</li>
<li>A display to indicate the station and currently playing song</li>
<li>Simple user interface, using standard radio controls (volume, tune, etc)</li>
<li>110VAC operation</li>
</ul>
<p><em>Optional features:</em></p>
<ul>
<li>Line output (to connect to a receiver/amplifier)</li>
<li>Web server for configuration/management</li>
<li>Ability to play files off a USB stick or iTunes server</li>
</ul>
<p><em>Definitely<strong> won&#8217;t </strong>be a feature:</em></p>
<ul>
<li>Any kind of over-the-air radio tuner</li>
<li>Commercials</li>
<li>Pledge season</li>
<li>Morning DJ&#8217;s</li>
<li><em>&#8220;Blah, blah, blah.&#8221;</em></li>
</ul>
<p>Now that we&#8217;ve defined the project&#8230;  it&#8217;s time for a commercial break.  That&#8217;s it for part 1 of this series.  Stay tuned for <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/">part 2</a>, where I&#8217;ll talk about choosing an embedded platform for the design and why Linux is so awesome!</p>
<p><strong>Update:</strong> <a href="http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-2-choosing-an-embedded-platform/">Part two is now available, click here to see it!</a></p>
<p><strong>Update 2:</strong> There is a new <a href="http://mightyohm.com/forum/viewforum.php?f=2">Wifi Radio Discussion Forum</a>, hop over there to ask questions about the project or see what other people are working on!  (<em>4/12/09)</em></p>
<p><strong>Update 3 (6/1/09):</strong> I finally added a table of contents to the top of this post to help everyone (including me) navigate the series!<em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mightyohm.com/blog/2008/10/building-a-wifi-radio-part-1-introduction/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
<enclosure url="http://www.di.fm/mp3/ambient.pls" length="189" type="audio/x-scpls" />
<enclosure url="http://www.di.fm/mp3/gabber.pls" length="196" type="audio/x-scpls" />
		</item>
	</channel>
</rss>

