Raspberry PI Radio
Raspberry PI Radio
Constructors Manual
Contents
Introduction ............................................................................................................................................ 5 Hardware ................................................................................................................................................ 7 Raspberry PI computer ....................................................................................................................... 7 The HD44780 LCD display ................................................................................................................... 7 Wiring ...................................................................................................................................................... 8 LCD Module Wiring ............................................................................................................................. 9 GPIO Hardware Notes ........................................................................................................................... 10 Using rotary encoder switches ......................................................................................................... 10 Parts List ................................................................................................................................................ 11 Construction HD44780 LCD................................................................................................................... 12 Building the LCD and pushbuttons interface board.......................................................................... 12 Construction using an Adafruit LCD plate ............................................................................................. 14 Software installation ............................................................................................................................. 15 Software download ........................................................................................................................... 15 Update the GPIO libraries ................................................................................................................. 15 Install the I2C libraries ...................................................................................................................... 16 Enable Network Time Daemon ......................................................................................................... 17 Source files ............................................................................................................................................ 18 The LCD Class .................................................................................................................................... 18 The Radio Daemon ............................................................................................................................ 18 The Adafruit Radio daemon .............................................................................................................. 18 The Daemon Class ............................................................................................................................. 18 The Radio Class ................................................................................................................................. 18 The Log class ..................................................................................................................................... 18 The RSS class ..................................................................................................................................... 19 The Translate class ............................................................................................................................ 19 LCD test programs............................................................................................................................. 19 Installing and Testing the Music Player Daemon .................................................................................. 20 Install the Music Player Daemon ...................................................................................................... 20 Configure the MPD daemon ............................................................................................................. 20 Test the Music Player Daemon ......................................................................................................... 20 Bob Rathbone |Raspberry PI Internet Radio - / 2
Configuring USB speakers instead of the analogue output .............................................................. 21 Configure the Radio daemon ................................................................................................................ 22 Disable serial interface...................................................................................................................... 22 Configure radio program log rotation............................................................................................... 22 Configure the Radio program to start automatically at boot time ................................................... 22 Operation .............................................................................................................................................. 24 Starting the program......................................................................................................................... 24 Buttons .............................................................................................................................................. 25 Mute function ................................................................................................................................... 26 Playing MP3 and WMA files .............................................................................................................. 26 Organising the music files ................................................................................................................. 26 MPD Logging ..................................................................................................................................... 26 Radio program logging ...................................................................................................................... 26 Configuration files ............................................................................................................................. 27 Displaying an RSS feed ...................................................................................................................... 27 Music Player Clients .......................................................................................................................... 27 Shutting down the radio ................................................................................................................... 27 Understanding PLS files ........................................................................................................................ 28 Installing the Web interface.................................................................................................................. 30 Install Apache .................................................................................................................................... 30 Test the Apache web browser .......................................................................................................... 30 Install the Web Browser server pages .............................................................................................. 30 Start the radio web interface ............................................................................................................ 30 Mounting a network drive .................................................................................................................... 32 Finding the IP address of the network drive ..................................................................................... 32 The CIFS mount command ................................................................................................................ 32 The NFS mount command ................................................................................................................ 33 Display the share directory ............................................................................................................... 33 Un-mounting the /share directory.................................................................................................... 33 Copy the mount command to the configuration .............................................................................. 33 Load the music library ....................................................................................................................... 33 Update the playlists for the new share ............................................................................................. 33 Disabling the share............................................................................................................................ 34 Further information .......................................................................................................................... 34 Bob Rathbone |Raspberry PI Internet Radio - / 3
Miscellaneous ....................................................................................................................................... 35 Configuring the Adafruit LCD backlight colours ................................................................................ 35 Troubleshooting .................................................................................................................................... 36 LCD screen not working .................................................................................................................... 36 The LCD displays hieroglyphics ......................................................................................................... 36 LCD backlight not working ................................................................................................................ 36 LCD only displays dark blocks on the first line .................................................................................. 36 Music Player Daemon wont start .................................................................................................... 36 The MPD may display a socket error ................................................................................................ 36 PLS files wont load using MPC ......................................................................................................... 36 The MPD daemon complains about the avahi daemon ................................................................... 37 Radio daemon doesnt start or hangs ............................................................................................... 37 Stream decode problems .................................................................................................................. 38 Cannot mount remote network drive ............................................................................................... 38 Configuring a wireless adaptor ............................................................................................................. 39 Install the wireless adapter ............................................................................................................... 39 Configure the adaptor....................................................................................................................... 39 Explanation of the network fields ..................................................................................................... 40 Operating the wireless interface ...................................................................................................... 40 Troubleshooting the wireless adapter .............................................................................................. 41 Licences ................................................................................................................................................. 42 Technical support.................................................................................................................................. 42 Acknowledgements............................................................................................................................... 42 Glossary ................................................................................................................................................. 43
Introduction
This manual describes how to create an Internet Radio using the Raspberry PI educational computer. The source and basic construction details are available from the following web site: http://www.bobrathbone.com/raspberrypi_radio.htm This manual provides a more detailed overview of construction and software installation than provided by the web site. It contains instructions for building the radio using either the HDD44780 LCD directly wired to the Raspberry PI GPIO pins or using an Adafruit RGB-backlit LCD plate for Raspberry PI. The features of the radio are: Raspberry PI running standard Music Player Daemon (MPD) Three different LCDs are supported o 2 x 16 character LCD with HD44780 controller o 4 x 20 character LCD with HD44780 controller o Adafruit LCD plate with 5 push buttons (I2C interface) Clock display or IP address display (for web interface) Five push button operation (Menu, Volume Up, Down, Channel Up, Down) Artist and track scrolling search function Plays music from a USB stick or from a Network drive (NAS) Menu option to display a single RSS news feed Web interface using snoopy and others Plays Radio streams or MP3 and WMA tracks Output either using the analogue adio jack or a USB speaker set. Controlled by an Object Orientated Python application Support for European character sets (Limited by LCD capabilities)
Various examples of the Raspberry PI internet radio were built using this design.
This classic style Internet Radio is built into a wooden case. This is using two four inch speakers and audio amplifier stripped out from an old pair of PC speakers. It has five buttons in all. The centre square button is the menu selection. For alternative ideas see both the next pages and the constructors page at http://www.bobrathbone.com/pi_radio_constructor s.htm
Example of the Internet Radio with a four line by twenty character compatible HD4478 LCD display. The transparent case was an old cream cracker box.
Example of the PI internet radio using an Adafruit RGB-backlit LCD plate for Raspberry PI from AdaFruit industries.
Example of a fun radio built using this design and Lego from Alan Broad (United Kingdom). This really puts the fun back into computing.
The prototype system. This consists of a Raspberry PI connected to an LCD display mounted in a black plastic case and two rocker switches and a centre push button for the menu. Using rocker switches however means that the mute function wont work with this design as it isnt possible to press the volume up and down buttons simultaneously.
Hardware
The principle hardware required to build the radio consists of the following components: A Raspberry PI computer An HD44780 LCD display or an Adafruit RGB-backlit LCD plate for the Raspberry PI LCD and switches interface board
Raspberry PI computer
The Raspberry Pi is a credit-card-sized single-board computer developed in the United Kingdom by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools.
More information on the Raspberry PI computer may be found here: http://en.wikipedia.org/wiki/Raspberry_Pi If you are new to the Raspberry PI try the following beginners guide. http://elinux.org/RPi_Beginners
Wiring
The following table shows the GPIO LCD interface wiring. If using the Adafruit LCD plate then skip this section (See Construction using an Adafruit LCD plate on page 14). This wiring works for both revisions 1 and 2 boards of the Raspberry PI however revision 2 boards require a small code change in the lcd_class.py code. Refer to RPI Low level Peripherals page at elinux.org for more information on Raspberry PI low level peripheral wiring.
Pin 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Description 3V3 5V GPIO 0 Reserved GPIO1 GND GPIO 4 GPIO 14 Reserved GPIO 15 GPIO 17 GPIO 18 GPIO 27(21) Reserved GPIO 22 GPIO 23 Reserved GPIO 24 GPIO 10 Reserved GPIO 9 GPIO 25 GPIO 11 GPIO 8 Reserved GPIO 7 ModMyPi Board 3V3 5V SDA0 Reserved SCL0 0V GPIO 7 UART TX Reserved UART RX GPIO 0 GPIO 1 GPIO 2 Reserved GPIO 3 GPIO 4 Reserved GPIO 5 SPI MOSI Reserved SPI MOSO GPIO 6 SPI SCLK SPIO CE0 Reserved SPIO CE1 4 RS 6 E 14 Data 7 12 13 Data 5 Data 6 11 Data 4 1,3,5,16 GND 2,15 5V LCD Function
Switches COMMON
MENU
Pin 13 is GPIO27 on Rev 2 boards and GPIO21 on Rev 1 boards Wire one side of the switches to the 3.3V pin. Wire the other side of each switch to the GPIO pin as shown in the last column of the above table via a 1K resistor. Also wire this same side of the switch to the 0V pin via a 10K resistor. See Figure 2 on page 9. For more information about wiring GPIO interface lines see the following link for some excellent GPIO wiring examples from Circuit Lab: https://www.circuitlab.com/browse/by-tag/gpio Bob Rathbone |Raspberry PI Internet Radio - Wiring 8
Note: The circuit will work without the 1K resistor but is advised for extra protection for the GPIO input.
Usually the device requires 8 data lines to provide data to Bits 0-7. However the device can be set to a 4 bit mode which allows you to send data in two chunks (or nibbles) of 4 bits. This is great as it reduces the number of GPIO connections you require when interfacing with your Raspberry Pi.
10
Parts List
The following table shows the parts list for the Raspberry PI Internet Radio. This list is for the version using the HD44780 LCD directly connected to the GPIO pins. If using the Adafruit five button LCD Plate then dont order the parts marked with an asterix (*)
Qty 1 Part Raspberry Pi Computer Clear Raspberry Case 4GByte SD Card Wooden Radio Case Raspbian Wheezy OS Four inch loudspeakers Four inch loudspeaker grills Stereo Amplifier (3 to 5 watt) Transformer for amplifier LCD HD44780 2 x 16 Display * ModMyPi Slice of Pi * Round push buttons * Square push button * 26 way ribbon cable 10K resistors * 1K resistors * Four port USB hub External power supply for USB hub (1200 mA) 26 way PCB mount male connector Mains cable Double pole mains switch with neon Male 2 pin PCB mount connectors Female 4 pin PCB connectors Female 2 pin PCB connectors 16 pin male in-line PCB mount connector Stereo jack plug socket Wall mount Ethernet socket Shrink wrap Thin wire for PCB wiring Supplier Farnell Element 14 RS Components Any PC or Photographic supplier A good friend of mine Raspberry Pi foundation downloads From set of old PC speakers Any electronics shop From set of old PC speakers From set of old PC speakers Farnell Element 14 Ciseco PLC Any electronics shop Any electronics shop Tandy or Farnell Element 14 Tandy or Farnell Element 14 Tandy or Farnell Element 14 Any PC supplier Any PC supplier Any electronics shop Hardware shop Farnell Element 14 Any electronics shop Any electronics shop Any electronics shop Any electronics shop Any electronics shop Any do-it-self shop Any electronics shop Any electronics shop
1
1 1 1 2 2 1 1 1 1 4 1 1 5 5 1 1 1 1
1
5 2 1 1 1 1
* These components are not required if using the Adafruit LCD plate.
11
The above photo shows the components before assembly. See from back and left to right. A wooden case, mains cable, Raspberry PI in a transparent plastic case, speaker grills, 5v power supply, 4 inch speakers, 2 x 16 LCD display, four port USB hub, stereo amplifier, five push button switches, 11.5v transformer for the stereo amplifier, ribbon cable and the LCD and push buttons interface board. Not shown is the (optional) USB wireless dongle.
12
The component side of the LCD and push button shows the female connectors for five push button switches and the five 10K pull down resistors. In this construction the 1K resistors shown in Figure 2 Switch Wiring on page 7 werent used but do provide some extra protection for GPIO inputs.
The following picture shows the components mounted in the wooden case.
Shown from top left to bottom right: 5V power supply (from a standard phone charger), four port USB with a memory stick for music files, LCD and Switch interface board (You can just see one of the switches connected with a twisted green wire), stereo amplifier (volume control now just a preset) and 4 inch speakers from a set of old PC speakers, mains input (mains switch behind this), mains transformer for the amplifier, Raspberry PI in a clear plastic case and finally the headphones socket.
13
Note 1: If you are going to plug the Adafruit LCD plate directly into the GPIO header on the Raspberry PI then you dont need the above reversing plate. Just follow the construction instructions on the tutorial on the Adafruit site. Note 2: The select button on the Adafruit plate is the Menu button for the radio. Note 3: If you want to use an Adafruit display that allows setting different colours for the backlight then see section Configuring the Adafruit LCD backlight colours on page 35 for instructions on how to do this.
Bob Rathbone |Raspberry PI Internet Radio - Construction using an Adafruit LCD plate
14
Software installation
This procedure assumes that the Raspberry PI is installed with Debian Wheezy and with a working Internet Connection. There are five steps to carry out to install the software. Download and un-tar the software from the Bob Rathbone web site Update the GPIO libraries to at least version 0.5.2 or install I2C library (Adafruit plate) Install the Music Player Daemon (MPD) and Client (MPC) Create play lists for the MPD and test Configure and run the radio software
Software download
The software is contained in a compressed tar file called pi_radio.tar.gz. This can be downloaded from the following location. http://www.bobrathbone.com/pi_radio_source.htm Either download it to the PC and copy it across to the Raspberry PI or use the wget facility if there is an Internet connection on the Raspberry PI. Create a directory called /home/pi/radio. Copy the pi_radio.tar.gz to the /home/pi/radio directory or use wget to download it.
# wget http://www.bobrathbone.com/raspberrypi/source/pi_radio.tar.gz
This will unzip the following files and directory: lcd_class.py, radio4.py, radio_class.py, radio_daemon.py, radiod.py, test_lcd.py, test_ada_lcd.py, ada_radiopy, i2c_class.py, ada_lcd_class.py, playlists/ python*.deb rss/* Make sure all of the *.py files in this directory are executable with the following command: # chmod +x *.py. Dont try to run the software just yet! It has to be configured first.
15
You may delete the above deb files once the latest libraries have been installed. Note: The libraries are for Debian wheezy only. If using another OS download the correct GPIO libraries.
Enter the following commands to add SMBus support (which includes I2C) to Python:
sudo apt-get install python-smbus sudo apt-get install i2c-tools
The i2c-tools isn't strictly required, but it's a useful package since you can use it to scan for any I2C or SMBus devices connected to the Raspberry. If you know something is connected, but you don't know it's 7-bit I2C address, this library has a great little tool to help you find it:
sudo i2cdetect -y 0 (if you are using a version 1 Raspberry Pi) sudo i2cdetect -y 1 (if you are using a version 2 Raspberry Pi)
This will search /dev/i2c-0 or /dev/i2c-1 for all address, and if the Adafruit LCD Plate is correctly connected, it should show up at 0x20.
Once both of these packages have been installed, you have everything you need to get started accessing I2C and SMBus devices in Python.
16
Test that the time is synchronising OK with the ntpq peers command
# ntpq ntpq> peers
remote refid st t when poll reach delay offset jitter ============================================================================== +ns0.solcon.nl 193.79.237.14 2 u 438 512 377 20.337 -1.030 5.302 -mu.monshouwer.e 193.79.237.14 2 u 352 512 377 20.197 -1.858 0.349 *ev001.tilaa.nl 193.190.230.65 2 u 415 512 377 19.891 -0.899 0.379 +ntp.raqxs.nl 212.45.32.36 3 u 388 512 377 20.354 -1.127 0.391
ntpq> quit
However to make the NTP daemon start at boot time it needs to be enabled first. Use the updaterc.d command to enable it.
# update-rc.d ntp enable 2 3 5
This enables the NTP daemon (ntpd) for run levels 2 3 and 5.
17
Source files
The source consists of several source modules all written in Python using Object Orientated techniques. The source can be downloaded from http://www.bobrathbone.com/pi_radio_source.htm
If using the Adafruit LCD plate you can skip the above section. This class can be used for other projects using the HD44780 LCD display.
18
19
Copy an example PLS file provided with the software from the /home/pi/radio/playlists directory for example the ukblues.pls PLS file to the /var/lib/mpd/playlists directory. Do this either as user root or using sudo.
$ sudo cp /home/pi/radio/playlists/ukblues.pls /var/lib/mpd/playlists/.
This will prevent IPv6 bind errors on start-up. Change the zeroconf_enabled parameter to no
#zeroconf_enabled zeroconf_enabled "yes" "no"
This prevents avahi daemon error messages on start-up. Save the /etc/mpd.conf file when finished.
Music should now be heard from Raspberry PI. If not troubleshoot the problem before continuing. To stop the MPD daemon enter:
Bob Rathbone |Raspberry PI Internet Radio - Installing and Testing the Music Player Daemon
20
If these tests succeed you are ready to run the Radio software.
Save the file and reboot the Raspberry PI. The radio should now use the USB speakers (The analogue output is disabled). Note: Make sure that the radio is first working with the analogue output before re-configuring the above file.
Bob Rathbone |Raspberry PI Internet Radio - Installing and Testing the Music Player Daemon
21
Add the following line to the /boot/cmdline.txt file. This is the same line as above but without any references to ttyAMA0.
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
In the /etc/inittab file disable the line which re-spawns ttAMA0 by adding a hash character at the beginning.
#Spawn a getty on Raspberry Pi serial line #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
This will rotate the log files every week so prevent the SD card from eventually filling up.
22
The Radio daemon will start automatically at boot time. The above command is for the directly wired LCD. If using the Adafruit LCD plate use the following command instead to start the radio.
/home/pi/radio/ada_radio.py start
23
Operation
This section assumes that the LCD screen is working correctly, the MPD daemon is installed and tested and that there is an Internet connection available. If you are using a 4x20 LCD then substitute radiod.py for radio4.py in all of the following commands. If using the Adafruit LCD plate then substitute ada_radio.py for all of the following commands.
Where start: Start the radio program. stop: Stop the radio program. restart: Restart the radio program. status: Show the status of the radio daemon. version: Show the version number of the program If you do not see all of the above options you are running old software and should update to the latest release. Change to the /home/pi/radio directory and run the following command:
pi@raspberrypi:~$ cd /home/pi/radio/ pi@raspberrypi:~/radio$ sudo ./radiod.py start
Alternatively run as root. All commands as root user dont need sudo.
# pi@raspberrypi:~$ sudo bash # cd /home/pi/radio # ./radiod.py start
The above pid (Process ID) number will be different each time the program is run. To see what version of the software you are running:
# ./radiod.py version Version 1.16
24
Buttons
There are five buttons, four function buttons and one menu button. The Menu button changes the display mode and the functions of the left and right hand buttons as shown in the following table.
Menu button - Changes the display mode and the functions of the buttons.
Table 1 Push Button Operation
Left button
Right button
Volume Up
Volume Down
Station/Track up
Station/Track down
Volume Up
Volume Down
Volume Up Mute
Toggle mode between Radio and Music Library Cycle through Random, Consume, and Repeat
Volume Up Mute
Station/Track up
Station/Track down
Volume Up Mute
Note 1: If the /var/lib/radiod/rss file is missing or contains an invalid RSS URL then this mode is skipped.
25
Mute function
Pressing both volume buttons together will mute the radio. Press either the volume up or down switch to un-mute the radio. If you change channel or use the menu switch the radio will also be unmuted.
MPD Logging
All logging for the MPD daemon is to the /var/log/mpd/mpd.log file by default.
There are four levels of logging namely DEBUG, INFO, WARNING and ERROR. The log level is configured in the /var/lib/radiod/loglevel file. The default is INFO. If you want to increase the logging say to DEBUG carry out the following command as root user and restart the program.
# echo DEBUG > /var/lib/radiod/loglevel # ./radiod.py restart
26
Configuration files
There are some other configuration files in the /var/lib/radiod directory. These are: current_station The current radio station current_track The current music track volume The volume setting You dont normally need to change these files. They are maintained by the program so that when it starts up the program uses the last setting, for example, the volume setting.
The above is the RSS for the BBC news however any valid RSS feed may be used. If the /var/lib/radiod/rss is missing or contains an invalid RSS URL then this mode is skipped when stepping through the menu. The software is provided with a valid BBC RSS feed file in the rss directory. You can test the feed first by pasting it into your PCs web browser URL and pressing enter.
27
The PLS file must always start with the [playlist] statement. The NumberOfEntries statement must match the number of streams you have defined in the PLS file (Two in the above example). Set the Version number always to 2. There must be a Filen, Titlen and Lengthn where n is the entry number. The Filen statement is the pointer to the Radio stream URL. The Titlen statement may be any useful title you wish. The Lengthn statement is always -1 (Unlimited) for a Radio station. You can create as many playlist files as you wish. The Radio program will attempt to load all of the PLS files it finds in /var/lib/mpd/playlists directory. Please note that a bad PLS file can stop the Radio from working (MPD limitation not the Radio program). Not all radio streams are supported by MPD. If you suspect a bad playlist stop the Radio and tail the /var/log/mpd/mpd.log file and restart the Radio. Below is a typical error:
# tail -f /var/log/mpd/mpd.log May 01 08:22 : player_thread: played "http://ics2bss.omroep.nl:80/radio2-bbaac?q=/npo/aac/radio2-bb.pls&stream=ok"
The reason for the above error is that the above URL points to the PLS file. It is not the PLS file entry itself. Use wget to get the correct PLS file. Most radio stations provide a URL which points to a URL file. For example: Bob Rathbone |Raspberry PI Internet Radio - Understanding PLS files 28
# cd /tmp/ # wget http://ics2bss.omroep.nl:80/radio2-bb-aac?q=/npo/aac/radio2bb.pls&stream=ok --2013-05-01 09:52:16-http://network.absoluteradio.co.uk/core/audio/mp3/live.pls?service=vrbb Resolving network.absoluteradio.co.uk (network.absoluteradio.co.uk)... 31.186.234.209 Connecting to network.absoluteradio.co.uk (network.absoluteradio.co.uk)|31.186.234.209|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 171 [audio/x-scpls] Saving to: `live.pls?service=vrbb.1' 100%[======================================================================= =====>] 171 --.-K/s in 0s 2013-05-01 09:52:16 (2.33 MB/s) - `live.pls?service=vrbb.1' saved [171/171]
Now copy this file to the /var/lib/mpd/playlist directory (with a better name).
# cp /tmp/live.pls\?service\=vrbb /var/lib/mpd/playlists/absolute_radio.pls
Alternatively add the contents to an existing PLS file. There are a lot of resources on the Internet how to find PLS files so simply search for PLS files through the search machine of your choice.
29
Install Apache
Install Apache the web server. Make sure that the system is up to date with the following command.
# apt-get update
This will install the radio pages in the /var/www directory and the CGI scripts in /usr/lib/cgi-bin directory.
30
Now click on the Web interface tab. If the radio software is running you will see the following:
Click on any station on the list to select a station. The Radio and Music buttons select the source.
31
There is a third type of network file protocol called SMB (Server Message Block Microsoft) but is replaced by CIFS in the Raspberry PI. Your PC will be using SMB most probably. The steps to mount the network drive are as follows: 1. 2. 3. 4. 5. Find out the IP address of your network drive. Create and test the mount command using either NFS or CIFS. Copy the mount command to /var/lib/radiod/share file. In the Radio menu select Music Library as the source and press Menu again to load Update the playlists to include the files on the new share (Network drive).
This procedure assumes that you already have your Network Drive configured and working with your PC and can play music via the PC. In the examples below a Synology Network Drive was used with a volume called Volume1 with a directory called music. The IP address for the Synology Network drive used was 192.168.2.6. First stop the Radio software when creating and testing the mount command. Dont configure /etc/fstab to do the mount of the network drive. Although this is the usual way of mounting shares however the radio program needs total control of the mount and un-mount process. The general syntax for the mount command is as follows:
mount -t <type> -o option1,option2, <remote IP address and directory> <mount point>
Where: <type> is either nfs or cifs. -o option1,option2 are the mount options. <remote IP address and directory> Is the IP address and music directory path <mount point> This will always be /share for this program
32
The share directory is created when you first run the Radio program (v1.6 onwards) so there is no need to create it. If the command was successful you should be able to display the music from the network drive. Go to section called Display the share directory on page 33.
A few things to note here; the NFS mount command uses the volume name (Volume1), The CIFS mount command doesnt. The second thing is that the IP address and remote directory are separated by a colon (:). If the command was successful you should be able to display the music from the network drive.
Feb 1 12:07 . May 15 10:48 .. Feb 1 12:05 Adriano Celentano Feb 1 12:07 Afric Simone Feb 1 12:07 Al Martino Feb 1 12:05 America Feb 1 12:06 Aphrodite's Child
cleared and updated from all the files loaded in the /var/lib/mpd/music directory including the new share. This can take some time ( Several minutes) if the Network Drive contains a large amount of music files. During this process the Radio program will ignore any button depressions and you will see the first Initialising (Library) and then Updating (Library).
Further information
For your information if you display the /var/lib/mpd/music directory you will see two soft links to the /share and /media directories for the network drive and USB stick respectively.
# ls -la /var/lib/mpd/music/ total 8 drwxr-xr-x 2 root root 4096 drwxr-xr-x 4 mpd audio 4096 lrwxrwxrwx 1 root root 6 lrwxrwxrwx 1 root root 6
19 16 19 19
These links are created automatically by the Radio program. If these are missing they can be recreated with the ln s command.
# cd /var/lib/mpd/music # ln -s /media # ln -s /share
This shouldnt normally be necessary as the links are created by the program when it creates the media and share mount points.
34
Miscellaneous
Configuring the Adafruit LCD backlight colours
Some Adafruit displays such as the rgb-negative Adafruit LCD allow changing the colour of the backlight. This isnt configurable at the moment and can only be achieved by modifying the code in the ada_radio.py program file. You can change the backlight colour with the lcd.backlight(lcd.color) command where color is RED, YELLOW, BLUE etc. The colours are defined in the ada_lcd_class.py file. Modify the test_ada_lcd.py program first as shown below to test the colours you want to use.
while True: if lcd.buttonPressed(lcd.MENU): print("Menu button") lcd.backlight(lcd.RED) lcd.line2("Menu button") elif lcd.buttonPressed(lcd.LEFT): print("Left button") lcd.backlight(lcd.BLUE) lcd.line2("Left button") elif lcd.buttonPressed(lcd.RIGHT): print("Right button") lcd.backlight(lcd.GREEN) lcd.line2("Right button") elif lcd.buttonPressed(lcd.UP): print("Up button") lcd.line2("Up button") elif lcd.buttonPressed(lcd.DOWN): print("Down button") lcd.backlight(lcd.YELLOW) lcd.line2("Down button")
Now modify the main loop in ada_radio.py" (line 99 onwards) to use the colours. For example if you want to change the background colour to RED during shutdown then modify the code as shown below.
# Shutdown command issued if display_mode == radio.MODE_SHUTDOWN: lcd.backlight(lcd.RED)
Note: Always use the American spelling color in all commands and not colour.
35
Troubleshooting
LCD screen not working
Check that the wiring conforms to the wiring list on page 8. Make sure that pin 3 is grounded (0V) to give maximum contrast. Run the lcd_test.py program to see if the LCD displays anything. This runs independently of any other software and can be used stand alone.
If this message is seen in the MPD log file this is simply because IP version 6 (IPv6) isnt installed so the message doesnt affect operation of the MPD. To prevent it from happening configure the bind_to_address parameter in the /etc/mpd.conf file to any as explained in the section called Configure the MPD daemon on page 20.
This is due to permissions on the files by not copying them to /var/lib/mpd/playlists directory using sudo or as root user. This can be seen by using the ls la command to display the permiisions.
pi@raspberrypi:~$ ls -la /var/lib/mpd/playlists/ukblues.pls -rw-r----- 1 root root 105 Oct 5 10:44 /var/lib/mpd/playlists/ukblues.pls
The -rw-r----- string means the other users (including pi) cannot read this file. You may need to learn about file permissions if you dont already know. The problem can be solved by setting the permissions for other to read:
pi@p raspberrypi:~$ sudo chmod o+r /var/lib/mpd/playlists/*.pls pi@ raspberrypi:~$ ls -la /var/lib/mpd/playlists/ukblues.pls -rw-r--r-- 1 root root 105 Oct 5 10:44 /var/lib/mpd/playlists/ukblues.pls
This should solve the problem as the rw-r--r-- string means the other users (including pi) can read the file.
Change the zeroconf_enabled parameter in the /etc/mpd.conf file to no as explained in the section called Configure the MPD daemon on page 20. The avahi daemon is used to configure systems without a network connection but is not enabled by default. It is not required for this design.
Also check that the GPIO libraries are at least version 0.5.2a as shown in the section called Update the GPIO libraries on page 15.
37
This is due to an invalid URL (In the above example this is http://173.244.194.212:8078) in one of the PLS files. Locate the offending URL in the play list file in the /var/lib/mpd/playlists directory. Either correct the radio stream URL or remove it all together. Also check that the file URL is not the pointer to the PLS file (See section Understanding PLS files on page 28.
38
The above shows a Ralink (Tenda) wireless adaptor but this will vary depending on the adapter that has been installed.
You should not need to change this file. The file to be amended is shown on the line beginning with wpa-roam and is /etc/wpa_supplicant/wpa_supplicant.conf. Edit this file. It will only contain a couple of lines.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1
Substitute YOUR_SSID and YOUR_KEY with the actual SSID and key for your wireless router. The above configuration is for a router using WPA encryption. If your router is using the older WEP encryption then you will need to adapt the configuration to use WEP. See next section. Bob Rathbone |Raspberry PI Internet Radio - Configuring a wireless adaptor 39
your wifi (SSID) name A value of 1 means broadcast and value of 2 means a hidden SSID (Normally enter a value of 1) Your WIFI password Your choice of RSN or WPA. RSN is WP2 and WPA is WPA1. (most configurations are RSN) Either WPA-PSK or WPA-EAP (pre-shared or enterprise respectively) Either CCMP or TKIP ( WPA2 or WPA1 respectively) OPEN option is required for WPA and WPA2 (other option, SHARED & LEAP)
The only problem with the above configuration is that the psk key is in plain text and can be read by anyone who has access to the Raspberry PI. It is possible to increase security by generating a socalled passphrase with the wpa_passphrase command. For example if your ssid is mywlan and the WIFI password is abcdef1234 then use the following command to generate the passphrase.
# wpa_passphrase mywlan abcdef1234 network={ ssid="mywlan" #psk="abcdef1234" psk=53a566e0ccf03ec40b46e6ef4fc48b836e428fb0fd5e0df95187ba96e60ce7ce }
Copy and paste the passphrase into the psk parameter into the /etc/wpa_supplicant/wpa_supplicant.conf file. Do not include any quotes around it.
and
root@raspberrypi:/home/pi# ifdown wlan0
To see what SSIDs are available run the iwlist command as shown in the following example:
root@raspberrypi:/home/pi# iwlist wlan0 scanning | grep ESSID ESSID:"mywlan" ESSID:"VGV751926F4B9" ESSID:"prime" ESSID:"Sitecom6A212C"
To display the IP address of the Wireless Adapter run the ip addr command:
root@raspberrypi:/home/pi# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
40
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether b8:27:eb:fc:46:15 brd ff:ff:ff:ff:ff:ff inet 192.168.2.11/24 brd 192.168.2.255 scope global eth0 3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether c8:3a:35:c8:64:cd brd ff:ff:ff:ff:ff:ff inet 192.168.2.13/24 brd 192.168.2.255 scope global wlan0
This is due to an incorrect /etc/wpa_supplicant/wpa_supplicant.conf file. The problem is due to an incorrect configuration. For example a space after the ssid= directive as shown below.
network={ ssid= "homelan" scan_ssid=1 psk="d762c954df" proto=RSN key_mgmt=WPA-PSK pairwise=CCMP auth_alg=OPEN }
Solution: Correct the error and run the ifup wlan0 command. Problem: The following is seen:
root@raspberrypi:/home/pi# ifup wlan0 ifup: interface wlan0 already configured
Solution: This isnt actually an error. Just run the ifdown wlan0 command and retry the ifup wlan0 command. It should then work.
41
Licences
The software and documentation for this project is released under the GNU General Public Licence. The GNU General Public License (GNU GPL or GPL) is the most widely used free software license, which guarantees end users (individuals, organizations, companies) the freedoms to use, study, share (copy), and modify the software. Software that ensures that these rights are retained is called free software. The license was originally written by Richard Stallman of the Free Software Foundation (FSF) for the GNU project. The GPL grants the recipients of a computer program the rights of the Free Software Definition and uses copyleft to ensure the freedoms are preserved whenever the work is distributed, even when the work is changed or added to. The GPL is a copyleft license, which means that derived works can only be distributed under the same license terms. This is in distinction to permissive free software licenses, of which the BSD licenses are the standard examples. GPL was the first copyleft license for general use. See http://www.gnu.org/licenses/#GPL for further information on the GNU General Public License.
Technical support
Technical support is on a voluntary basis by e-mail only at bob@bobrathbone.com. Before asking for support, please first consult the troubleshooting section on page 36. Be sure to provide the following information: What have you built (Adafruit or normal LCD) and which program you are running. A clear description of the fault. Is anything displayed on the LCD. Switch on DEBUG logging as described on page 26, run the program and include the log file.
Acknowledgements
My thanks to Matt Hawkins for the original LCD screen driver routines. It made the job of writing the lcd_class.py much easier. Also to Adafruit Industries for their excellent LCD plate and I2C code. See http://www.adafruit.com. To contributors such as Alan Broad who supplied photos of the Lego example of the radio plus code contribution. Also to Mike Whittaker for his contribution on how to drive the USB speaker set.
42
Glossary
I2C CGI CIFS Industry standard serial interface (Philips) using data and clock signals Common Gate Interface Executable Server Side scripts Common Internet File System
DHCP Dynamic Host Configuration Protocol GPIO LCD MPC NFS MPD PID PLS RSS SSID URL USB WEP WPA General Purpose IO (On the Raspberry PI) Liquid Crystal Display Command line client for MPD Network File System Music Player Daemon Process ID MPEG Playlist File (as used by Winamp) Really Simple Syndication Web feed usually containing news items An SSID is the public name of a wireless network. Universal Resource Locator ( A link to a Web page for example) Universal Serial Bus Wired Equivalent Privacy (WEP) is a security algorithm considered less secure than WPA Wi-Fi Protected Access (WPA) and Wi-Fi Protected Access II (WPA2)
43