Pi Radio Redesign

I’ve redesigned my internet radio project – now it features an amplifier with 12v 2A power supply, which is split off to a 5v UBEC to power the Pi via its GPIO pins. The amplifier powers the speakers so the only USB connections are the DAC and wifi dongle.

The sound is much louder and there is no hum or whine like before – I think that was a ground loop or antenna issue with all the USB cables and hub.

I’ve got to solder a little daughterboard together to tidy up the power splitter (shown on breadboard in the photo) and replace the wires on the speakers, as they are so brittle one has already fallen off. I’ve also got to add a pushbutton and voltage divider for controlling the play/pause/stop, probably on the same board.

I also am now using a i2c backpack for my LCD, so only need a set of 4 dupont cables instead of a dozen or more cables, potentiometer etc. I wrote a simplified version of the pi-libs library and made some minor changes to my main pi-radio script here.

As I had lost the SDcard image of my previous installation, I had to start all of the configuration from scratch, so made sure to note everything down this time!

1. Install dependencies:

dpkg -i python3-rpio_0.10.1_armhf.deb python-rpio_0.10.1_armhf.deb
apt-get install mpd mpc autofs

2. Edit /etc/mpd.conf

music_directory "/mnt/data2/music/sorted"
bind_to_address "any"
auto_update "yes"
zeroconf_enabled "no"
audio_output {
	type		"alsa"
	name		"DAC"
	device		"hw:0,0"	# optional
	format		"44100:16:2"	# optional
	mixer_device	"default"	# optional
	#mixer_control	"PCM"		# optional
	#mixer_index	"0"		# optional
}

3. Create MPD database:

mpc update

4. Comment out/add these lines in /etc/modprobe.d/alsa-base.conf to make the DAC the default device with lower latency:

#options snd-usb-audio index=-2
options snd-usb-audio nrpacks=1

5. Comment out these lines in /etc/modprobe.d/raspi-blacklist.conf to stop blacklisting the I2C/SPI modules:

#blacklist spi-bcm2708
#blacklist i2c-bcm2708

6. Add these lines to /etc/modules to load the I2C kernel modules on boot:

i2c-dev
i2c-bcm2708

7. Setup autofs to automatically mount the NFS4 fileserver:

echo 'data2 -fstype=nfs4,hard,timeo=60,ro,rsize=32768,wsize=32768 vader:/data2' > /etc/auto.nfs
echo '/mnt /etc/auto.nfs --timeout=60 --ghost' > /etc/auto.master

8. Copy everything into place and setup the init script to run on boot:

cp pi-radio /etc/init.d/
cp radio.py pylcd2.py /usr/local/bin/pi-radio
cp pylcd2.py /usr/local/bin/
cd /usr/local/bin/
chmod 755 pi-radio pylcd2.py
update-rc.d pi-radio defaults
update-rc.d nfs-common enable
update-rc.d rpcbind enable

Update: I’ve soldered/heatshrinked everything together and it works wonderfully! I didn’t use a resistor divider for the pushbutton, I just connected it to 3.3v, GND and GPIO24 using dupont cables and a pullup resistor, which actually makes it nicely modular. I could add another button by making another board in the same way and linking 3.3v/GND via headers like here.

I’ve got to gluegun some of the connectors to give some strain relief and then look into mounting everything in a case. At the moment everything but the LCD and button fit in the box I bought.

Update 2: I’ve switched to 3 buttons now (uses 3 GPIO pins plus 3.3v/GND) so we have play/pause, skip track, stop/shutdown. I noticed that the speakers sound much better when placed on a wooden table, so I think I’ll have to look for an old wooden subwoofer or speaker box I can gut and screw everything inside.

Pi Radio (again?)

I’m thinking of getting back to my Raspberry Pi internet radio project again. A few weeks ago I found that the pulsing from the wifi card was caused by a ground loop problem with the USB hub, as I got the exact same problem on the BeagleBoneBlack.

So I’ve bought a Lepai TA-2020A+ amplifier and 12V 2A PSU to power it. I plan on making a little board to tap off 5V 1A via a 7805 to power the Pi. Therefore I won’t need a powered USB hub, as I’ll only have the wifi dongle and USB DAC plugged into the two onboard USB ports and the speakers will be powered by the amp, not USB. And I still manage to keep it to one mains plug.

It also means I can get rid of some cabling and the little volume/power board into the speakers. I may need a bigger box, and I wonder about the heat coming off the 7805. I may screw everything into a wooden baseboard perhaps too.

Update: I’ve decided to ditch the 7805 idea as I’ll need a huge heatsink to dissipate a potential 7-14W, so I’ve bought a UBEC and a DC-DC step-down regulator to try.

Internet Radio Project Part 3

I’ve updated the python code having now migrated to RPIO for the GPIO control as its interrupt and debouncing setup is more complete as of v0.10.1 than GPIO 0.5.0a, and should soon make it into the Raspbian repositories.

So now you can find the code, including init script and Fritzing breadboard file, here

Functionality-wise it now does:

  • Display of band+track or radio station on LCD whilst playing, NTP date+time whilst stopped (may add RSS feed)
  • Button pauses/plays when pressed or stops playback and switches to clock mode when held down for a second, playback can be resumed with another press
  • MPD runs locally and fetches MP3’s and radio playlists over NFSv4 from fileserver, should also work for local files on sdcard or usb drive
  • LCD also reflects the status from external MPC clients like gmpc or MPDroid
  • Volume control is handled via hardware knob or software
  • Speakers can be powered off independently of the RPi

