RASPBERRY PI SQUEEZEPLUG PROJECT



mirror_pi
The current craze in the hacker community now is a $35 complete computer called Raspberry Pi. The RPi was designed as an inexpensive tool to teach school kids how to write computer code. It is doing that, however it has taken the hacker community by storm.

Here’s what I did with one of my Raspberry Pi’s.

A few years back a company called Logitech created some internet radio appliances called “Squeezebox”. Since just about any computer can stream music from the internet I’m assuming having a dedicated appliance to do something you could already do on your computer wasn’t an economic boom to Logitech so they discontinued the line. The Squeezebox did make big waves in the audiophile community and they sound great hooked to your home stereo They also contained Linux which made them easily hackable, and hack they did.

Anyway, I have a Squeezebox Radio that I had big plans for. I planned to hook it directly to my home stereo, a beast of an old vacuum tube amplifier however I didn’t do my homework so well and found that the Squeezebox Radio only has a Headphone Out jack and not a proper Line Out. It works as a stand alone appliance great but lacks in sound quality when hooked to my stereo.

So I went to the internet recently to buy a Squeezebox Boom or a Squeezebox Touch and I found out they are out of production and sell for more than their original price. Ouch.

All was not lost as I had a spare Raspberry Pi laying around and one day stumbled across a project called Squeezeplug that essentially turns your Raspberry Pi into a Squeezebox. With the addition of a USB Digital to Analog Converter (DAC) you can make beautiful audiophile quality music for Walmart prices.

Here is my project in a nutshell:


pi
What you’ll need:

Raspberry Pi - $35

Cell Phone charger cable with mini usb port - $10-20. You probably already have one. It should be capable of supplying 700 mA.

HiFiMeDIY Sabre USB DAC - $45

Wireless dongle (optional) - $10

SD Card - 4 to 8 Gig, Class 10 recommended

Audio cable - 3.5mm male on one end with RCA right and left connectors on the other end. $10 and up.
1806_small

Squeezeplug - Free download

And finally you need an audio system to plug it into. It should be noted that a used Squeezebox radio costs just a little more than all this. But that’s not what this is all about and it won’t sound NEARLY as good as this.

Ok. You have all the parts, now it is time to install. I’m not going to duplicate the efforts of the Squeezeplug developer. Go to his homepage and watch his video and follow his instructions. You’ll need to download the hard float version here. Next download USB Image Tool. You’ll need it to install the Squeezeplug ISO image to the SD Card. There are other ways to do it but that is the easiest.

