Wednesday
May152013

Weekend Project: PiSwitch using the Raspberry PiFace

Here at Polyideas we're big fans of power efficiency- we're convinced it's the next big thing.  Some people may hear 'efficiency' and think going without- but more and more these days there are clever solutions to saving electricity.  In Southern California, this means saving money!
 
This project focuses on a common area of power usage in the home- the humble PC.  Sure, laptops are more efficient- but sometimes only a PC will do.  Many of us leave a PC on just in case we need to log onto it remotely.  If we're not using it, it's just sitting there using electricity- and usually quite a bit of it.  The most efficient desktop PCs still use around 35-45 watts when idling.  Gaming PCs with big video cards can easily top 200 watts!  
 
The PiSwitch solution lets you hook up a Raspberry Pi to your PC to control your power and reset buttons.  The Raspberry Pi only uses about 1 watt of power when on, so it's more economical to leave it on all the time.  In this article, I'll walk through how to set up the Raspberry Pi from start to finish to do this.  The list of parts is available below, most of which you can get from SparkFun. All Sparkfun parts are on the wishlist here.
This project makes use of the very nifty Raspberry PiFace, which takes all the guesswork out of interfacing switches with the Raspberry Pi.  In this article, we'll do the following:
  • Format the SD card with Raspbian Wheezy
  • Install the files needed for the PiFace
  • Setup our scripts
  • Install the Raspberry Pi in our PC case
  • Test it out