Next I’ve got to get some perspex for a case and glue things in place. In the meantime I’ve got to decide whether to purchase a Model-A or a second Model-B, and also think about switching to veroboard and put the button/LCD on wires instead of mounted directly on the breadboard.

Update: I received my RT5370-based wifi dongle today and whilst it works it suffers from the same “pulsing” noise out of the speakers as the RTL8188CUS.

See also photo gallery and video

Internet Radio Project Part 2

I’ve started to receive my parts and have cleaned up my music collection using Beets, well I say cleaned up, I’ve actually got about half of it nicely sorted and half of it is just a bunch of random MP3’s or rips of old “Best Of” CD’s from Woolworths circa 1990! I’ve installed MPC and MPD, setup autofs to mount the NFSv4 fileserver, and got playback working from the 3.5mm jack by running:

amixer cset numid=3 1

Or set it back to HDMI using:

amixer cset numid=3 0

I sent one set of USB speakers back and got a new set that are much better, albeit larger, the sound from the 3.5mm jack is incredibly quiet though, so I look forward to receiving my DAC.

I’m not a big fan of how complex it is to manage MPC via the commandline – like having to add directories or URL’s before playing them, and switching between playing MP3’s and radios is too much hassle (stop MP3, clear playlist, add URL, play radio) and the Gtk+/Qt4 GUI’s seem like overkill, MPDroid is pretty good as a basic remote control; so I will still probably be writing my own basic web frontend or looking at the existing ones. Essentially I need the following capabilities:

  • Play a directory of MP3’s (and therefore select it from a list)
  • Play an internet radio URL (selected from a predefined list stored in a textfile which I can manually edit over SSH, no need for a fancy GUI)
  • Stop playback (this could double as Play if playback is already stopped and vice versa)
  • Skip to next track
  • Display info on LCD

I don’t really need to control the volume, I could just use the speaker knobs. So really only five basic functions, probably a lot more complexity under the hood though.

The parts list so far is:

Plus the breadboard, 8Gb SDcard and electronic components I’ve already got, comes to about £35 so far (plus either £29.95 for a Model B or £18.88 for a Model A) still well under half the price of a SqueezeBox or MusicPal.

Update: if I do write a web interface, I don’t think I’ll be doing it in PHP, I’ve just looked at the latest PHP5 docs and it seems to have turned into Java with all the “public static class extends…” crap. I might use it as an excuse to try mod_wsgi in Python. I may possibly write a little client in PyQt although it seems that still has the licensing bullshit and is a bit dead, plus when I’ve used it before the Python wrapper seemed so much like C++ and un-Pythonic you might as well use C++, so maybe I’ll have a go at PyGObject for Gnome3 as I’ve not tried that since PyGtk for Gnome2.

Update 2: I’ve been thinking about the client, and I’d actually like to be able to use any of the multitude of clients available, as well as possibly my own, but be able to drive the LCD from them all rather than just mine. So I’m going to have to write some sort of daemon to monitor MPD, probably running mpc current once a second or so to update the LCD.

If I go with hardware buttons for previous/next, then I can make those send a message to the daemon to do an instant update rather than wait a second. This chap seems to have come to the same conclusion. I don’t believe MPD has any kind of notification system like a DBus interface or anything that could be used, as that would be nicer than timed polling in a loop.

I’ve pretty much decided not to do a web client as I don’t want the extra load on the Pi, in case I go for a Model-A

Internet Radio Project Part 1

I’m planning to make an internet radio using my Raspberry Pi.

First off I plan to control it entirely using a web interface which I guess I’ll write. The popular alternative is to use MPD with one of its cli/web/Android clients. I don’t fancy all of the bloat of XBMC.

Eventually I may add an LCD display and a couple of GPIO buttons at least for play and skip. Edit: I’m really considering this now as I could do with an alarm clock that uses NTP, I could even get it to turn the display off at night until a GPIO button is pressed (which could double as a snooze button). I’ve bought an incredibly cheap (God bless ebay China!) HD44780 LCD module and header pins, jees I hope I can find my soldering iron!

I plan to be able to use internet radio stations as well as playing MP3 files from the NFS server and local storage on the SD card or USB stick.

I’ve bought a wifi dongle and USB soundcard as apparently the built-in 3.5mm line out is pathetic and suffers from popping. It will all be powered by a 7-port USB hub that I have a couple of already for my Pi.

Speakers will be the complicated part – I could go the easy route and get some USB-powered speakers which could be powered from the same hub, or I could use some old PC speakers and a DC-DC power adaptor to convert whatever the speakers use (12V?) to 5V for the Pi, thus still only using one mains plug. Edit: I’ve decided to go for these cheap’n’cheerful USB speakers which I’ll canabalise. Edit: the speakers are going back, they emit a lot of static when not in use – even on my laptop/desktop machines. I also noticed that the Pi’s 3.5mm jack does indeed suffer from popping and not being very loud.

Then finally I need to find a case to put it all in.

I’m going to get the system initially setup using my Model-B, but am thinking that eventually I could use a cheaper Model-A (and a smaller SD card) as I don’t need ethernet or 2 USB ports, or case. I wonder how well Debian+MPD+nginx would run in 256Mb though…..

So far the current cost is £22.19 for speakers, LCD, DAC, 802.11n dongle and 0.1″ header pins. That doesn’t include the Pi (£18.88 for Model-A) and some sort of case, and I already have the USB hub (about £4) and various USB cables, resistors/pots, GPIO cables, breadboard etc. Not bad considering a Logitech radio would be £130+ and not half as tweakable.