I just reached a milestone with another Raspberry Pi project – a network music player.
The main aim was to provide access to my extensive digital music collection on my file server, in a form my oldish (but decent) stereo can digest. Access to other music would be a bonus. I intended to control the player through a web interface.
Mopidy seems to be the thing for the job, and it adds support for a bunch of music services, as well as access to some free web-radio stations. On top of that, some kind person has even bundled a pre-configured and ready to go version of mopidy for the Rasberry Pi in the form of PiMusicBox.
It turns out that “out of the box”, there are a few problems. The Pi itself has less than stellar audio output. I can hear distortion (apparently from the power supply), and there are clicks and worse yet, gaps when I play files. To solve these problem, I bought a Wolfson audio card.
The PiMusicBox project, would handily provide all my needs. However, it turns out that it is distributed in the form of a standard Raspbian image with the mopidy software and setup baked in. While this is great for inexperienced users to get going fast, it uses a kernel that does not support the Wolfson audio card, and the Wolfson drivers are not integrated into the upstream kernel. However, they are available in source code, or there are pre-compiled images of the kernel out there. Wolfson distribute their own complete modified Rasbian image for use with their card, which of course does not include the nifty PiMusicBox software.
- Download PiMusicBox image, copy to SD card.
- Build recent, Wolfson capable kernel and copy to SD card.
- Configure PiMusicBox (mopidy) software.
I should have started by starting the downloads of software – I could assemble my gear while that takes place.
However, I assembled the case – which sort of required inserting the Pi as I went. So I disassembled the case, and seated the Wolfson audio card on top of my Pi B rev 2. You must use a rev 2 Pi, since the Wolfson uses the P5 pads on the Pi, which are only found on the rev 2 boards – either A or B (but not B+).
I then assembled the case around my Pi-Wolfson sandwich. It fit really nicely, with the case milled to accept the edges of both boards. I tested the Pi with an existing Raspbian SD, and it worked fine – although of course there was no Wolfson audio.
Prepare the OS Image
Meanwhile, I dd’ed an image of the PiMusicBox software onto a 2GB SD I had lying around. I didn’t need local storage for music, as I had it all on a central server in our house (an arrangement which Apple’s iTunes software does not care for).
I then tested this, and was able to play some music on the standard (built in) Pi audio Line Out. Now for the Wolfson.
Cross compiling a new kernel.
I used a this page to cross-compile a 3.12 kernel with built in support for my Wolfson Audio Card. I then copied the kernel and modules onto the Pi’s SD card.
Initially, the Pi crashed on boot as it was (by default) loading the modules for the HifiBerry DAC, which appears to be incompatible (also uses i2s bus) with the Wolfson. I removed the modules from the /etc/modules file, and added a blacklist file for them, and the Pi booted fine.
So – now I have a PiMusicBox with Wolfson support. So far, so good. But it is not yet tested or configured to do anything. Once the Pi booted, I looked on my router’s DHCP Client list for it’s IP address so I could connect, using a web browser.
To do detailed configuration, I wanted to ssh into the box, so first I had to enable ssh using the musicbox interface under settings. While I was at it, I checked off the box that would automatically expand my filesystem to fill the SD card on next boot. Then I could connect with a terminal. The next thing I wanted was an editor (for those config files), so I installed vim (
# apt-get update; apt-get upgrade; apt-get install vim). Other folks may find nano adequate for their needs.
The first thing was to get sound output working from the Wolfson. I ran
# aplay -L to see the setup of sound devices under alsa. My device (snd_rpi_wsp) was listed as 0. I modified my
/etc/asound.conf to point the default output to the Wolfson, and that was it.
I happen to subscribe to Google Play Music, so I wanted to configure that service on the PiMusicBox. One “gotcha” I discovered about the config files, is that although the
/etc/mopidy/mopidy.conf file has “” (quoted empty strings) as place holders for values like user-name and password, the conf file does not work if you quote your strings for answers to these questions. In other words, don’t put
"firstname.lastname@example.org" – just plain
email@example.com is what will work. I used the “Android Device Id” app from Google Play on my phone to get the deviceid required – which was called the “Google Service Framework ID” in the Android tool.
As mentioned earlier, our household’s music is on a network server. It happens also to be a Linux box. Although PiMusicBox comes with instructions to connect to a Samba server, I prefer to use NFS when both ends support it – I imagine it is more efficient. Poking around the PiMusicBox distribution, I discovered that it’s web server finds music in sub-directories under
/music. There is already a directory
/music/Network there. I created another subdirectory
/music/Network/gemini named after my music file server. I tested the idea with
mount 192.168.2.100:/home/export/data/music /music/Network/gemini. After restarting mopidy
/etc/init.d/mopidy restart, firing up a browser on a PC let me browse my music files and play them. Then a quick edit of the
/etc/fstab file and I could make my change permanent:
192.168.2.100:/home/export/data/music /music/Network/gemini nfs defaults,soft,ro 0 1
For Phase two of this project, I intend to mount a nice blue 16×2 LCD panel, which will allow it to show the artist and song title playing, and subsequently an IR receiver for direct player control, for which I will write a simple interface (probably using python). Then the PiMusicBox can be a stand alone player.
My wife would like me to integrate SiriusXM play capability into the project as well. I think it would be possible using a mopidy extension, which I will have to research. As a starting point, she is having fun building Google playlists to listen to in the meantime.