The author does assume your internet connection works prior to giving installation instructions. Mine did not. I had a Logitech wireless N150 dongle ($10). I recommend that while installing Squeezeplug you plug your raspberry pi into your router utilizing a wired ethernet connection. It should work just as his video does. If it does you’ll see this if you ssh in from another computer: (note the command -I issued to make sure you log in as root and you have to know your own IP address.. 10.0.2.44 is mine on my local network.

User name is:

root

Password is:

nosoup4u
Screen Shot 2013-05-16 at 2.47.50 PM

Here’s your setup login screen: (it gives you 20 seconds to stretch the screen in the terminal if you are ssh-ing in. If you don’t resize it then it won’t come up.
Screen Shot 2013-05-16 at 2.53.53 PM


If you opt to be brave and go the wireless route here’s what I had to do as the configuration for the wireless did not work for me. First hook up a monitor, keyboard, and mouse. I have a Logitech N150 dongle that I bought for $10 locally. I installed Squeezeplug and it takes you to a configuration page. Quit the configuration page and it drops you to a command prompt. Type: startx

That will start the graphical interface (think Windows). Once there click on the Start button, then “Internet” then “wpa_gui”. Set your wireless dongle up in wpa_gui.

Then logout of x just like you would a windows computer and back to the command prompt.

Now type: setup

This puts you right back where you were and you can continue following the Squeezeplug developers instruction. Make sure to expand the root filesystem on the SD card to use the whole card, and change your user password. But again. Follow his directions. No way I can improve on them here.

Now to the gotcha’s. Squeezeplug will have you install the Logitech Media Server.
Screen Shot 2013-05-16 at 2.56.04 PM

Then they will have you install the Squeezelite Media Player.

Screen Shot 2013-05-16 at 2.56.57 PM

When Installing Squeezelite is when you select your output audio device. Make sure and follow the prompts and select the HiFiMeDIY USB DAC.
Screen Shot 2013-05-16 at 6.11.33 PM

Once you do that is amends a file called /etc/default/squeezelite

I found that it did not properly amend this file and that the Squeezelite media player would not start when you booted the raspberry pi which means the whole damn thing doesn’t work.

So boot into your raspberry pi either through an ssh shell or via your attached monitor. To ssh from another computer type this command: (as I did in the example above)

ssh 10.0.2.44 -l root (note that the IP Address 10.0.2.44 is MY IP ADDRESS. Change it to reflect yours) If it gives you any beef about having ssh keys and strict checking and tough luck type the following command:

ssh-keygen -R 10.0.2.44

Screen Shot 2013-05-16 at 6.05.48 PM

(again that is MY IP ADDRESS. Change it to reflect the address of your Raspberry Pi) Then next time you ssh in it will ask you if you want to use the new keys.

Type yes and then proceed to log in normally.

Screen Shot 2013-05-16 at 6.07.55 PM

Once you do that you’re looking at a command prompt. Log in with user: root and whatever your password is. If you didn’t change it then it will still be nosoup4u

Now type the following:

nano /etc/default/squeezelite

Screen Shot 2013-05-16 at 2.59.01 PM

It will open an editor. Go all the way to the bottom with the cursor and change the line that says

-n Squeezelite -o [CARD=DEV0] [or whatever yours says]

Then change it to this: (ensure the S is not a capital S)

squeezelite -n UpSqueeze -o hw:CARD=DAC,DEV=0 -a 20:4:24_3:1 -d all=debug

Update: I bought a Nuforce Udac 2 today and confirm it works out of the box with Raspberry Pi and Squeezelite too. I used this as boot to make it work:

squeezelite -n UpSqueeze -o hw:CARD=N2,DEV=0 -d all=debug

This sets your squeezelite up. UpSqueeze is the name of the device. Name it anything you want. After -0 is your card. After -a is the buffer settings. The first two are 20 to 4. The next 24_3:1 is for 24 bit. The -d stuff is for a debug file.

Actually just add that line to /etc/rc.local and you’ll be better off. You’re really better off. Type:

nano /etc/rc.local

Then add the command line above, save and reboot.

Screen Shot 2013-05-24 at 5.27.25 AM

If you do add your stuff to /etc/rc.local be sure to put a # in front of the last three lines in this file. OR:

Save your changes by hitting CTRL + X keys and then get type “Y” when it asks you to save modified buffer.

Now type:

nano /etc/asound.conf

Screen Shot 2013-05-16 at 3.04.15 PM

Cut and paste this code in the file:

pcm.rate_convert {
        type plug
        slave {
                pcm "hw:0,0"
                rate 96000
        }
}


#pcm.!default {
#type plug
#slave.pcm "hw:0,0"
#rate 48000
#}

ctl.dmixer {
type hw
card 0
}


It’ll look like this:

Screen Shot 2013-05-16 at 3.08.07 PM

Again hit CTRL + X and then Y and then enter to save. Make sure you’re not accidentally changing the names of these files.


I got this from this website. This is not my fine work. Somebody else’s. Save this file and reboot.

If you want to be really clean you can erase the lines that have # in front of them. The author just left that there to show you what it looked like before. Adding the “#” uncomments the following line from the code.

Now go to any browser on the same network and type:

Squeezeplug:9000

Screen Shot 2013-05-16 at 3.10.50 PM

into the address bar and you should be looking at the Logitech Media Server and from there you can configure Pandora, MOG, or whatever. Play some music and enjoy.

Next up I’ll show you how to set a Samba Server up to access your home music library.

First things first. You must have some network attached storage that has a STATIC IP address. Otherwise if your computer changes IP addresses via DHCP your Samba Shares will get lost in the sauce. I recommend hooking up a hard drive to the USB port of your router. I have a Linksys E4200 which uses Tomato Firmware. That’s another story. Routers with manufacturer firmware are like stereos that haven’t been tweaked. Nuff said.

My router address is 10.0.2.1 Yours can be whatever you want it to be but be sure to make the appropriate changes in your setup.

Okay. Go to Advanced Configuration

Screen Shot 2013-05-16 at 6.35.01 PM

Now install a Samba Server

Screen Shot 2013-05-16 at 6.35.48 PM

Hit yes when it asks and it’ll install and start the server. You should see it on your network places at this point. I use a Mac. Mine looks like this.

Screen Shot 2013-05-16 at 6.37.10 PM

Now go back to the main screen and select “Media Handling”
Screen Shot 2013-05-16 at 6.38.58 PM

Configure the Media Library
Screen Shot 2013-05-16 at 6.39.27 PM

Say “Yes” Then select “Samba”.

Screen Shot 2013-05-16 at 6.40.31 PM

Enter your IP address and hit Ok.
Screen Shot 2013-05-16 at 6.41.07 PM

Path to your Samba Server is a little tricky

Screen Shot 2013-05-16 at 6.42.02 PM

Mine has the fancy name of “Unknown” Anyway gravitate to the file where your music actually is then right click and get the properties
Screen Shot 2013-05-16 at 6.42.36 PM
Screen Shot 2013-05-16 at 6.43.16 PM

See my highlighted stuff above? That’s it. Paste that in the path field.

Now use guest as the Samba User name
Screen Shot 2013-05-16 at 6.45.52 PM

No password. Just click Ok.
Screen Shot 2013-05-16 at 6.46.36 PM

Ok now your Samba account is set up. It tells you your stuff can be found at /mnt/samba
Screen Shot 2013-05-16 at 6.48.40 PM

Now go to your browser and type:

Squeezeplug:9000

in the address bar. Go to the bottom right hand corner and click on Settings.
Screen Shot 2013-05-16 at 6.50.29 PM

Go to the Media Folder and type in /mnt/samba or select it in “browse” and then hit “Rescan”.
Screen Shot 2013-05-16 at 6.51.43 PM

Restart Samba by getting back to the terminal and typing:

/etc/init.d/samba restart

if it didn’t work drop back to a terminal prompt and type

nano /etc/fstab
Screen Shot 2013-05-16 at 7.24.26 PM

Look at the last line in my /etc/fstab file below. That/’s the good one. The one just above it is messed up. Just comment it out. Restart Samba

Screen Shot 2013-05-16 at 7.25.19 PM

That’s it. Be sure to restart Samba and go back to the Logitech Media Server and do a scan again.

Your library is yours and so is Pandora and MOG and anything else out there on the internet.

And finally some extra details to make things better.

Couple more lessons I learned throughout all this.

Once you get squeezeplug installed get the latest and greatest Raspberry Pi Firmware.  It resides on the SD Card so it follows the card and doesn't actually change anything on the board.

Anyway at a command prompt run

rpi-update

Let it do its thing.  Should help if you have any stability issues.

rpi-update gets you the latest Raspberry Pi firmware. There is an experimental firmware out there that addresses audio and USB issues. I recommend you get it instead of just rpiupdate

Get to a terminal prompt and type the following three commands:

sudo apt-get install git-core

sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update

sudo BRANCH=fiq_split rpi-update



Last gotcha I had was I had two cheap wireless dongles that I was running.  Both were based on the Realtek rt2800 chipset.

I've been having nightly crashes.  After poking around on Google for a couple days I found a couple pages that basically say "Oh my God, don't use rt2800 chipset on Raspberry Pi, it works but crashes, etc, etc, etc.

Seems one of the more stable chipsets is the RT8192cu

The Edimax EW-7811Un 150 is one such wireless dongle.  I went down to the local electronics store in Japan and no Edimax here but I found a Planex GW-USEco300 that has the same chipset.

Go to a prompt and type this:

/etc/modprobe.d/8192cu.conf

You'll see nothing as it's a new file.  Paste this in and save it:

options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

Reboot.

That file turns off the power management of the wifi dongle so it doesn't sleep on you.

The last part of the command turns off usb auto suspend.

This should keep you rock solid.




More stuff added:

Conf file for wireless /etc/wpa_supplicant/wpa_supplicant.conf

This will allow you to get your wifi dongle working without hooking up a monitor and booting into X. Enter

nano /etc/wpa_supplicant/wpa_supplicant.conf

Edit the top two lines to match your network. Save, exit, restart.



ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="
Tomato24_e4200"
psk=“
xxxxxxxxxxxxxxx
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}


For some reason my Samba sharing stopped working. Don’t ask me why. But here’s what I had to do to get it going again. Mount the drive at boot from rc.local and alter the fstab entry.


Edit /etc/rc.local to mount the NAS share

mount -t cifs //unknown/SAMBA /mnt/samba

Edit /etc/fstab

//unknown/SAMBA /mnt/samba cifs guest,uid=1000,_netdev 0 0

Check the services and restart them automatically if they die

Make a file called /root/check_services

Paste this in:

/usr/bin/pgrep squeezelite || /etc/init.d/squeezelite restart

If you did the thing way up the page where you started squeezelite from /etc/rc.local then add this line instead to /root/check_services

squeezelite -n UpSqueeze -o hw:CARD=DAC,DEV=0 -a 20:4:24_3:1 -d all=debug

Save and do a:

chmod 700 /root/check_services

Then do a crontab -e

Add this:

*/15 * * * * /bin/bash /root/check_services

Save and run the cron. It will check every 15 minutes to see if squeezelite and squeezeboxserver processes are still running. If they are not they will restart them.

Now that you are (hopefully) playing music run this command while you are playing something:

cat /proc/asound/card0/pcm0p/sub0/hw_params

You should see something like this. The format line shows me in 24 bit. My rate is only 44100 on this example because I’m playing streaming radio from the internet at that rate.


root@squeezeplug:~# cat /proc/asound/card0/pcm0p/sub0/hw_params
access: MMAP_INTERLEAVED
format: S24_3LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 221
buffer_size: 884

IN THE EVENT YOU HAVE LITTLE TO NO SOUND…………………..

Drop back to a command prompt and type:

alsamixer

You should then be able to take your number keys and increase the volume output.


Linux is awesome!


Rpi_hack


Email me with questions.