If you're familiar with our last Raspberry Pi article on setting up the MiniDLNA server, these steps may be familiar- this time we're using Raspbian Wheezy (http://www.raspberrypi.org/downloads).  Other than that, these next few steps cover imaging your SD card using a PC.  We're a pretty PC-friendly shop, so here we go!  These steps work the same on Windows 7 & 8.  MAKE SURE YOUR SD CARD IS EMPTY- we will be erasing it in the next few steps!
Right-click on the new hard drive and select 'Format'.  Be very careful you've got the right drive!
If the memory card is under 20GB, select FAT32.  Others might work, but I have done this with FAT32.  That's ok, because it's going to get overwritten.  We need the SDHC card to be blank though- don't skip this step.
 
Go ahead and check the box 'Quick Format' and click the 'Format' button.
Now that we have a blank SDHC card, we can write the Wheezy image onto it!
 
Download a copy of the Raspbian Wheezy 2013-02-09 image from here.  This may take a little bit since it's over 800 megabytes, so we'll come back to this step in a bit.  When it's done downloading, it's a zip file that must be extracted to get the file named "2013-02-09-wheezy-raspbian.img". 
Download the Win32DiskImager application here and extract the zip file to a folder.  Inside the folder of files you just extracted, you will find Win32DiskImager.exe, go ahead and run it.  If you're on Windows 7 or 8 and have User Account Control (UAC) turned on, it may prompt you for administrator access- this is ok since the application needs access to your disk devices to write the image.  Now that we have it running, it looks something like the window below:
 
Click the blue file icon and navigate to your 2013-02-09-wheezy-raspbian.img file.  If you try to do it with the original zip file you downloaded without extracting it, this process won't work.  Under 'Device' you'll see that the application has selected a removable disk letter for you automatically.  Make sure this is the right drive letter for your SDHC memory card!  Again, if you select the wrong drive letter you can erase a drive on your PC.  Once you're sure, click the "Write" button.
 
When it's done you'll get a dialog box that tells you it's been successful.  This means you have successfully written the Wheezy image to the SDHC card.  Go ahead and unplug the SDHC USB adapter from your computer and insert it into the Raspberry Pi.  Note the angled end of the memory card and how it lines up with the Raspberry Pi when you slide it in.
 
 
Go ahead and hook up all the connections to the Raspberry Pi.  We're going to need to connect a monitor to it for the first time while we setup networking and some other steps.  Go ahead and plug in an HDMI monitor, a USB keyboard and an ethernet cable.  You may be able to use WiFi for this project, but our PC case is all metal and the wireless signals will have trouble- so this article will focus on wired networking.
 
Go ahead and connect the power, which will power on the Raspberry Pi.  Run through the local menu that you get the first time to change your locale and keyboard layout among others.  The UK keyboard is the default, and if you leave it in place you will have trouble using the '#' key.  Make sure to go through each line in the initial setup.  If you forget to do something like change your keyboard layout or expand the SD card, you can come back to the first setup menu by running 'raspi-config' from the command prompt.
 
After you've setup the initial settings, we still have a few steps to perform.  We need to setup networking, update the Raspberry Pi and install the files for the PiFace.  First, let's set a static IP address for the Raspberry Pi.  This will make it easier for us to remote into the Raspberry Pi from other machines, and it's required if we're going to open a port on our router to get to the Raspberry Pi.  Let's
start by running the command:
 
sudo nano
/etc/network/interfaces
 
We need to comment out a couple lines on the configuration- when we add a '#' to the beginning of a line, it tells Linux to skip that line- this lets us disable certain lines without deleting them.  
The file starts out looking like this:
 
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
 
When we're done, we've added our static IP, network mask and default gateway. Don't forget to make sure your Raspberry Pi's static IP doesn't overlap with ones given out by your router.  My final network setup looks like this:
 
auto lo

iface lo inet loopback
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.123.123
netmask 255.255.255.0
gateway 192.168.123.1

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
 
The easiest thing to do now is save the file with a Ctrl-O then quit with a Ctrl-X.  Now reboot with the command:
 
sudo reboot
 
When the Raspberry Pi comes back, go ahead and login.  Try pinging www.yahoo.com with the command:
 
 
You should see ping times in milliseconds if your network setup is good.  If not, you'll need to grab a networking friend to help you get your networking squared away.  Assuming we're good here- let's update some hardware settings our Raspberry Pi.  We do this with the following commands:
 
sudo nano /etc/modprobe.d/raspi-blacklist.conf
 
When it's open, insert a # at the start of the line that says 'blacklist spi-bcm2708'.  The line should now look like this:
 
#blacklist spi-bcm2708
 
Now save the file with a Ctrl-O then quit with a Ctrl-X.  Now when the Raspberry Pi reboots it will find the PiFace automatically.  From the shell we can run this command to turn it on manually:
sudo modprobe spi-bcm2708
Now that our PiFace hardware is setup, let's update the software to use it.  Run the following commands to update your Raspberry Pi:
 
sudo apt-get update
sudo apt-get upgrade
 
If you are prompted, press 'Y' or enter to agree to the updates.  The second command will take a little while, so it's a good time to grab a cup of coffee.  When these commands have completed, run the following command:
 
 
This step installs the files needed for your PiFace.  When it's done, shut down with Raspberry Pi with the command:
 
sudo halt
 
After all the green and yellow lights are off on your Raspberry Pi, go ahead and unplug all the connections.  We need to drill the holes into the mounting plate so we can install the Raspberry Pi inside our PC case.  You can see in the photo I have a wifi adapter on my Raspberry Pi to make sure I have room to add the wifi later if I want.  
 
 
I used a small jewelers screwdriver (link) to scratch two small holes on the bracket to line up with the mounting holes on my Pi.  Next, I drilled the holes- the holes need to be slightly larger than the thread in the screws.
 
 
After the holes have been drilled, I add in my spacers and spacer screws, if you look close you can see them in the pic below:
 
 
After we install the spacers, we can mount the Pi to the spacers, then the PiFace to the Pi.  It should look something like this:
 
 
Now let's take our motherboard wires and clip the ends with the switches off.  Clip close to the switches to make sure we have as much length of wire as possible- it needs to be able to reach our motherboard after we install the Pi.  After we clip the switches off the wires, let's strip 1/8" of wire off the ends we just clipped.  Attach the wire pair for the reset switch to terminals closest to jumper #3 on the PiFace.
 
Make sure the wires go in the center connector and the 'NO' connector.  This means 'Normally Open' and means the switch is off unless you turn on the relay. 
 
Attach the wire pair for the power switch to terminals remaining relay terminals, again using the center connector and the 'NO' connector.
 
 
When we're done, our setup should look like this:
 
 
Now that we've connected the wires, let's power on our Raspberry Pi to test the setup before we install it in the PC.  Reconnect everything on the Raspberry Pi and login.  Let's create our script files for power on and reset of the PC.  Let's start with the reset.  Run the command:
 
nano reset.py
 
The Nano text editor opens, type or paste in this:
 
#!/usr/bin/python
 
from time import sleep
import piface.pfio as pfio
pfio.init()
pfio.digital_write(0,1) #turn on
sleep(0.1)
pfio.digital_write(0,0) #turn off
exit()
 
Now save the file with a Ctrl-O then quit with a Ctrl-X.  Now we need to mark the file as executable to make it easier to run.  Run the command:
 
chmod +x reset.py
 
Now you should be able to run this command and hear the PiFace quickly click one of its relays, just like a person hitting the reset switch on a PC when you run the command:
 
./reset.py
 
If you're looking at the PiFace you can see an LED flash on as well.  Run it as many times as you like to test.  When you're done, let's make the power script by running the command:
 
nano power.py
 
The Nano text editor opens, type or paste in this:
 
#!/usr/bin/python

from time import sleep
import piface.pfio as pfio
pfio.init()
pfio.digital_write(1,1) #turn on
sleep(0.1)
pfio.digital_write(1,0) #turn off
exit()
 
Now save the file with a Ctrl-O then quit with a Ctrl-X.  Now we need to mark the file as executable to make it easier to run.  Run the command:
 
chmod +x power.py
 
Now you should be able to run this command and hear the PiFace quickly click one of its relays, just like a person hitting the power switch on a PC when you run the command:
 
./power.py
 
If both of these run fine, then you're ready to power off and install the PiSwitch in your PC case.  If you get errors, you need to recheck our PiFace hardware setup from the commands to make sure the hardware has been found.  Also, remember that these Python scripts are sensitive to formatting, so extra tabs or spaces will break the scripts.  Go ahead and shut down the Pi with the command:
 
sudo halt
 
Unplug the power, usb keyboard and network connections and install the PiSwitch in the PC case.  You can see how I ran the power and network cables through the back of my PC case here:
 
 
Unplug your PC case's connectors for your power and reset wires from the PC motherboard and replace them with the PiSwitch ones.  If you want to be fancy you can splice the PiSwitch ones without unplugging the existing case ones, but for us we'll just wire the PiSwitch directly to the motherboard. You can see this in the photo below:
 
 
When we're all wired up, go ahead and power on the Raspberry Pi, making sure the power and network cables are plugged in.  Then from your PC you can remote into your Pi using SSH (we like Putty).  Go ahead and test the power on script by running:
 
./power.sh
 
You should see your PC power on!  If you don't, try running:
 
./reset.sh
 
If that works, it means you have your power and reset wires mixed up.  Now you're ready to remotely turn your PC on and off remotely!  We'd like to thank our sponsor Sparkfun for their support.

 

Monday
Apr222013

2 Axis Solar Tracker, Powered by Arduino

My nearly year-long project starting with a design concept and finishing with a prototype is almost done.  There's more tweaking to do, but I'm happy to announce this week I'll be posting several articles on the building of my Solar Outdoor Robot here on Polyideas.  I'll be posting four different articles, each focusing on a different part of the build.  These four articles will be:

 

  1. Hardware protoyping, including materials selection and working with the different iterations of the design.
  2. Electronics prototyping, including methods used, part selection and more.
  3. Discussion and release of the source.
  4. Wrap up and overview of the whole project.

 

I'll be sharing more to come, but here's a teaser of the hardware prototype!

You can also see me here on Adafruit's Show & Tell back in October with a very early prototype.  

Thursday
Apr112013

Cool New Pixel Qi Display

I'm looking forward to playing with one of these in the coming weeks.  The display has a normal mode with the backlight on that works great indoors- but can also be easily read in direct sunlight! 

Monday
Apr012013

Efficiency is the new Gigahertz

Not too long ago, Intel and AMD sparred in the user arena over faster and faster clock speeds.  Even the ubiquitous Pentium D was Intel's dual core answer to the AMD dual core Athlon.  The trouble was that the Pentium D was really just two discreet CPUs on one die- and it was horribly inefficient in terms of both heat dissipation and energy consumption.

Fast forward 10 years:

Los Alamos National Labs is getting ready to decommission on of their newer, record-breaking computation clusters.  Why? It costs to much to operate. That is, it uses too much electricity.

Like it or not, California and much of the southwestern US is showing the trend that will set the pace for the next 10 years- power efficiency.  It's not just about using less electricity- that's conservation (and sometimes good in its own right), efficiency is about losing as little heat as possible for each CPU operation.

For example:

 

  • A Raspberry Pi uses about 2 watts of power when really chugging along. In Southern California that costs about $5 a year. So assuming you spent nothing else, you're talking about $40 for the first year (counting the purchase of the Pi) and $5 each year after that.  
  • Now compare an AMD E-350 system, one of the lowest power AMD offerings- It costs about $115 to buy and $70 per year to operate. That makes it a whopping $185 in the first year, or $465 over five years- compared to $60 for 5 years on the Pi.
  • Now compare the lastest Xeon CPU, which costs about $350 for a basic motherboard and the CPU.  It costs about $125 a year to operate. That's $975 over 5 years.

Now ask yourself- surely there are things that require a Xeon CPU- but are your needs really with the clock speed king... the Xeon?  Most people, most of the time simply don't need that much power, but more importantly, once people have a choice they won't want to pay that much for what they feel they need.

 

 

 

Saturday
Mar302013

Afternoon Project: Raspberry Pi DLNA & File Server

In the spirit of a nice afternoon project, I'd encourage you to use what's laying around if it's close to the specs here.  But if you're going to buy all these parts ahead of time like I do, hopefully it will help to use the product links below.  While I love Amazon, please try and support great suppliers like Adafruit, who have a great forum community, customer service and tutorial section!
  • Raspberry Pi Model B (Although a Model A might work, it wasn't used for this build.) Get it from Adafruit or Amazon.
  • 5VDC USB Power Supply (For some reason, I had 2 of these in the bottom of a box, but this one would work great too.)
  • 16GB SDHC Memory Card (I used this one, but feel free to use whatever you have laying around- this tutorial might not work with smaller density cards, so beware.)
  • HDMI Monitor and HDMI Cable (I happen to have this one, but anyone should do.)
  • 3TB External Hard Drive (I used this one.)
  • A USB to SDHC Adapter (Like this one.)
  • USB Keyboard
I'm guessing you already have a Windows PC nearby, you'll need that too.  For software, you'll need:
From your Windows PC:
There are other ways to do this with Linux and OSX, but our tinker machines a PCs, so I thought it would be helpful to give everyone the rundown on a PC.
First, we need to setup the external drive.  Since all my cool tunes from Archive.org are on another Windows PC, and most of the machines in my house are also Windows, it's important that I can plug the big storage drive into a Windows machine and copy stuff whenever I need to. Do the following:
  • Assuming you're starting with a brand new drive, find it in My Computer and format it. To do this, right-click on the new hard drive and select 'Format'.  Be very careful you've got the right drive, otherwise you're going to delete important stuff.  If it's not a new drive, move everything off before formatting it.  !!Formatting the drive will erase everything on the drive!!
  • When you format it, select the filesystem type 'ExFAT'.  Exfat is cool because it's supported a little better than NTFS on Linux, and it's fully supported on Windows 7&8 too- even for very large drives (unlike FAT or FAT32).
  • Go ahead and check the box 'Quick Format' and click the 'Format' button.
  • Once it's formatted with ExFAT, go ahead and copy stuff onto it- in my case it's my Music from Archive.org.
  • Assuming you've got quite a bit of stuff to copy, go ahead and step away while the copy job is running.  If you don't have anything to copy, unplug the drive and set it aside- we'll come back to it later.
Next up is setting up the SDHC card to image Occidentalis onto it.  Go ahead and plug the SDHC card into the USB adapter, then plug that into the PC.  Note what drive comes up, because we're going to format it too.
  • Again, I'm assuming you've got a brand new memory card to play with- if you still have stuff on it, move it off now- we're going to format this card too, and that erases everything on the memory card.
  • Right-click on the new hard drive and select 'Format'.  Be very careful you've got the right drive!
  • If the memory card is under 20GB, select FAT32.  Others might work, but I have done this with FAT32.  That's ok, because it's going to get overwritten.  We need the SDHC card to be blank though- don't skip this step.
  • Go ahead and check the box 'Quick Format' and click the 'Format' button.
Now that we have a blank SDHC card, we can write the Occidentalis v0.2 image onto it!
Download a copy of the Occidentalis v0.2 image from Adafruit here.  This may take a little bit since it's over 800 megabytes, so we'll come back to this step in a bit.  When it's done downloading, it's a zip file that must be extracted to get the file named "Occidentalis_v02.img".  
Download the Win32DiskImager application here and extract the zip file to a folder.  Inside the folder of files you just extracted, you will find Win32DiskImager.exe, go ahead and run it.  If you're on Windows 7 or 8 and have User Account Control (UAC) turned on, it may prompt you for administrator access- this is ok since the application needs access to your disk devices to write the image.  Now that we have it running, it looks something like the window below:
Click the blue file icon and navigate to your Occidentalis file, and it should be named "Occidentalis_v02.img".  If you try to do it with the original zip file you downloaded without extracting it, this process won't work.  Under 'Device' you'll see that the application has selected a removable disk letter for you automatically.  Make sure this is the right drive letter for your SDHC memory card!  Again, if you select the wrong drive letter you can erase a drive on your PC.  Once you're sure, click the "Write" button.
When it's done you'll get a dialog box that tells you it's been successful.  This means you have successfully written the Occidentalis image to the SDHC card.  Go ahead and unplug the SDHC USB adapter from your computer and insert it into the Raspberry Pi.  Note the angled end of the memory card and how it lines up with the Raspberry Pi when you slide it in.
Raspberry Pi Memory Card photo
Go ahead and hook up all the connections to the Raspberry Pi.  This includes:
  • Plug in the SDHC card, in case you haven't done so already.
  • Plug in the HDMI cable to your monitor and the other end to your Raspberry Pi.
  • Plug in the network cable to the Raspberry Pi.
  • Plug in the USB keyboard
  • Last, plug in the power.

 

It will take a minute to boot up, but you'll find out that this $40 computer runs pretty fast!
When the Pi boots up for the first time, you'll be greeted by the Raspi-config menu.  We'll do a couple things here that will help with the operation of the Pi.
  • First, use the arrow keys to select 'expand_rootfs' and hit Enter.  It will only take a second and give you a message something like, "Root partition has been resized. The filesystem will be enlarged upon the next reboot." 
  • Hit Enter again.
  • It will take a second or two to load, but it will load up a list of locales.  Scroll down and find "en_GB.UTF-8 UTF-8" and hit the spacebar to clear the * next to it.  I'm not in England and don't have one of their keyboards, so I don't want this locale.  Scroll down and find, "en_US.UTF-8 UTF-8" and hit the spacebar to select it.  You should see a * next to it.  Use the Tab button to get to the 'Ok' button and close this menu. 
  • When prompted, select 'en_US.UTF-8' for the default system locale and hit Enter.  It will take 20-30 seconds to update the system.
  • Arrow down to 'ssh' and hit enter. When prompted, select 'Enable' and hit Enter. Hit Enter again after it tells you it's been enabled.
  • Arrow down to 'change_pass' and hit Enter.  Enter your new password, then again to confirm.  Your username is pi.
  • Arrow down to 'Finish' and hit Enter.  When prompted for the reboot, select 'Yes'.
  • When it reboots it will resize the partitions to use the whole SDHC card. This only takes about 1 minute.
  • Login with your new password. Remember, your username is 'pi' and the password is whatever you set it before rebooting.
Nano Primer
We're going to be using 'nano' to edit our files.  Old-schoolers may prefer emacs or vi, but for the casual user nano is the way to go.  You'll see 'sudo' at the beginning of each command, which is required since each of these files can only be opened by a root account. Sudo will run whatever you type in after it as root.  Commands in nano are easy- they are at the bottom of the screen, but the easy ones are Ctrl-O to save the file, Ctrl-X to exit.
Networking
This step is optional, but if you are going to use the Pi as a file server then you want a static IP for a number of reasons. We're going to change from a dynamic IP that uses 'DHCP' (Dynamic Host Configuration Protocol) to a static one. DHCP addresses are usually handed out by your router- we're going to assign one that never changes.  We're going to use 192.168.26.6. First, let's fire up nano again, this time to edit the /etc/network/interfaces file.  Go ahead and run the command:
sudo nano /etc/network/interfaces
See the line that says:
iface eth0 inet dhcp
We're going to put a '#' in front of it so that Linux will skip it. Edit it so it looks like this:
#iface eth0 inet dhcp
Now below it, add these lines:
iface eth0 inet static
address 192.168.26.7
netmask 255.255.255.0
gateway 192.168.26.1
You can leave all the other lines alone.
Hit Ctrl-O to save it, then Ctrl-X to quit.
We now need to reboot to make the changes take effect.  At the console type:
sudo reboot
After it's done rebooting, go ahead and log in again.  From here on out you can use Putty as an SSH client to connect to your Pi from a windows machine.  The commands will be the same, but to use Putty simply run it, type in the IP address of your Pi, then click 'Connect'. The first time you connect it will ask you to confirm the RSA thumbprint- it's ok just to click yes.
Next up, let's make sure all of our packages are up to date.  We'll be using the system many Linux systems enjoy called 'apt-get'.  This is a system for downloading and installing packages.  Since many add-on applications for Linux require other applications, apt-get does a great job of automatically getting these dependencies for you.
This command will update the package list that apt-get has.
sudo apt-get update
Now that we've updated apt-get, let's go ahead and upgrade all of our packages.  
Press 'y' when prompted.
sudo apt-get upgrade

This will take a while- go grab a cup of coffee while you wait, this could take at least an hour.
Now let's install the packages we need:
First we'll add support for the ExFAT filesystem. This is easy, thanks to our friend apt-get:
sudo apt-get install exfat-fuse
Pretty easy! Now let's plug in your external drive to the Raspberry Pi.  You can run the command 'dmesg' and it will spit out a bunch of stuff- but if you look, you can see the last 20 or so lines it can see your hard drive you just plugged in.  Look at the screenshot below, and you can see if found my 'U3 Cruzer Micro' and you can see it's been identified as disk [sda1].  Now we're ready to mount it, but before we do we need to make a folder for it to mount to. Let's call it 'flash4gb' and let's put it under the /media folder.  To do that, run this command:
sudo mkdir /media/flash4gb
Now let's mount the drive:
sudo mount /dev/sda1 /media/flash4gb -t exfat
Let's check and make sure it's there:
df -h

Ok, if we look at the screen above we can see it's mounted and it sees all 3.8GB of the USB drive.  Remember, this process is the same for the 3TB drive in the example- my 3TB is still copying files over so it will be a little while.  We'll keep going with the flash drive.
If we left it as it is now, the drive will be uncleanly dismounted (forced) when the Raspberry Pi shuts down, and it won't be mounted automatically either.  Let's modify the fstab file that keeps track of what gets mounted on boot.  If you're going to remove the drive all the time, you don't want it in fstab- but we will want it in there.  Run the command:
sudo nano /etc/fstab

Add a new line at the bottom that reads (each set of text is separated by a tab):
/dev/sda1       /media/flash4gb       exfat   defaults        0       1
Again, Ctrl-O to save, Ctrl-X to exit.
Let's install Samba, the network suite that lets our Raspberry Pi look like a Windows file server. Run the
apt-get command as shown:
sudo apt-get install samba
When prompted, hit Enter to approve the packages and let apt-get do all the work.  Now it's time for some very, very basic Samba configuration.  Samba is a beast, and can take lots of effort to get it just right.  For this tutorial, we're only going to setup basic sharing so we can see our media files.  To do that, we need to edit the Samba configuration file:
sudo nano /etc/samba/smb.conf
Scroll down about 300 lines, and you'll see a section called [printers].  We're not going to add any printers, but you can look at that section and how it's laid out.  We're going to add a new section below it, but leave the printers stuff there.  Add the following lines:
[Archive.org-Music]
        comment = Archive.org Music Share
        path = /media/flash4gb/music
        guest ok = yes
        browseable = yes
        create mask = 0600
        directory mask = 0700
Again, press Ctrl-O to save, Ctrl-X to exit.
Now let's restart Samba to read our new configuration.
sudo service samba restart
Now if we navigate to the Raspberry Pi from the network, we can see the files are there from the flash drive and happy. 
Now we're ready for minidlna, a lightweight and simple DLNA server that will stream to network devices, specifically my TV. First, let's install minidlna with apt-get, confirm when it asks with a press of the Enter key.
sudo apt-get install minidlna
Now that it's installed, we need to setup the folder in minidlna.conf
sudo nano /etc/minidlna.conf
We're going to add a line that looks like this:
media_dir=A,/media/flash4gb/music
We will also comment out the line that looks like this:
media_dir=/var/lib/minidlna
Now it should look like this:
#media_dir=/var/lib/minidlna
We're telling minidlna which folders have media to stream, and the A stands for audio.  If you had one with video, we'd change it to a V. Hit Ctrl-O to save, Ctrl-X to exit.
Now we need to launch minidlna the first time with a -R to get it to build the library.  Run this command:
sudo minidlna -R
Depending on the size of your library, this could take several minutes.  For me, I only have a few albums here, so it indexed right away. Finally, let's restart minidlna one more time:
sudo service minidlna restart
Go check your local DLNA client.  For me, it's the TV.
Now that we have it running, it's time to tinker with it!  As you can probably tell from the first photo, the cables weigh more than the Raspberry Pi itself.  I needed something to anchor it to, and I figured that new 3TB hard drive would do the trick.  So I carefully drilled a few holes...
Then I mounted a couple generic standoff screws to it.  I carefully screwed on the standoffs- the plastic is very soft and I did not want to strip the threads.  Then I mounted the Raspberry Pi using a couple small PC screws.
After that, I wired it all back up.
And that's it! Please remember to check the parts list for links to pick up the parts, and a big shout-out to Adafruit!
Follow up: I shared this project on Adafruit's Show and Tell this last weekend.  You can see it on YouTube here: