Copyright 2009-2012 by djg. All Rights Reserved.

Wonky Gibbon Ramblings


Raspberry Pi Wireless Radio – Part 1

Posted on December 27, 2012 by danny

As with many such posts, this one is primarily a reminder to myself, should I need to repeat my steps at a later date. However, I hope they are of use to someone also as it was a number of days work.

You will need one raspberry pi and a wireless USB adapter based on the Realtek RTL8188CUS chipset such as the Edimax EW-7811Un micro-usb adapter (cheap as chips and available from Amazon).

Basic Setup

Download the Arch Linux ARM install (because it is very lightweight and boots in under 10 seconds), burn to an SD card and plugin to the Pi as per the instructions on the download page here.

Boot it up. If you don’t have a screen and usb keyboard available just plug it into a wired network. ssh is enabled by default so you can connect using Putty immediately, instead.

Follow the update instructions here (http://elinux.org/ArchLinux_Install_Guide) to bring it up to the most recent distribution.
Early on it talks about rc.conf which doesn’t exist in this distribution, there’s probably an alternative but as I didn’t need to change timezones, I wasn’t concerned.
The command pacman-key –init, does take A LONG time (like 10 minutes with no onscreeen feedback).

Wireless Networking

Plug in the Edimax EW-7811Un micro wireless USB adapter and reboot. Support for the Realtek RTL8188CUS chipset this is based on is built into the current distributions of Arch Linux for the Pi.
Install the netcfg package so that wireless can be configured from the command line

 # pacman -S netcfg

Then follow these instructions to configure wireless: https://wiki.archlinux.org/index.php/Netcfg
Use the example wireless-wpa script as the starting point.
After issuing this instruction in that post: # netcfg mynetwork you will see this error nl80211: ‘nl80211’ generic netlink not found. This isn’t actually a problem, this post describes why https://bbs.archlinux.org/viewtopic.php?pid=940669
To ensure wireless is restarted after a reboot of the Pi, the following command in that post must be executed

# systemctl enable netcfg@myprofile

Reboot and check that you can putty to the Pi over wifi.

In the event, that the wireless hardware doesn’t initialise fast enough (can happen), you may get an error like ‘wlan0 does not exist’. See the entry in this post https://wiki.archlinux.org/index.php/Netcfg_Troubleshooting to resolve.

You may find that a few days after doing this, the IP lease for the Pi expires on the router causing it to assign a new IP address to it. This can cause the Pi to no longer be able to connect to the router because it’s own expectation of what the IP lease should be, aren’t being met. This post https://bbs.archlinux.org/viewtopic.php?id=120230 should troubleshoot this.

Install and Configure Media Player

Now install mpd & mpc:

# pacman -S mpd mpc alsa-utils

Sound itself needs enabling at boot up. To do this you need to create a script in the directory called /etc/modules-load.d called snd_bcm2835.conf which looks like this:

# Load snd_bcm2835 at boot
snd_bcm2835

You also need to install initscripts:

# pacman -S initscripts

A lot of the challenge is in getting mpd configured correctly, when stuff doesn’t work, it’s usually due to this file not being setup quite right. Also the errors reported to the command prompt are often less than helpful so don’t forget to check the mpd.log file, sometimes that actually provides useful help. In general it is recommended you don’t run it as root but rather as a user with less all-encompassing rights.

Here’s my /etc/mpd.conf file:

music_directory		"~/music"
playlist_directory "~/mpd/playlists"
db_file "~/mpd/mpd.db"
log_file "~/mpd/mpd.log"
pid_file "~/mpd/mpd.pid"
state_file "~/mpd/mpdstate"
user "wonkygibbon"
bind_to_address		"127.0.0.1"
port				"6600"
input {
        plugin "curl"
}
audio_output {
	type		"alsa"
	name		"My ALSA Device"
	device		"hw:0,0"	# optional
}

The default input plugin is called “curl” and can be used to pick up streaming audio over the web.

For this to work, I needed to create the various files and directories that these point at. Hence, login as your user (in my case wonkygibbon), then do the following:

$ mkdir music
$ mkdir mpd
$ cd mpd
$ mkdir playlists
$ touch mpd.log mpd.pid mpdstate

Finally, start mpd, connect to a radio stream, and play it:

$ mpd
$ mpc add http://80.13.146.243:8000/
$ mpc play

The IP address is that of one of my favourite french stations – replace with whatever you want to listen to.

If you wish to test using mp3 files – you can copy them to the Pi using WinSCP (provides an ftp type interface from windows to the Pi using ssh – meaning you don’t need the Pi to be running an ftp server).

They need to be placed in the “music” folder you created earlier. Then update mpd’s music database using:

$ mpc update

Thanks primarily to the following sites as well as others to numerous to mention:
http://miro.oorganica.com/raspberry-pi-mpd/
https://wiki.archlinux.org/index.php/Music_Player_Daemon#Starting_mpd_as_a_user
http://crunchbang.org/forums/viewtopic.php?pid=182574
https://wiki.archlinux.org/index.php/Netcfg_Troubleshooting
https://bbs.archlinux.org/viewtopic.php?id=120230
Part 2 if/when it follows will focus on how to to add external switches to select channels and the bits of scripting required to respond to them.

Leave a Reply




↑ Top