Raspberry Pi Internet Radio: Bob Rathbone Computer Consultancy
Raspberry Pi Internet Radio: Bob Rathbone Computer Consultancy
Constructors Manual
Version 6.9
Contents
Tables
Table 1 Display Type options ................................................................................................................ 15
Table 2 User interface options .............................................................................................................. 15
Table 3 Radio wiring conflicts ............................................................................................................... 18
Table 4 Controls and LCD wiring 26 pin version ................................................................................... 19
Table 5 Radio and DAC devices 40 pin wiring ....................................................................................... 20
Table 6 LCD module wiring for 26 and 40 pin Raspberry Pi's ............................................................... 23
Table 7 Parts list (LCD versions) ............................................................................................................ 28
Table 8 Remote Control Activity LED .................................................................................................... 39
Table 9 Adafruit backlit RGB display wiring .......................................................................................... 53
Table 10 PulseAudio installation options .............................................................................................. 69
Table 11 IR Sensor Pin outs ................................................................................................................... 92
Table 12 Remote Control Key names and functions ............................................................................. 94
Table 13 WiFi network configuration ................................................................................................... 97
Table 14 Push Button Operation......................................................................................................... 124
Table 15 Rotary Encoder Knob Operation .......................................................................................... 125
Table 16 Graphic screen keyboard command .................................................................................... 133
Table 17 Common MPC commands .................................................................................................... 140
Table 18 Example playlists .................................................................................................................. 140
Table 19 Playlist files and directories.................................................................................................. 141
Table 20 Display classes ...................................................................................................................... 205
Table 21 Sound card Device Tree overlays ......................................................................................... 230
Table 22 UDP messages ...................................................................................................................... 231
Table 23 40-PinPush-buttons/Rotary encoder Wiring ........................................................................ 232
Table 24 26-PinPush-buttons/Rotary encoder Wiring ........................................................................ 232
Table 25 IQaudIO Cosmic Controller Wiring ....................................................................................... 232
Table 26 Pimoroni Pirate radio (pHat BEAT) Wiring ........................................................................... 233
Table 27 40-PinPush-buttons/Rotary encoder Wiring ........................................................................ 233
Table 28 Status LED indications .......................................................................................................... 233
Table 29 Rotary menu switch ............................................................................................................. 233
The source and basic construction details are available from the following
web site: https://bobrathbone.com/raspberrypi/pi_internet_radio.html
Media Player
Play your favourite MP3 tracks from a USB stick, SD card or from a
NAS (Network Attached Storage).
Airplay Receiver
This design allows the Raspberry Pi to act as an Airplay receiver.
Music tracks can be played from your Apple or Android mobile
phone or tablet.
Spotify Receiver
Turn your Raspberry Pi into a Spotify Receiver. This requires a
Spotify Premium account.
Shoutcast
Shoutcast radio is a streaming audio which is used by some 50,000
Internet Radio stations across the internet. This radio software
allows multiple playlist creation from Shoutcast radio stations by
genre or country which can selected through the radio menus.
Icecast
Icecast is free streaming software which supports a variety of
streams such as MP3 and OGG. Icecast can optionally be installed
on the Raspberry Pi and allows the currently playing station or track
to be streamed around the local network or out to the Internet.
Web interface
The radio software includes an optional web interface powered by
Apache. This allows stations and playlists to be selected via web
pages on your PC, mobile telephone or tablet.
Quick links
Topic Page(s) Topic Page(s)
Adafruit 32 PiFace CAD 41,74
Airplay 192 Playlists creation 140
Buttons (Switches) 109 Radio software installation 69, 108
DAC sound cards 42 Radio software operation 122
Glossary 214 RSS feed
GPIO configuration 109 Rotary encoders 109
HDMI TV or screens 108 Shoutcast 146
I2C backpacks 34 Spotify 188
IQaudIO Cosmic Controller 40 Speech facility (espeak) 104
Interface boards 29 Switches (Buttons) 109
Icecast streaming 181 Touch screens 12,108
IR sensors 38,42,118 USB Sound card 86
LCD displays 16,23 Vintage radios 9
Media 136 Web interface 100
Network drives (NAS) 155 WiFi 96
OLED displays 14,166 Wiring 18
Pimoroni pHat BEAT 14,41,83,233
Please note that there is also a full document index on page 234 at the end of this
document.
This design caters for both the complete novice and more advanced constructors. Do not be put off
by the size of this manual as it shows a lot of different designs. Simply read through the following
examples and decide which one is the best for you. Some examples are shown in the following
pages. Various examples of the Raspberry PI internet radio can be built using this design.
The above example built by the author has a transparent perspex front and back panel. It uses a
Raspberry Pi with a HiFiBerry sound card and a Velleman 30 watt amplifier.
Figure 12 Boom Box radio front view Figure 13 Boom Box Radio rear view
Below is a Raspberry Pi radio built into a old wine box. It uses a 2x8 character LCD and rotary
encoders. The amplifier and loud speakers are from a set of old PC speakers.
Figure 14 Raspberry Pi Wine Box radio Figure 15 Wine box internet radio internal view
Figure 17 RPI radio with two-stage valve amplifier Figure 18 The RPi valve radio chassis view
This version of the software allows for the program to be configured without a screen for use with a
vintage radio as shown below:
The radio is a Philips BX490A manufactured in the Netherlands in 1949. The purpose of this design is
retain as much of the original look and feel of a vintage radio which has been converted to run as an
Internet radio. It does not have any LCD display. In the above example the following controls are
used:
• Far left switch - Simple tone control
• Middle left switch - Volume and mute switch
• Middle right switch – Radio channel (Tuner) or media track selection
• Far right switch – Menu switch (8 positions)
• Push button on right side (Not shown) - Standard menu switch
At the top left the so-called magic eye tuning indicator has been replaced with a Red,Green,Blue
status LED. In the above picture the LED is glowing green (Normal operation). This window also
contains the IR sensor and activity LED for a remote control. If the radio is busy (loading stations for
example) it glows blue. For an error or shutdown the LED glows RED. The IR remote control also
flashes red to indicate IR remote control activity.
The software allows espeak to be configured to ‘speak’ station and search information etc.
The details on how to construct a similar project is contained in the following documents:
http://www.bobrathbone.com/raspberrypi/documents/Raspberry%20PI%20Vintage%20Radio.pdf
http://www.bobrathbone.com/raspberrypi/documents/Raspberry%20PI%20Vintage%20Radio%20O
perating%20Instructions.pdf
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.
Earlier versions of the Raspberry Pi have a separate audio output jack and composite video output.
Later versions of the Raspberry Pi have a new AV (Audio/Video) port which combines the audio and
video signals in a single jack. Instead of using a standard composite cable, this new connector
requires a 4 pole 3.55mm AV cable. To complicate matters: not all of these cables are the same!
However existing audio jack plugs are compatible with the new AV connector.
Note: The Raspberry PI Zero does not have an onboard audio output jack. Sound must be
played through either the HDMI port or a USB sound dongle (See Figure 11) or one of the Pi
Zero DAC boards available from manufacturers such as IQaudIO, HiFiBerry, or JustBoom.
See https://en.wikipedia.org/wiki/OLED
There is a very good setup guide for the Raspberry Pi touch-screen at:
https://www.modmypi.com/blog/raspberry-pi-7-touch-screen-assembly-guide
Please also note that touch screen functionality has nothing to do with the radio software.
Touch screens emulate mouse functions such as click, drag and hover using standard mouse
routines. Should you use another touch-screen other than the one recommended and this does not
work then you need to solve this first (or use a mouse/keyboard). Regrettably the author cannot
provide any support on how to configure other touch screens.
Warning: During testing, a touch screen using USB-OTG (USB On-The-Go) technology was
tried but was unsuccessful. Also attempts to enable USB OTG software seemed to disable
the normal USB ports. USB-OTG technology allows USB devices to act as a host for other USB
devices such as USB storage or cameras. The author regrettably cannot give any support on these
types of screens.
If the screen is displaying upside-down then edit the /boot/config.txt configuration file and add the
following line.
lcd_rotate=2
Another important aspect of screen size are the following parameters in /boot/config.txt.
framebuffer_width=1280
framebuffer_height=720
Changing the above can force a console size. By default it will be display's size minus overscan
settings in /boot/config.txt.
If using the Elecrow 7 inch TFT Capacitive touch screen display then see C.2 -Elecrow 7-inch touch-
screen notes on page 229.
Note: The Olimex OLED screen is not a particularly fast device when compared with say an
LCD or graphics screen. However, its biggest advantage is its size.
Any type of HD44870 LCD display can be used with any user interface. The HD44870 can either be
connected directly to the GPIO pins or via a so-called I2C (also known as IIC) backpack.
The Adafruit RGB plate has a two-line 16-character display and comes with five inbuilt pushbuttons.
It also has its own I2C interface using the MCP23017 chip so it does not require a separate I2C
backpack.
The PiFace CAD comes with a two-line 16-character display and comes with six inbuilt pushbuttons.
It uses the SPI interface from Motorola.
The touch screen can be used with or without rotary encoders or push buttons. The touch screen
variants can also use a mouse and keyboard.
It is a simple choice of which display (two or four lines, 8, 16, or 20 characters LCDs or a touch screen
or HDMI screen, OLED display or Pirate radio) and whether to use rotary encoders or push-button
switches as the user interface. The rotary encoder options give the most natural feel for the radio as
most conventional radios use knobs to control the volume and station tuning. The keyboard
interface, whilst supported on the touch-screen versions, is a very limited option.
There is a configuration program called configure_radio.sh which configures the choice of display
and user interface required. It can be safely re-run at any time.
The vintage radio software (Display option 9) specifically intended for converting an old radio to an
Internet radio whilst retaining the original look and feel of the radio. It has no LCD display.
The four lines LCD can display more information than two-line versions.
Note: The touch screen software (gradio.py or vgradio.py) cannot be run at the same time
as the LCD version of the radio software (radiod.py). It is a case of using one or the other. It
is however it is possible to switch between gradio.py or vgradio.py programs during operation.
• Directly connect the LCD to the GPIO pins. This uses six GPIO pins.
• Connection via an I2C backpack. This uses the two-pin I2C interface
The first choice uses more wiring but is the cheapest option. The second choice uses an I2C backpack
which is an extra component to be purchased. However, I2C backpacks are reasonably cheap.
If you decide to use a metal case (not advised) you will need a WiFi dongle with an aerial
mounted externally to the case. Also, the case must be earthed at the main supply both
for safety reasons and to prevent interference with sound and/or the LCD screen
This is where it can get a little confusing. The radio components (LCD, buttons, rotary encoders etc.)
can use either 26-pin or 40-pin wiring as shown in the two tables. The 26-pin version wiring can also
be used on a 40-pin Raspberry Pi. The 40-pin version of the wiring in Table 5 guarantees that there
will be no wiring conflicts with DAC components.
Things get more complicated with HiFiBerry, Justboom or IQaudIO Digital to Audio Converters
(DACs). These devices give excellent audio output quality and naturally many constructors want to
use these. However, they conflict with two GPIO pins that are used for the original radio wiring
scheme.
Pin GPIO Radio Function Conflicts with Use pin GPIO Note
12 GPIO18 Down switch DAC 19 GPIO10 26 or 40 pin Rpi
15 GPIO15 LCD data 5 IQaudIO Amp Mute 31 GPIO6 40 pin only Rpi
You are strongly advised to use the alternative 40 pin wiring scheme so that IQaudIO and
HiFiBerry products and similar can be used either at the outset or at a later date.
The configuration for the radio is contained in a file called /etc/radiod.conf. By default, this is
configured for the 40-pin scheme. Every component of the radio is configurable in this configuration
file. There is a program called configure_radio.sh that is used to configure the settings in the
/etc/radiod.conf file.
The original 26-pin Raspberry Pi’s had a GPIO conflict with GPIO 18 which was used by DACs. The
down switch now uses GPIO 10 as a result.
down_switch=18
Changed to:
down_switch=10
Note: All settings in the /etc/radiod.conf file use GPIO numbers and NOT physical pin
numbers. So in the above example down_switch is GPIO 10 (Physical pin 19).
* These pins are used for the I2C LCD backpack if used instead of the directly wired LCD to GPIO pins.
** Pin 18 is used by some DACs so pin 10 should be used for the down switch.
Pin Description Radio Name Audio DAC LCD Push Encoder Encoder
Function Function Pin Button (Tuner) (Volume)
1 3V3 +3V supply +3V +3V +3V
2 5V 5V for LCD +5V +5V 2,15
3 GPIO2 I2C Data I2C Data I2C Data
4 5V +5V
5 GPIO3 I2C Clock I2C Clock I2C Clock
6 GND Zero volts 0V 0V 1,3*,5,16 Common Common
7 GPIO 4 Mute volume MUTE Knob Switch
8 GPIO 14 Volume down UART TX LEFT Output A
9 GND Zero Volts 0V
10 GPIO 15 Volume up UART RX RIGHT Output B
11 GPIO 17 Menu switch MENU Knob Switch
12 GPIO 18 I2S CLK
13 GPIO 27
14 GND Zero Volts 0V
15 GPIO 22 Mute
16 GPIO 23 Channel down Rotary enc A DOWN Output A
17 3V3 +3V supply 0V
18 GPIO 24 Channel up Rotary Enc B UP Output B
19 GPIO 10 SPI-MOSI
20 GND Zero Volts
21 GPIO9 SPI-MISO
22 GPIO 25 IR Sensor IR sensor
23 GPIO 11 SPI-SCLK
24 GPIO 8 LCD E SPI-CE0 6
25 GND Zero Volts 0V
26 GPIO 7 LCD RS SPI-CE1 4
27 DNC PiDac+ Eprom
28 DNC PiDac+ Eprom
29 GPIO5 LCD Data 4 11
30 GND Zero Volts
31 GPIO6 LCD Data 5 12
32 GPIO12 LCD Data 6 13
33 GPIO 13 LCD Data 7 14
34 GND Zero Volts
35 GPIO 19 IQaudIO DAC+ I2S I2S
36 GPIO 16 IR LED out
37 GPIO 26
38 GPIO 20 IQaudIO DAC+ I2S DIN I2S DIN
39 GND Zero Volts
40 GPIO 21 IQaudIO DAC+ I2S DOUT I2S DOUT
Note: Make sure you are using the correct columns in the above wiring tables. Use column
6 (Push Buttons) for the push button version and the last two columns (Encoder
Tuner/Volume) for the rotary encoder version.
To Switch
GPIO
Push button
10K Resistor
GPIO
GND (0V) Push-button
Warning: The push switches (if fitted) on the rotary encoder are wired differently from
the push buttons in the earlier push button versions of the radio. For these encoders one
side of the push button is wired to GND (not 3.3V) and the other to the relevant GPIO.
If using a Revision 1 board it is necessary to use 10K pull up resistors connected between the GPIO
inputs of the rotary encoder outputs and the 3.3-volt line. Do not add resistors if using revision 2
boards and onwards.
This project uses a COM-09117 12-step rotary
encoder from Sparkfun.com. It also has a select
switch (by pushing in on the knob). These are
“Incremental Rotary Encoders”. An incremental
rotary encoder provides cyclical outputs (only) when
the encoder is rotated. The other type is an absolute
rotary encoder which maintains position information
even when switched off (See Wikipedia article on
rotary encoders). These tend to be bigger and more
expensive due to extra electronics required Only
incremental encoders are used in this project.
The rotary encoders used in this project are wired with the COMMON or GND pin in the middle and
the A and B outputs either side. However, some rotary encoders are wired with A and B as the first
two pins and GND (COM) as the third pin. Note that not all encoders come with a switch, so separate
switches for the Menu and Mute button will need to be installed. Check the specification for your
encoders first.
If using IQaudIO, HiFiberry or similar DAC products it is necessary to use the 40-pin version of the
wiring (See Table 5).
Note 1: The contrast pin 3 (VE) should be connected to the center pin of a 10K
potentiometer. Connect the other two pins of the potentiometer to 5v (VDD) and 0v (VSS)
respectively. Adjust the preset potentiometer for the best contrast. If you do not wish to
use a contrast potentiometer then wire pin 3 (VE in the diagram below) to GND (0V).
Note 2: The standard LCD comes with 16 pins. Adafruit supply an RGB backlit LCD with
two extra pins namely pins 17 and 18. These are non-standard. These must be wired to
ground (0 Volts) to work. For more information see the section Using the Adafruit backlit
RGB LCD display on page 53.
The standard LCD comes with 16 pins. Adafruit supply an RGB backlit LCD with two extra
pins namely pins 17 and 18. These are non-standard. These must be wired to ground
(GND 0 Volts) to work. For more information see the section Using the Adafruit backlit
RGB LCD display on page 53.
Warning – Some LCD displays such as Midas have a different voltage arrangement for Pin
15 and Pin 5 (Contrast). Pin 15 is an output which provides a negative voltage ( VEE)
which connects to one end of the 10K contrast potentiometer and the other end to +5V
(VDD). Connecting +5 Volts to pin 15 will destroy the LCD device.
DO NOT USE THESE DEVICES UNLESS YOU KNOW WHAT YOU ARE DOING.
If using a 16x4 LCD although not directly supported then set the lcd_width statement in
/etc/radiod.conf to 16 (lcd_width=16).
Note: All settings in the /etc/radiod.conf file use GPIO numbers and NOT physical pin
numbers. So in the above example lcd_width is GPIO 16 (Physical pin 36).
From version 5.9 onwards there is a new program called wiring.py which will display
physical the wiring required for the settings found in /etc/radiod.conf. See page 176.
The Raspberry Pi uses a standard Micro USB (type B) power connector, which runs at +5V. In general
the Raspberry PI can draw up to 700mA. Many telephone adapters deliver less than that and can
lead to problems. You also need to consider the LCD screen which can also need up to 20mA but
depends on the type of backlight. However due to the extra current that can be drawn by connected
USB or other devices, a 2.5A supply will be needed.
Try to find a power adapter that delivers at least 1.5 Ampere. As mentioned above a 2.5A supply
may be required if USB are used. See the following article. The newer RPi models can draw up to 1.5
Amps if USB peripherals or sound cards are attached.
http://elinux.org/RPi_VerifiedPeripherals#Power_adapters
The Raspberry PI can be powered either the USB port or via the GPIO header (Pin 2 or 4). Some
prototyping boards such as the Ciseco Humble PI can provide power in this way.
Visit https://www.modmypi.com
This interface board can be ordered with an optional 5-volt regulator. If using the Humble PI try with
regulator use 6v to 7v as the power input to the Humble PI 5v regulator (Not the Raspberry PI).
Trying to use 9v or more will mean that the 5-volt regulator will get far too hot.
If using an adaptor or separate 5-volt Power Supply try to use a switched-mode power supply
adaptor. This take less current and generate less heat that a power dissipation device. If a power
supply is designed to be earthed then use a 3-core cable with live, neutral and earth wires.
Things to do:
• Use double pole mains switches for isolating the mains supply when switched off. A lot of
European plugs can be reversed leaving the live wire un-switched if using a single pole
switch.
• If using a metal case always earth it and use a three-pin plug with earth pin.
• In general feed the 5-volt supply via the Raspberry Pi rather than via the GPIO header. This is
because the Raspberry Pi is fitted with a so-called poly-fuse for protection.
You should try to use a single power supply switch for the radio. Connect the AC power supply of the
adaptor to the mains switch. This switch can also provide the mains supply to the speaker amplifier.
Also see the section on preventing electrical interference on page 26.
Always consider safety first and make sure that no-one including yourself can
receive an electric shock from your project including when the case is open.
Also see disclaimer on page 211.
Audio
Input
The above manufacturer’s boards are examples only and do not imply any specific
recommendations.
The following shows the pin outs for the GPIO pins on revision 1 and 2 boards. For more information
see: http://elinux.org/RPi_Low-level_peripherals.
The above list is not relevant if using a touch screen except when used with rotary encoders or push
buttons.
The figure below shows a 4x20 HD44870 LCD plugged into the interface board.
Below is the complete overview of the interface card with some test rotary encoders, an IR sensor
the IR activity LED.
There are various interface boards available on the market for both 26-pin and 40-pin Raspberry PIs.
When this project was begun in the early days of Raspberry Pi there was very little in the way of
breakout boards. It was necessary to make connections to button, LCDs and Rotary encoders either
direct on the GPIO header or via an especially constructed breakout board. Things became more
complex when digital sound cards (DAC) were introduced as these occupied the GPIO header and
either did not extend the header pins, or if they did so, only extended a few of them.
This has now changed and there is a wide variety of breakout boards available.
On the left of the above photo is an example of the 4Tronix GPIO breakout and extender board. On
the right of the same photo is the break-out board used with a Raspberry Pi Zero W and an IQaudIO
DAC plus. All 40-pins are now made available, except for those used by the DAC, to attach buttons
and the like to the GPIO pins.
See:
https://shop.4tronix.co.uk/products/gpio-interceptor-gpio-breakout-for-40-pin-raspberry-pi
Note: Soldering skills are required to solder the 40-pin header to the breakout board.
The above breakout board is only shown as an example and many more are available on
the Internet.
Note: Don’t confuse this product (which has an I2C interface chip) with the two-line and four-line
RGB LCDs which Adafruit also sell.
1. 3.3 Volts
2. 5.0 volts
3. SDA0
4. -
5. SCL0
Figure 53 Adafruit LCD plate with ribbon cable adapter
6. Ground
Note 1: If you are going to plug the Adafruit LCD plate directly into the GPIO header on the
Raspberry PI then you don’t 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.
It is advisable to solder two posts (male pins) for each switch on the reverse side of the board (The
non-component side). Don’t solder wires directly into the board. It is better to use push-on jumper
wires connected to the switches to connect to the posts on the card.
Note: Rotary encoders cannot be used with the Adafruit Plate as these require three
connections and the Adafruit routines to utilise them are not supplied by Adafruit.
Using the Adafruit LCD plate with the model B+, 2B and 3B
The plate is designed for revisions of the Raspberry Pi. It uses the I2C (SDA/SCL) pins. Adafruit supply
a special extra tall 26-pin header so the plate sits above the USB and Ethernet jacks. For Pi Model B+,
the resistors sit right above the new set of USB ports. To keep them from shorting against the metal,
a piece of electrical tape must be placed on the top of the USB ports.
220 or 330
Ohm resistor
Note that the RGB part is a RGB LED that you If running the radio version 5.9 or earlier then
see shining very brightly in the above picture. solder a 220 or 330 Ohm resister between pin
It is not actually lighting up the LCD backlight 1 (0V GND) and pin 16 (Backlight). Version 5.10
unlike the Adafruit RGB plate. or above this is no longer necessary.
To switch off the very bright RGB light switch off the colour definitions in /etc/radiod.conf.
For example: bg_color=OFF
Skip this section if you are not using an I2C backpack. There are two versions of the backpack
supported:
1. Adafruit I2C backpack using an MCP23017 port expander – Hex address 0x20
2. Arduino I2C backpack using a PCF8574 port expander – Hex address 0x27 or 0x37
The I2C interface only requires two signals namely the I2C Data and Clock. This saves six GPIO pins
when compared with the directly wired LCD interface. See https://www.adafruit.com/product/292.
The radio software also supports the more common PCF8574 chip based backpack popular with the
Arduino hobby computer may also be used. See http://www.play-zone.ch/en/i2c-backpack-
pcf8574t-fur-1602-lcds-5v.html for example.
Note: In previous versions the i2c_backpack parameter was incorrectly shown as PCF8475
instead of PCF8574. Check the /etc/radiod.conf file.
These types of backpack are popular with Arduino users. The device address is usually hex 0x27.
Another manufacture may use hex 0x37. This is configurable in the radio configuration program.
The above figure shows the I2C interface board The above diagram shows the Adafruit I2C
using the Ciseco Humble PI (Discontinued). The backpack connected to the interface board along
header pins in the centre from left to right are, with the rotary encoders. The 26-pin male
I2C interface connector (4 pins), Volume rotary header connects to the GPIO ribbon cable on the
encoder (5 pins), Channel rotary encoder (5 Raspberry PI. On the left is a 6V to 9V power
pins), IR sensor (3 pins) and front panel LED (2 input feeding a 5 Volt regulator.
pins). In this version there are two rows of 18
pins (male and female) to allow different I2C
backpack to be connected. You will normally
only need one or the other.
Note: There are two types of TFT touch-screen available screen available from Adafruit
namely Capacitive or Resistive. The one used in this project was the 3.5-inch Resistive type.
Software installation is also covered in the above manual. Below is the easy installation script from
the manual. The supported resolution is 720 x 480 pixels. Smaller resolutions are not supported.
$ wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-
Scripts/master/adafruit-pitft.sh
$ chmod +x adafruit-pitft.sh
$ sudo ./adafruit-pitft.sh
Note: This installation procedure is only for LCD versions of the radio. If using a HDMI or
Touchscreen display see Installing the FLIRC USB remote control on page 42.
IR Sensor
If you wish to use an IR remote control with other variants of the radio then purchase an IR sensor
TSOP38238 or similar. The output in this case will be connected to GPIO 11 (Pin 23) or GPIO 26 (pin
37) for LCD or Adafruit Plate respectively.
There are equivalent devices on the market such as the TSOP4838 which operate on 3.3 volts only.
Tip: These IR sensors are very prone to damage by heat when soldering them. It is a
good idea to use a 3-pin female connector and push the legs of the IR detector into
them. If you solder the IR detector directly into a circuit then take precautions by
connecting a crocodile clip across each pin in turn whilst soldering it. See figure below:
Remote control
Almost any surplus IR remote control can be
used with this project. Later on it is explained
how to set up the remote control with the radio
software. You will need to install the software
for IR sensor.
See the section called Installing the Infra Red
sensor software on page 91.
The following table shows the GPIO pin used for the LED connections.
Table 8 Remote Control Activity LED
How to configure the LED is shown on in the section called Configuring the remote control activity
LED on page 110.
From version 6.6 onwards the radio software provides support for the IQaudIO Cosmic controller.
The IQaudIO Cosmic controller consists of the following:
• A three push-button interface (Channel UP/DOWN and Menu)
• A rotary encoder (Used as volume control)
• Three status LEDs (Normal, Busy and Error)
• A 128 by 64 pixel OLED display (I2C interface)
• Optional IR detector (Ordered separately)
The main advantage of this hardware, is that it contains everything required by the radio software.
If using the IQaudIO Cosmic controller it is necessary to configure it as shown in the section
Configuring the IQaudIO Cosmic controller and OLED on page 111.
A full set of instruction for building the Pimoroni Pirate radio with pHat BEAT can be found here:
https://learn.pimoroni.com/tutorial/sandyj/assembling-pirate-radio
Various ready-made cases are available from various suppliers. Warning: not all fit properly and
might require some modification.
Note: This installation procedure is only for the HDMI or Touchscreen display of the radio. If
using an LCD display see Installing an IR sensor and remote control on page 38.
The FLIRC USB dongle allows the use of any remote control with your
Raspberry Pi. In this design it is intended for use with the graphical
version of the radio (Touch-screen or HDMI displays). It allows
button presses on a remote control to be mapped to the keyboard
input of the Raspberry Pi. For example, pressing the volume up
button on the remote control will act just like pressing the + key on
keyboard (If so mapped). The graphical version of the radio accepts
key presses. The LCD versions of the program don’t so FLIRC will not
work with the LCD versions. This may however change in a later
version.
HiFiBerry DAC
This version supports the HiFiBerry DAC (Digital Analogue Converter) from HiFiBerry. See
https://www.hifiberry.com. There are a lot of versions of the HiFiBerry DAC.
See https://www.hifiberry.com/soldering-hifiberry/
1 - +5V
2 - +3V3
3 - GPIO28 PCM_CLK
4 - GPIO29 PCM_FS
5 - GPIO30 PCM_DIN
6 - GPIO31 PCM_DOUT
7 - Ground
8 - Ground
These GPIOs are not available on the A+/B+/Pi2
Figure 70 Raspberry PI P5 connector
Figure 71 HiFiBerry DAC plus Connector Figure 72 Pi Radio with HiFiBerry DAC
Create your own P5 connector using an eight Male/Female patch wires as shown in the above left
figure. Although not essential it is a good idea to use shrink wrap to keep the patch pins neatly
together.
The HiFiBery DAC PLUS uses the 40-pin connector and has an unpopulated 40 pin header to extend
the GPIO pins on the HiFiBerry DAC to use with other cards.
Note: All settings in the /etc/radiod.conf file use GPIO numbers and NOT physical pin
numbers. So in the above example down_switch is GPIO 10 (Physical pin 19).
The Pimoroni pHat is compatable with HiFiBerry DAC (Not DAC+) and uses the same Device
Tree (DT) overlay.
The switch and LCD GPIO configuration in /etc/radiod.conf must also be changed to match the
wiring shown in Table 5 Radio and DAC devices 40 pin wiring. This can be done with the
configure_radio.sh program.
# Other switch settings
menu_switch=17
mute_switch=4
up_switch=15
down_switch=14
left_switch=23
right_switch=24
The radio installation program will allow selection of either the 26 pin or 40 pin wiring scheme.
Note: The above configuration is set-up using the configure_audio.sh program to amend
the /etc/radiod.conf during installation.
Features:
•24-bit audio at 192KHz
•Line out stereo jack
•pHAT format board
•Uses the PCM5102A DAC to work with the Raspberry Pi I2S interface
Note 1: Do not use the 40 female header that comes with the board but use a 40-pin
extender so that other cards can be used on top of it.
Note 2: The Pimoroni pHat is not completely compatible with the HiFiberry DAC although it
uses the same software driver. In particular to use the Alsa sound mixer a package called
pulseaudio is required. However pulseaudio is not compatible with several of the features of this
package such as the espeak speech package. Normally the pulseaudio package must be removed as
shown in the section called Installing pulseaudio on page 69. The Pimoroni pHat DAC will run fine
without any mixer controls.
One of the most irritating faults that one can have is the LCD screen occasionally either going blank
or displaying hieroglyphics especially when switching on and off other apparatus or lights on the
same circuit. This is due to Electromagnetic Interference (EMI).
See https://en.wikipedia.org/wiki/Electromagnetic_interference for more information.
EMI can be caused by any number of sources such as fluorescent lighting, switching on and off
equipment on the same circuit as the radio or even electrical storms. If you are using a standard
Raspberry PI USB power supply then you will probably not experience this problem as nearly all are
fitted with a ferrite core (This is the big lump in the cable or may be built in). If you do experience
this problem then try the following solutions one at a time in the order shown below. They can all be
used together if required.
For most of the radio designs in this document no specific cooling is required. If you need to cool the
Raspberry Pi (Those with touchscreens in particular) then a variety of heat sinks and cooling fans are
available as shown in Figure 93 below. Even with a heat sink good ventilation is necessary.
Miscellaneous
Simple tone regulator
It may be that you wish to fit a tone regulator to the radio. Below is one option.
The following diagram and modified text came from Jack Orman at:
http://www.muzique.com/lab/swtc.htm
Note that the above circuit has a lot of attenuation of the audio output so using the
onboard audio output of the Raspberry Pi might result in a disappointing level of
volume. It is recommended to use a sound output DAC or USB sound dongle.
The audio output from the Raspberry Pi or DAC is fed into the
board via a standard Audio socket.
Below these the Left and Right audio outputs connect to the
Amplifier.
The diodes used are any low voltage low current diodes such as the
IN4148. So to use all of the above combinations would require a single
pole 8 way rotary switch and logic and nine diodes. The first switch
position is off.
Figure 97 IN4148 diode
Note: Don’t carry out any of the following commands just yet. They are just examples.
Raspberrypi login: pi
Password: raspberry
pi@raspberrypi:~$ Last login: Sun Apr 6 10:18:18 2014 from 192.168.2.100
pi@raspberrypi:~$
The prompt line is displayed ending with a $ sign. The pi@raspberrypi:~ string means user ‘pi’ on
host machine called ‘raspberrypi’. The ~ character means the user ‘pi’ home directory /home/pi. In
this tutorial if you are required to do something as user pi then only the $ sign will be shown
followed by the command as shown in the example below:
$ mpc status
Again, the prompt shows the username, hostname and current working directory. However only the
# followed by the required command will be shown in this tutorial. For example:
# apt-get install mpd mpc python-mpd
Some commands produce output which does not need to be shown. In such a case a ‘:’ is used to
indicate that some output has been omitted.
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
: {Omitted output}
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 0/1
Subdevice #0: subdevice #0
$ /usr/share/radio/configure_radio.sh
The third command has a ./ in front of it, the first one doesn’t. Why?
The reason is that the raspi-config program is in the /usr/bin directory which is in the PATH
environment directive. This can be seen with the following command.
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/game
s:/usr/games
The second program is located in the /usr/share/radio directory which is not in the PATH directive.
The ./ in front of the command means that the program or script will be found the current directory.
So, this means for programs not in directories specified in the PATH environment directive, you must
either specify the full path name to the command or change to its directory and then enter the
command with a ./ in front of it.
In the system prompt for user pi you will see a ~ character. The ~ character means the home
directory for the current user, this case pi. So ~ is the same as /home/pi.
pi@raspberry3:~ $
At various points during the installation procedures in this manual you will be asked to edit certain
configuration files such as /etc/radiod.conf (The radio configuration file) or /boot/config.txt (The
boot configuration file). There are various text editors that can be used but the main ones in the
case of the Raspberry Pi are:
1. Nano - nano is a small, free and friendly editor particularly suited for use by beginners.
2. Vi – vi is usually the professional user’s choice of editor. It is very powerful but a lot harder
to use for someone unfamiliar with it.
Usage:
nano <filename>
or
vi <filename>
Where <filename> is the name of the file to be edited.
It is important to know that most configuration files are owned by root so you may be able to read
them but not write them. For example:
$ nano /etc/radiod.conf
This will allow you to read the file but not change it. To give user pi temporary root user permissions
so that you can save changes to the file use the sudo command in front of the editor command:
$ sudo nano /etc/radiod.conf
Or
$ sudo vi /etc/radiod.conf
Note: Make sure that you edit the file /etc/radiod.conf and not
/usr/share/radio/radiod.conf which is the distribution file. The latter is copied to the /etc
directory during installation and configuration.
Using Nano
When nano is started it will display the contents of the file being edited. For example,
/etc/radiod.conf. In this example the following screen will be displayed.
Hold down the Ctrl key and press the letter G on the keyboard to display the help text. The following
screen will be displayed:
The ^ character means the Control-key (Ctrl). So for example ^O above is Ctrl + O. For more
information on nano see https://www.nano-editor.org/dist/v2.0/nano.html
The latest version of the operating system is called Raspbian Stretch (Raspbian Linux 9). Create a
new SD card with Stretch.
Note: The touch-screen version of the software requires a desktop version of the
operating system so use Rasbian Stretch and not the Lite version. Although it is
possible to upgrade Lite to use a desktop, it is beyond the scope of this manual. Only
use Lite for LCD versions of the radio.
Note: The Raspberry Pi 3B+ released in March 2018 needs Raspbian Stretch from
March 2018 or later. The Pi 3B+ will not boot with earlier versions of the operating
system.
SD card creation
Use at least an 8 Gigabyte Card. Create an SD card running the latest version of Raspbian Stretch or
Stretch Lite. See the Image Installation Guides on the above site for instructions on how to install
the Raspbian operating system software.
After logging in run raspi-config. Select “Advanced options” and select option A4 to enable SSH.
$ sudo raspi-config
Reboot the Raspberry Pi after which it will be possible to log into the Raspberry Pi using SSH.
$ sudo reboot
Note: Security is becoming more and more of an issue for devices connected to the internet.
If SSH has been enabled then please change the user password at the first opportunity. See
the section called Chapter 13 - Internet Security page 198 for further information on security issues.
Run the following command to upgrade to the latest packages for this release.
$ sudo apt-get upgrade
If you have an older version of the Raspberry Pi then update the firmware.
$ sudo rpi-update
Important: After upgrading the system the repository locations may no longer be valid. Re-
run apt-get update to refresh the package list. Failing to do this may result in packages
failing to install.
Once you have updated the operating system login to the system and run raspi-config.
$ sudo raspi-config
Warning: If you are intending to run the touch-screen/HDMI version of the radio, do not be
tempted to start removing components of the pygame software such as games as this may
unfortunately remove graphic libraries used by the radio software.
The desktop environment is not required for the LCD versions of the Radio and takes a lot of
processing power. It is enabled by default in Stretch but is not installed with Stretch Lite. If you are
not planning to use the touch-screen or HDMI version of the radio then disable it. Select option 3
Boot options
Select option 4 “Localisation Options”, Use the tab key to move to <Select> and press enter.
The above screen is using the Bitvise SSH client program (See Putty on the web).
Select the “Change Timezone” option. Again, use the tab key to move to <Select> and press enter.
Select the correct one and save it by tabbing to <ok> and pressing the enter key. The time zone will
be updated. Exit the program once finished.
Both the password and hostname can be changed using the raspi-config program.
Option 1 is used to change the password. Make sure you record your new password somewhere
safe (It is easy to forget it).
As the password is entered nothing is displayed. This is normal. You will be asked if you wish to
reboot the system. After you reboot the system you will see the new hostname at the login prompt.
pi@piradio:~$
In the above example the new hostname is piradio. Once the hostname has been changed the
program will ask if you wish to reboot. Answer “yes” to reboot.
Now enter the SSID and passphrase for your network. Save the settings and reboot the Raspberry
PI. If this option is not available then use the procedure Configuring a wireless adaptor on page 96.
In such a case re-run rasp-config. Select localisation options and select I4 to set Wi-Fi country:
Select your country from the dropdown menu and exit the raspi-config to save the setting.
Select a locale beginning with the two-letter international code for your country and language.
In the following example for the Netherlands the locale is this nl_AW UTF-8 for the Netherlands (nl).
Warning: Do not be tempted to generate “All locales” as this is not necessary and will take a
very long time.
Press OK to continue. The program will now generate the selected locales.
Generating locales (this might take a while)...
en_GB.UTF-8... done
nl_AW.UTF-8... done
Generation complete.
Select the required locale nl_AW in this example and press OK to save. The new locale will become
active after the next reboot.
If the installation fails with the above message re-run the apt-get update command to update the
library list and retry installing ffmpeg.
Install python-requests
If you are running Stretch Lite it is necessary to install python-requests for the Shoutcast program as
this is not loaded by default. This step should not be necessary if using the Stretch desktop operating
system.
Scratch is not actually used by the radio software but the graphic files in the
/usr/share/scratch/Media/Backgrounds directory are used for the background wallpaper of the full
feature graphical radio.
The background wallpaper is set by the following parameter in /etc/radiod.conf and can be
amended to use a different background.
wallpaper=/usr/share/scratch/Media/Backgrounds/Nature/beach-malibu.jpg
After reboot install the Music Player Daemon (mpd) and its client (mpc) along with the Python MPD
library.
$ sudo apt-get install mpd mpc python-mpd
If the installation says it cannot find the above packages then re-run the update command to update
the library list and retry installing.
$ sudo apt-get update
Note: If installing on Stretch Lite this will take quite a long time as there are a lot of software
libraries to be installed.
Note: At this stage there are no playlists configured so the music daemon won’t play
anything. The play lists are created when the radiod Debian Package is installed in the next
section.
Installing pulseaudio
The pulseaudio package may or may not be installed. This has been different between various
releases of the operating system. Currently the pulseaudio package causes a lot of problems with
the radio software, in particular espeak. If you do not intend to use espeak and need pulseaudio, for
example, for blue-tooth devices or pHat BEAT then install it. The following table shows the options:
The radio installation program will configure the Music Player Daemon to use pulseaudio instead of
alsa. Note: The Pimoroni installation software for Pirate Radio installs pulseaudio.
To install pulseaudio:
$ sudo apt-get install pulseaudio
To remove pulseaudio:
$ sudo apt-get remove pulseaudio
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 69
Also remove unwanted libraries.
$ sudo apt autoremove
The Raspberry PI Internet Radio software is distributed as a Debian package. This can be
downloaded from http://www.bobrathbone.com/raspberrypi/pi_internet_radio.html
Either download it to your PC or Macintosh and copy it to the /home/pi directory or get it directly
using the wget facility.
To use the wget facility first copy the download link from the above page (Right click on the link). Log
into the Raspberry PI. Now use wget to the software package:
$ wget http://www.bobrathbone.com/raspberrypi/packages/radiod_6.9_armhf.deb
Note: This configuration program does the basic configuration to get the radio going with
the hardware you are using. More complex configuration options are explained in Chapter 7
– Configuration on page 108.
The configuration program is automatically run when installing the radio package but can safely be
run at any time using the following commands:
$ cd /usr/share/radio
$ sudo ./configure_radio.sh
The installation script detects if this is a software upgrade and if that is the case displays the
following screen. Normally select option 2 if upgrading the software. This means that the
configuration will not be changed.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 70
Figure 117 Configure radio – Upgrade
If you selected option 1 above and you are upgrading the software from a previous version, the
program will ask if you wish to overwrite the existing configuration. Unless you have a heavily
modified configuration you may safely overwrite the configuration file:
If option 1 is selected the existing configuration will be replaced. A backup copy of the original
configuration is written to /etc/radiod.conf.save. The following screen will then be displayed:
Even if you are using a touch screen or HDMI display you still can select option 1 or 2. Only select
option 3 if you are only going to use a HDMI or touch screen display with no buttons or rotary
encoders and with or without a mouse. pHat BEAT and PiFace CAD come with their own push-
buttons so select option 5 or 6 respectively.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 71
Note: This configuration program can be re-run at any time in the future. Change directory
to /usr/share/radio and run configure_radio.sh. To do this run the following:
$ cd /usr/share/radio
$ sudo ./configure_radio.sh
Select option 1 if push buttons are being used or option 2 if using rotary encoders. This screen and
all following screens have the option to not change the configuration. The program will then ask you
If the push-button interface is selected, the program will ask how they have been wired. As from
version 6.9 push-buttons can be wired to either +3.3V(The original scheme) or GND(0V).
Select the correct voltage that the push-buttons have been wired to, either GND(0V) or +3.3V.
The program will now ask which version of the wiring has been used during construction:
Normally select the 40-pin option unless you have used the 26-pin wiring scheme. See Table 4
Controls and LCD wiring 26 pin version and Table 5 Radio and DAC devices 40 pin wiring.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 72
Confirm selection and continue to the next screen:
Select the correct option for the display interface and confirm selection. Again, it is possible leave
the configuration unchanged.
If option 5 – ‘HDMI or touch screen display’ was selected the go to the section called Installing the
HDMI or touch screen on page 78.
If option 2, 3, 4 or 6 was selected then this will require the hex address to be configured. Otherwise
the program will skip the screens in the next section and go to the section called Select the type of
LCD display on page 77.
If option 6 (Olimex OLED) was selected then the following will be displayed:
This option sets the flip_display_vertically parameter in /etc/radiod.conf to yes or no and allows
the Olimex OLED display to be flipped vertically.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 73
Configure SPI Kernel Module
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 74
Select Yes to enable the SPI kernel module. Select “Finish” to exit.
At this stage you may not know what the Hex address for PCF8574 devices is so simply select option
1 or 2 depending upon whether you are using an Adafruit or Arduino backpack. These use different
I2C integrated circuits namely MCP23017 (Adafruit) or PCF8574 (Arduino). For the OLED display
select option 4. Once you have installed the I2C libraries (described later) you can run the
configure_radio.sh program again to change to the correct hex address.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 75
Figure 128 Configure radio - Enable I2C libraries
The raspi-config program now runs. Select 5 “Interfacing options” then option P5:
Select - P5 I2C Enable/Disable automatic loading of I2C kernel module. The following screen will be
displayed. Select yes to enable the ARM I2C interface.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 76
Select the type of LCD display
Skip this section if you are not using an LCD display directly connected to the GPIO pins. Confirm the
selection and continue to the next screen to select the type of LCD display. This section is not
relevant for a HDMI or touch screen.
Select the type of display to be used and confirm the selection. The installation script asks if you wish
to configure the audio device:
You should select option 1 to run the audio device configuration program.
If you selected option 1 then go to the section Configuring the audio output on page 79.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 77
Installing the HDMI or touch screen software
This section is only relevant if configuring an HDMI or touchscreen interface. If using an LCD display
then skip this section. The following screen is displayed:
Select which radio program to start-up. . See Figure 1 Raspberry pi 7-inch touchscreen radio and
Figure 3 Vintage tuning touch-screen radio on page 4.
Normally select option 1 to automatically start the gradio.py program when the Graphical Desktop is
loaded. This copies a desktop configuration to the file /home/pi/Desktop/gradio.desktop file.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 78
[Desktop Entry]
Name=Radio
Comment=Internet radio
Icon=/usr/share/radio/images/radio.png
Exec=sudo /usr/share/radio/gradio.py
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;
There is also a similar file created called gradio.desktop for the vintage graphical radio.
The installation script also copies the graphic screen configuration to /etc/radiod.conf. It also
disables start-up of the radiod service which is only used for the LCD versions of the radio.
Now select the option to display the radio full screen (7-inch touchscreen) or in a desktop window
(Large HDMI monitor or TV).
Configuration of the HDMI/Touch screen is shown in the section Configuring the HDMI or Touch
Screen on page 108.
Operation of the HDMI/Touch screen is shown in the section called Operation of HDMI and touch
screen displays on page 127.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 79
Figure 137 Selecting the audio output device
Note: This configuration program can be re-run at any time in the future. Change directory
to /usr/share/radio and run configure_audio.sh. To do this run the following:
$ cd /usr/share/radio
$ sudo ./configure_audio.sh
Note: python-smbus may already be installed on Raspian Stretch but not the Lite version
If you are using a revision 2 Raspberry Pi (Newer boards) carry out the following:
$ sudo i2cdetect -y 1
If you are using a revision 1 Raspberry Pi (Old boards) carry out the following:
$ sudo i2cdetect -y 0
This will search /dev/i2c-0 (Old RPIs) or /dev/i2c-1 (Later versions) for all address, and if correctly
connected, it should show up at 0x20 for the Adafruit LCD Plate or normally 0x27 for the Arduino
PCF8574 backpack but might be another address such as 0x3F. The OLED 128x64 pixel display uses
address 0x3C. See Figure 138 The I2C bus display using the i2cdetect program.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 80
Figure 138 The I2C bus display using the i2cdetect program
If the following is seen instead then it is necessary to run enable the I2C module at boot time using
raspi-config.
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or
directory
If problems with i2cdetect are still encountered, then edit the /boot/config.txt file using sudo nano
and change the following line:
#dtparam=i2c_arm=on
Change to:
dtparam=i2c_arm=on
Note: If the Arduino PCF8574 backpack is using another address other than 0x27 then you
must modify the i2c_address parameter in /etc/radiod.conf. For example, if the backpack
is using the address 0x3F then modify the i2c_address parameter to match this as shown in
the example below:
# The i2c_address parameter overides the default i2c address. 0x00 = use default
# Some backpacks use other addresses such as 0x3F, then set i2c_address=0x3F
i2c_address=0x3F
Once both of these packages have been installed, you have everything you need to get started
accessing I2C and SMBus devices in Python. Now reboot the Raspberry PI.
$ sudo reboot
The Radio should start automatically. If not then go to the section called Chapter 9 -Troubleshooting
on page 160.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 81
Installation log
A log of the changes made by the configuration program will be written to the
/usr/share/radio/install.log file.
Once rebooted the software should run and music should be heard out of the on-board audio jack. If
not go to the section called Chapter 9 -Troubleshooting on page 160.
The radio daemon (LCD versions only) can be started and stopped with the service command:
$ sudo service radiod start
$ sudo service radiod stop
To prevent automatic start-up of the radio at boot time run the following command:
$ sudo systemctl disable radiod
To re-enable it:
$ sudo systemctl enable radiod
The SPI maximum frequency has changed to 125000000 after kernel 4.9.43, however the pifacecad
software can't support the default frequency. You can read about this at the following link:
https://github.com/raspberrypi/linux/issues/2165
It is very likely that this problem my be fixed in a later release of the kernel and that the following
patch will not be necessary.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 82
Edit the “spi transfer struct” from
# create the spi transfer struct
transfer = spi_ioc_transfer(
tx_buf=ctypes.addressof(wbuffer),
rx_buf=ctypes.addressof(rbuffer),
len=ctypes.sizeof(wbuffer)
)
To:
# create the spi transfer struct
transfer = spi_ioc_transfer(
tx_buf=ctypes.addressof(wbuffer),
rx_buf=ctypes.addressof(rbuffer),
len=ctypes.sizeof(wbuffer),
speed_hz=ctypes.c_uint32(100000)
)
Warning. Do not forget to add the comma (,) to the end of the previous line. Restart the PiFace CAD
radio. Also run update the Raspberry Pi firmware to the latest version.
$ sudor pi-update
Once the Pimoroni software is installed and tested it is then necessary to disable the Pimoroni radio
software and install the Rathbone radio software as shown in Chapter 6 - Installing the radio
Software on page 69. Only the VU meter software is used by the Rathbone software.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 83
Enter y to continue. The installation script will take some time to install and build the software.
Reboot the Raspberry Pi and test the Pirate radio.
$ sudo reboot
Note: This author does not provide any support for the Pimoroni software or VLC
media player. If you have problems getting the Pimoroni software to run then contact
https://forums.pimoroni.com/c/support
Do the following:
1. Now carry out the instructions shown in Chapter 6 - Installing the radio Software on page 69.
2. Since the Pirate Radio does not have a screen it is necessary to install espeak as shown in
the section called Installing the speech facility on page 104 to hear choices when using the
menu button.
For example:
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 84
radiod-patch-6.9-1.tar.gz
The above illustration shows the bcm2835 Alsa Mixer. There is only one mixer control called PCM
(Pulse Code Modulated). Adjust the volume to 100% if not already set by using the Up and Down
keys on the keyboard. Press the Esc key or Ctl-Z to exit the program.
It is also possible to set the volume for the on-board mixer volume with the amixer program.
$ amixer cset numid=1 100%
numid=1,iface=MIXER,name='PCM Playback Volume'
; type=INTEGER,access=rw---R--,values=1,min=-10239,max=400,step=0
: values=400
| dBscale-min=-102.39dB,step=0.01dB,mute=1
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 85
Configuring other sound devices
Other sound devices can be used with the radio. Currently supported are the following devices:
In the above example Card 0 is the on-board devices namely the audio output jack and HDMI. Card 1
is a USB PnP sound device.
To configure USB audio devices run the Run the configure_audio.sh utility.
$ cd /usr/share/radio
$ ./configure_audio.sh
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 86
Figure 140 Configure USB DAC
Reboot when prompted. After rebooting the Raspberry Pi run the alsamixer program.
$ alsamixer
Use the Left and Right keys to position on the ‘Speaker field’. Adjust the sound level using the Up
and Down keys (80% in the above example). Pres Esc key or Ctl Z key to exit.
To configure add on audio cards run the Run the configure_audio.sh utility:
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 87
$ cd /usr/share/radio
$ ./configure_audio.sh
Select option 4, 5, 6 or 7 depending upon the HiFiBerry device being used an press OK.
Reboot when prompted by the next screen.
The Pimoroni pHat is compatable with HiFiBerry DAC (Not DAC+) and uses the same Device Tree (DT)
overlay so select HiFiBerry DAC if using the pHat.
Use the left and right keys to select the mixer control (Analogue) and use the up down keys to
change the volume to 100%.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 88
Figure 143 Set mixer analogue volume
Next use the right key to position on the “Digital” mixer control and use the up down keys to change
the mixer volume:
If no music is heard check that there are playlists configured using the music player client mpc
playlist command (sudo isn’t necessary):
$ mpc playlist
Nashville FM
RAI Radio Uno
RAI Radio Duo
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 89
Prima Radio Napoli
Radio 1 Nederland
:
If no playlists are shown run the create_stations.py program as shown in the section called Creating
new playlists on page 141.
dtoverlay=hifiberry-dacplus
Modify the audio_output section in /etc/mpd.conf to support the HiFiBerry DAC and software
mixer.
audio_output {
type "alsa"
name "HiFiBerry DAC"
device "hw:0,0"
# mixer_type "hardware"
mixer_type "software"
:
If no music is heard run the alsamixer program and set the volume to at least 80% as shown in the
previous section on HiFiBerry devices.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 90
Configuring MPD to use pulseaudio
In this version pulseaudio is removed due to the fact that for some unknown reason MPD has
problems if pulseaudio is installed and MPD is configured to use the default ALSA system. However,
more and more people want to use the Pi as Bluetooth speakers which requires pulseaudio
MPD can be configured to use either the default Alsa sound system or the Pulse audio server. If you
want to use pulseaudio, stop the radio and install pulseaudio:
Either re-run the configure_radio.sh program or manually change the audio_output type statement
in /etc/mpd.conf to pulse.
audio_output {
# type "alsa"
type "pulse"
name "IQAudio DAC+"
device "hw:0,0"
mixer_type "software"
:
}
http://lirc.sourceforge.net/remotes/
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 91
It is necessary to install the python-lirc package.
Note: Earlier versions of Raspbian Stretch do not have the python-lirc package in its
repository which means it must be downloaded from the author Tom Preston at GitHub.
Normally python-lirc it can be installed using apt-get as shown below.
Note: The above command is all one line. Now install the software:
$ sudo dpkg -i python-lirc_1.2.1-1_armhf.deb
If you carried out the above command then edit /etc/lirc/lirc_options.conf and change the driver
name in the [lircd] section from ‘devinput’ to ‘default’.
[lircd]
Nodaemon = False
driver = default
The following step requires configuration of the lirc-rpi dtoverlay in /boot/config.txt file using the
following table:
If using the separate IR sensor and activity LED configure lirc-rpi in the /boot/config.txt file with the
lirc-rpi device details. Edit the /boot/config.txt file and add the correct dtoverlay statement to the
end of the file:
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 92
Do this for the AdaFruit plate.
dtoverlay=lirc-rpi,gpio_in_pin=16,gpio_in_pull=high
Now test your remote control with the mode2 command. You should see lots of codes when you
press buttons on the remote control.
$ sudo mode2 -d /dev/lirc0
space 5358604
pulse 4591
space 4459
pulse 651
If you see the following output then edit /etc/lirc/lirc_options.conf and change the driver name in
the [lircd] section from ‘devinput’ to ‘default’ as previously shown.
Check that the lirc0 device exists. If it doesn’t exist you cannot continue. Check that the
/boot/config.txt file has been correctly configured as shown above.
$ ls -la /dev/lirc0
crw-rw---T 1 root video 246, 0 Jan 1 1970 /dev/lirc0
It is now necessary generate a configuration for the remote control then first move the distributed
/etc/lirc/lircd.conf file out of the way.
$ sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd.conf.org
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 93
Now run the configuration program.
$ sudo irrecord -f -d /dev/lirc0 /etc/lirc/lircd.conf
If the problem persists, make sure the /boot/config.txt file has been correctly set up as previously
shown and that a reboot was carried out.
The irrecord program will ask you for the names of the buttons that you want to configure. You may
not make your own names up. You must use the names shown in the first column of the following
table and which are defined in /etc/lirc/lircrc.
It is a good idea to just start with the basic keys for volume up and channel change and when you
have the remote control working re-configure with all of the keys shown in Table 12 Remote Control
Key names and functions.
The actual list of available names that may be used can be displayed with the following command:
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 94
$ sudo irrecord --list-namespace
There are more than 440 key names but only use the ones defined in the list above.
The activity LED will flash a few times however it is necessary to reboot the system to enable the
new IR remote configuration.
$ sudo reboot
Now test the remote control with your newly configured remote control.
Now run ircat and press each key on the remote control in turn:
$ ircat piradio
KEY_VOLUMEUP
KEY_VOLUMEDOWN
KEY_CHANNELUP
KEY_CHANNELDOWN
KEY_MENU
KEY_MUTE
KEY_UP
KEY_RIGHT
KEY_LEFT
KEY_DOWN
KEY_LANGUAGE
KEY_INFO
Use Ctrl-C to exit. If keys are not responding repeat the previous Remote-Control installation
procedure.
Check that the radio is listening on UDP port 5100 (or as configured in /etc/radiod.conf).
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 95
$ sudo netstat -an | grep 5100
udp 0 0 127.0.0.1:5100 0.0.0.0:*
begin
prog = piradio
button = KEY_VOLUMEDOWN
config = KEY_VOLUMEDOWN
repeat = 0
end
If you need to manually configure a wireless adaptor for the radio then follow this procedure.
Choose a wireless adapter that has been approved for the Raspberry PI or use the model 3B with in-
built WiFi adapter. See the following link for approved Raspberry PI peripherals:
http://elinux.org/RPi_VerifiedPeripherals
The above shows a Ralink (Tenda) wireless adaptor but this will vary depending on the adapter that
has been installed.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 96
source-directory /etc/network/interfaces.d
You do not need to change this file. To configure a static IP address, see Configuring a static IP
address on page 99). 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.
Field Description
ssid your WIFI (SSID) name
scan_ssid A value of 1 means broadcast and value of 2 means a hidden SSID (Normally enter a
value of 1)
psk Your WIFI password
proto Your choice of RSN or WPA. RSN is WP2 and WPA is WPA1. (most configurations are
RSN)
key_mgmt Either WPA-PSK or WPA-EAP (pre-shared or enterprise respectively)
pairwise Either CCMP or TKIP ( WPA2 or WPA1 respectively)
auth_alg 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 so-
called 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.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 97
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. Remove the
comment line which shows the original key (#psk=”abcdef1234”)
The adaptor can be started and stopped with the following commands:
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"
Solution: Correct the error and run the ifup wlan0 command.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 98
Solution: This isn’t actually an error. Just run the ifdown wlan0 command and retry the ifup wlan0
command. It should then work.
1. Configure the home router so that DHCP delivers a fixed address based upon the Raspberry
Pi’s MAC address. This is called DHCP IP address reservation.
2. Configure the Raspberry Pi with a static IP address.
If DHCP IP address reservation isn’t an option then it is possible to configure a so-called static IP
address which will not change between reboots. To do this you must find out the IP address of your
router (gateway) and netmask for your network. Do this with the netstat command as shown below:
$ netstat –r -n
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
In the above example the IP address of the gateway is 192.168.1.254. Your router’s IP address will
almost certainly be different. Take a note of the gateway IP address and the subnet (Genmask) of
your network. In this case that is 255.255.255.0. You will need to use these values to configure the
interface. The next thing you need is a free IP address in your network. There will be lots of them but
approximately 50 to 100 of them will be claimed for the DHCP pool. The only way to know what
DHCP is using is to log into your router and look at the configuration. If this isn’t possible or you are
unsure of what to do then pick one somewhere in the middle of the network range. For example, in
the above network you could choose 192.168.1.125. Check that it isn’t already in use somewhere
else in your network. Check it with the ping command. If you see 100% packet loss then the IP
address you have chosen isn’t in use in your system so you can use it.
$ ping -c 4 192.168.1.125
PING 192.168.1.125 (192.168.1.125) 56(84) bytes of data.
From 192.168.1.8 icmp_seq=1 Destination Host Unreachable
From 192.168.1.8 icmp_seq=2 Destination Host Unreachable
From 192.168.1.8 icmp_seq=3 Destination Host Unreachable
From 192.168.1.8 icmp_seq=4 Destination Host Unreachable
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 99
4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 3012ms
Remove the # character from the interface definitions and modify the IP addresses as required.
However, use an IP address which is clear of the DHCP pool. An IP address 150 or higher will
probably be safe.
interface eth0
static ip_address=192.168.0.150/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1 8.8.8.8
Note IP 8.8.8.8 is the IP address of Googles public DNS (Domain Name System) servers.
Save the file and reboot the system. After reboot; log into the Raspberry PI using the new IP
address. If unable to log in connect a keyboard and screen and reboot. Log in and troubleshoot the
problem.
Install Apache
Install Apache the web server. Make sure that the system is up to date with the following commands
otherwise installation of Apache may fail.
$ sudo apt-get update
$ sudo apt-get upgrade
Now install Apache and the PHP libraries for Apache as user root.
This will take some time. If the above fails run the following command and re-run the installation:
$ sudo apt-get -f install
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 100
Test the Apache web browser
Point your web browser at the IP address of the Raspberry PI. For example: http://192.168.2.51.
You should see the following display.
Now run:
$ sudo dpkg -i radiodweb_1.7_armhf.deb
This package will install the radio web pages in the /var/www/html directory and the CGI scripts in
/usr/lib/cgi-bin directory. It will also enable the CGI scripts module.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 101
apache2: Could not reliably determine the server's fully qualified domain
name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress
this message
The message may be ignored or it can be suppressed by editing the /etc/apache2/apache2.conf file
and adding a ServerName directive.
Now click on the ‘Radio’ tab. If the radio software is running you will see the following:
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 102
Figure 146 Snoopy web interface
Click on any station in the list to select a station. After a short pause the station should start playing
if it is online.
The Shoutcast tab is explained in Using the Shoutcast Web Interface on page 147.
Note: The radio tab only displays radio stations or media tracks from MPD. It is not currently
capable of displaying Spotify or Airplay details which can only be seen on the radio itself.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 103
Changing the Web Interface Radio photo
If you want to change the photo displayed by the web interface, then replace the jpeg photo file at
/var/www/html/images/radio.jpg. Try to adjust the size on disk to about 50K using a suitable photo
editor such as Photo Shop. Copy the new jpeg photo to the pi home directory with any ftp program.
Now copy it to the web pages image directory using sudo.
$ sudo cp radio.jpg /var/www/html/images/.
If the new image looks stretched then it may also be necessary to change image proportions in the
<img..> statement in /var/www/html/index.html file. Find the following line in the index file and
adjust the width/height values to display the photo with the correct proportions.
The speech facility makes use of the /var/lib/radio/language file as already described in the section
called Creating a new language file on page 114
The verbose setting speaks the station or track details every time it is changed. However it can take a
long time to move through the tracks or stations whilst speaking. Usually set this to no.
verbose = no
To get the right balance between speech volume and the normal radio volume adjust the
speech_volume parameter percentage (10-100%)
speech_volume=30
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 104
$ espeak -ven+f2 -k5 -s130 –a
Where -v is the voice (en+f2 = English female voice 2), -k is capitals emphasis, -s is the voice speed
and -a is amplitude (0-200), the -a parameter is filled in by the radio program.
Testing espeak
You can test espeak with the following command (Stop the radio first).
$ espeak -ven+f2 -k5 -s130 -a20 "Hello Bob" --stdout | aplay
If no sound is heard then then test using the aplay program. The espeak system will not work if
aplay is not working. Test with aplay and a suitable wav file.
$ sudo mpc pause
$ aplay /usr/share/scratch/Media/Sounds/Vocals/Singer2.wav
# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Device [Generic USB Audio Device], device 0: USB Audio [USB Audio]
Subdevices: 0/1
Subdevice #0: subdevice #0
In the above example there are two devices namely bcm2835 ALSA (normal audio jack output) and
Generic USB Audio Device. If using either a HiFiBerry DAC or IQaudIO device then create the
/etc/asound.conf file using nano:
$ sudo nano /etc/asound.conf
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 105
pcm.!default {
type plug
slave {
pcm "plughw:0,0"
format S32_LE
}
}
The format S16_LE is an alternative format but does not work with HiFiBerry DAC. The above
statements set up the default mixer and PCM sound device respectively to use card 1.
If using the USB (Card 2 device 1) then change the device definition in the above file.
pcm "plughw:1,0"
Speech Operation
At the moment the speech function is highly experimental and will be developed further if there is
the demand. The best use is with the remote control which includes a button for toggling sound on
and off and another button to speak information about the station or track as well as speaking the
time. These buttons are set up in the section called Installing the Infra Red sensor software on page
91.
The Rotary encoder version of the radio is the best implemented. The MUTE switch is now the
“Speak information” switch. To mute the radio, hold the button in for two seconds and release.
The exclamation message is removed if the message is displayed on a display. Only speech is
affected.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 106
Keeping the radio software up-to-date
The Radio software may be updated from time to time especially if a new
version of the operating system is released or a new feature is added to
the software. To keep up to date follow the author on Twitter at:
https://twitter.com/bob_rathbone (https://twitter.com/bob_rathbone)
One of the easiest ways of backing up the SD card on a Windows machine using Windows Disk
Imager (Win32DiskImager) described in the following link.
https://www.raspberrypi.org/forums/viewtopic.php?t=26463
This allows you to create a copy of the SD card in ann image (.img) file. This can then be compressed
using winzip/Zzip or any other zip utility to reduce the space on disk.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 6 - Installing the radio Software 107
Chapter 7 – Configuration
This section covers manual configuration of the radio. A number of programs are provided to help
with configuration. These are:
The above programs are found in the /usr/share/radio directory and are normally used to configure
the radio and audio output. The following descriptions cover manual configuration and those
configuration parameters not set by the above programs.
Parameter Explanation
fullscreen Set to yes or no. If using a large HDMI monitor or TV set to no.
window_title Title to display in the desktop window if fullscreen=no
window_color Window background colour if wallpaper (See below) not specified.
banner_color This is the colour of the time and date banner.
labels_color This is the colour of the radio and MPD option labels.
display_window_color This is the background colour of the station/track display window.
display_window_labels_color Colour of the display window text.
All parameters use the American spelling for color and not the British spelling.
The wallpaper parameter overrides the window_color parameter.
The parameters allow any theme to be configured for the HDMI or Touch Screen window.
All switches, rotary encoders and LCD display settings are configurable in the /etc/radiod.conf file.
If the GPIO assignments are changed in the /etc/radiod.conf file then these must
match the actual physical wiring for your radio project.
Configure the LED in /etc/radiod.conf for to pin 11 GPIO 23 for all versions except AdaFruit plate or
Vintage radio. For Adafruit RGB plate configure either remote_led=0 (No LED) or GPIO 13 (pin 33).
For the vintage radio use GPIO 23 (Pin 16). See the section called Remote Control Activity LED on
page 39.
The irradiod script calls the remote_control.py program. The activity LED should flash about six
times. If not then check that the remote_led parameter in the /etc/radiod.conf configuration file is
correctly set and that the activity LED is correctly wired (See LED wiring on page 39).
It is possible to change the date format (for example for the United States) by changing the format.
Some valid formats are:
%H:%M %m/%d/%Y US format
%H:%M %d-%m-%Y Minus sign as date separator
%d/%m/%Y %H:%M Reverse date and time
%H:%M %m%d Short date display for Olimex OLED
display_type=OLED_128x64
When running with the Cosmic controller OLED screen there are two relevant settings in the
/etc/radiod.conf file which are not set by the configure_radio.sh program.
The OLED display can be flipped vertically by setting the flip_display_vertically parameter to yes.
flip_display_vertically=yes
Note: If upgrading you will need to add this parameter to the [RADIO] section of the
/etc/radiod.conf file.
The three LEDs on the Cosmic Controller board are driven by the status_led_class.py program. This
class was originally written for the Vintage radio but is now also used with this board. Configure the
following parameters in /etc/radiod.conf as shown below:
rgb_red=14
rgb_green=15
rgb_blue=16
The left LED means an ERROR, the middle LED means NORMAL operation and the right-most is BUSY.
Note: Always use the American spelling ‘color’ in all commands and not the British spelling
‘colour’.
Alternatively, the radio can be configured to load a specific playlist. To display the available playlists
run the following command:
$ mpc lsplaylists
USB_Stick
_UK_stations
Beatles
_Radio
:
If you configure startup=RADIO the program will load the first available Radio playlist. Likewise if you
configure startup=MEDIA the program will load the first available Media playlist.
12:01 30/08/2017
WPJR Country
Lonestar – Mr. Mom
Volume 75
12:01 30/08/2017
WPJR Country
Lonestar – Mr. Mom
If the timer or alarm functions are being used then the volume display reverts back to
text display so as to allow display of the alarm or timer values.
The MPD daemon has a volume range from 0 to 100. The volume is incremented or decremented by
one each time the volume button is pressed or rotary encoder is turned a notch. This means a lot of
turns of the knob or pushes of the button to change the volume the full range. Also, different
devices are more sensitive than others.
For example, the Adafruit plate version allows very rapid change of the volume and the default
range of 0 to 100 is not a problem. The rotary encoder version of the radio requires a lot of twisting
of the volume knob to get from 0 to 100.
This volume_range parameter allows you to set the volume range to increase the sensitivity of the
volume control as shown below. For example, if the volume range is set to 20 you will see the
volume displayed from 0 to 20 however the MPD volume is incremented by 5.
The volume range is configured in /etc/radiod.conf configuration file using the volume_range
parameter:
Ideally you should choose a volume range number that divides into 100 equally as shown above
however other values will work.
$ cd /usr/share/radio
$ ./language_class.py
airplay: Airplay
alarm: Alarm
alarmhours: Alarm hours
alarmminutes: Alarm minutes
colour: Colour
consume: Consume
current_station: Current station
information: Information display
loading: Loading
loading_media: Loading media library
loading_radio: Loading radio stations
main_display: Main
media_library: Media library
menu_find: Find
menu_option: Menu option:
menu_search: Search
:
Now edit the text (Not the labels) in the language/language.nl file. It isn’t necessary to change every
message. Lines beginning with # are for any comments.
Finally copy the new language file to /var/lib/radiod/language (Omit the country code) and restart
the radio.
$ sudo cp language/language.nl /var/lib/radiod/language
$ sudo service radiod restart
The above is the RSS for the BBC news feed 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 comes with a valid BBC RSS feed file in the
/var/lib/radio/rss file. You can test the feed first by pasting it into your PC’s web browser URL and
pressing enter.
If configured, the RSS feed will be automatically displayed by stepping through the menus.
Note: The author of the radio software does not currently have a configuration that is
compatible with either Pulseaudio or Airplay. If you wish to use either Pulseaudio or Airplay
you cannot currently use the Alsa equalizer. This may change in a future release.
Amend the “device” parameter in the audio_output block in /etc/mpd.conf configuration file.
audio_output {
type "alsa"
name "IQAudio DAC+"
#device "hw:0,0"
device "plug:plugequal"
mixer_type "software"
}
In the above example we are using an IQaudIO card but may be any sound card.
Save the existing asound.conf file just in case you need to restore the original file
$ sudo cp /etc/asound.conf /etc/asound.conf.save
If your sound system is using card 1 (for example a USB audio device) then change the hardware
settings in the above configuration to use card 1.
:
type hw card 1
:
slave.pcm "plughw:1,0";
After reboot run the Alsa Equaliser as user mpd. It will not work if called as either user pi or root
(sudo).
$ sudo -H -u mpd alsamixer -c 0 -D equal
Use the Tab key to move along to the desired equalizer frequency to be changed. In this example, it
is the <2KHz> block. Use the up and down arrows to adjust the level. The settings are saved in the
/var/lib/mpd/.alsaequal.bin file. Changes to the sound should be heard.
Note: If you set a particular frequency value too high you will cause unpleasant distortion to
the sound output.
Note: This installation procedure is only for the HDMI or Touchscreen display of the radio. If
using an LCD display see Installing the Infra Red sensor software on page 91.
Click on the left-hand program icon (A Raspberry) and select Accessories. In Accessories select Flirc.
The following screen will be displayed. However, on a 7-inch touchscreen you may not be able to see
the whole FLIRC window. In this case use the procedure called Configuring FLIRC from the command
line on page 119. The first time you run this program it may ask you if you want to upgrade the
firmware (Version v4.4.2 at the time of writing).
On the Controllers drop down menu select the Full Keyboard controller.
Now map the buttons on the remote control to the keys shown in Table 16 Graphic screen keyboard
command on page 133. For example, press the letter m on the above keyboard and then press the
Mute button on the Remote Control. For volume control up press Shift key followed by the + key on
the keyboard, then press the volume up button on the remote control. Do the same with the – key
for volume down. Full instructions for configuring FLIRC are to be found at:
https://flirc.gitbooks.io/flirc-instructions/
If using a small touchscreen there may not be enough room to see the Flirc screen. If so do the
following:
$ flirc_util format
‘up’ is the name of the key. Now press the Channel Up key. The following will be displayed:
Successfully recorded button.
In the case of the + and – keys press shift first, followed by the + or – key.
Test and if necessary repeat key-mapping. If configuring on an HDMI Television do not configure
volume (+-) or mute (m) keys as the TV will provide these functions.
The configured keys can be displayed with the flirc_util keys command.
$ flirc_util keys
Recorded Keys:
Index hash key
----- --------- ---
0 7D14E297 down
1 ED385097 up
2 58C86297 right
3 41787497 left
4 BF8F6297 return
5 AB616762 r
6 2676D097 t
7 B6536297 c
8 9206E297 s
9 590C3E97 l
10 E8E8D097 p
11 C49C5097 a
12 F1EFD097 e
13 B9F03963 escape
14 D1F15097 pageup
15 53DA6297 pagedown
16 9F5BE297 escape
17 A8DDF497 left_ctrl Q
$ flirc_util delete_index 18
Re-test and repeat until a reliable ‘hash’ is received from the remote control.
If a key is multiply defined delete the first one you see by its index.
13 B9F03963 escape
14 D1F15097 pageup
15 53DA6297 pagedown
16 9F5BE297 escape
$ flirc_util delete_index 13
To display the status either use the program directly or use the sudo service radiod status
command:
$ sudo service radiod status
● radiod.service - Radio daemon
Loaded: loaded (/lib/systemd/system/radiod.service; enabled; vendor
preset: enabled)
Active: active (running) since Wed 2017-11-08 10:06:19 CET; 3h 55min ago
Main PID: 1619 (python)
CGroup: /system.slice/radiod.service
└─1619 python /usr/share/radio/radiod.py nodaemon
:
{The last relevant log entries will be displyed here}
The above shows the process ID of the radio, the Music Player Daemon version and operating
system details.
Mode = SEARCH
If source = RADIO Volume Up Volume Down Scroll up radio Scroll down radio
Line 1: Search: station station
Line2: Radio Station
Mode = SEARCH
If source = MEDIA Scroll up through Scroll down Scroll up Scroll down through
Line 1: Search artists through artists through track track
Line2:
MusicTrack/Artist
Mode = SOURCE
Line 1: Input Source: Volume Up Volume Down Cycle up Cycle down through
Line2: Radio or Media Mute Mute through Airplay, Radio and
playlist or Airplay Airplay, Radio Media playlists
and Media
playlists
Mode = OPTIONS
Line 1: Menu Toggle selected Toggle selected Cycle through Cycle through
Selection mode on or off. mode on or off. Random, Random, Consume,
Line 2: <option> Set timer and Set timer and Consume, Repeat, Reload Music,
Options are Random, Alarm Alarm Repeat, Reload Timer, Alarm Time
Consume, Repeat, Music, Timer, Set and Streaming:
Reload Music, Timer, Alarm , Alarm
Alarm ,Alarm Time Time Set and
Set (Hours), Alarm Set Streaming
(Minutes), Streaming:
Mode = TIME
Line 1: Time Volume Up Volume Down Station/Track up Station/Track down
Line 2: Station or Track
Mode = SEARCH
If source = RADIO Volume Up Volume Down Scroll up radio station Scroll down radio
Line 1: Search: station
Line2: Radio Station
Mode = SEARCH
If source = MUSIC Scroll up Scroll down through Scroll up through track Scroll down through
LIBRARY through artists track
Line 1: Search artists
Line2:
MusicTrack/Artist
Mode = SOURCE
Line 1: Input Source: Volume Up Volume Down Cycle up through Cycle down through
Line2: Radio or Media Mute Mute Airplay, Radio and Airplay, Radio and
playlist or Airplay Media playlists Media playlists
Mode = OPTIONS
Line 1: Menu Selection Toggle Toggle selected mode Cycle through Random, Cycle through
Line 2: <option> selected on or off. Set timer Consume, Repeat, Random, Consume,
Options are Random, mode on or and Alarm Reload Music, Timer, Repeat, Reload
Consume, Repeat, off. Set timer Alarm Time Set, Music, Timer, Alarm ,
Reload Music, Timer, and Alarm Streaming and Alarm Time Set,
Alarm and Alarm Background colour(1) Streaming and
Time(Hours), Alarm Background colour(1)
Time(Minutes) set and
Change colour(1),
Streaming on/off.
Note 1: The colour change option is only available for the AdaFruit RGB plate
(ada_radio.py). Note 2: If the /var/lib/radiod/rss file is missing or contains an invalid
RSS URL then the RSS mode is skipped.
To start the radio from command line run the gradio.py program:
$ cd /usr/share/radio
$ sudo ./gradio.py &
In all cases a screen similar to the following will be displayed. In this example fullscreen=no.
Date
Banner Display
window
Search
Search
Up
Options
First
page
Search
window Search
slider
Last
page
MPD
Options
Search
Down
Clicking the mouse on a control such as station Up/Down or touching it do the same thing. In the
following description we will only refer to “clicking”. By this, also touching a control is also meant.
The display window normally displays the Radio station or Media rack that is currently playing.
Clicking in the display window changes the third line to display the RSS feed if configured. A second
click in the same window displays version details, IP address and hostname.
In this example the hostname is ‘stretch’. The version number will be different for later releases.
Two IP addresses are displayed (Wireless and Ethernet).
Click on a station in the list selects it. Clicking in the slider window or dragging the slider re-positions
the list. The current position, 16 in this example, is displayed next to the slider. The length of the
current playlist, 28 for this playlist, is displayed at the bottom of the slider window.
Clicking on the Up and Down arrows travels up and down the list. Clicking on the left double arrow
goes to the first page in the list. Clicking on the right double arrow goes to the last page in the list.
In the following example the USB stick playlist was selected. Once a playlist selected the list is
displayed.
Clicking the Artists radio button displays the list of artists in the search window. Once clicked the
search window positions on the first song of that artist’s tracks.
Note that if you click on the ‘Artists’ radio button when displaying Radio stations, it will always be
forced back to the ‘List’ display as Artist selection is not relevant for Radio stations.
Search
list type
The search list type (Playlist, Station/Track list or Artist) is cycled through by clicking on the Search
list type button. All other controls work the same as shown in Figure 150 on page 127.
Artwork display
If the music track has artwork and the ffmpeg (See Setting up the locale on page 65) package has
been installed then the artwork will be displayed. Clicking on any of the radio search buttons will re-
display the search window. The artwork cannot be displayed until the track is re-selected.
Note that the two grey push buttons now display ‘Track Up/Down’ instead of ‘Station Up/Down’.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 8 - Operation 130
Volume and Mute controls
The volume is controlled by a slider at the bottom left of the
window. Clicking on the loud-speaker at the bottom of the
screen mutes the sound and displays the mute icon as shown
on the left. Any volume control change un-mutes the radio.
Source selection
Click on the down arrow on the right of the Source selection to
select the Source namely Radio, Media, Airplay or Spotify. The
radio will select the first playlist in that source. Re-selecting the
same source will select the next playlist for that Source.
Airplay must first of all be installed on the Raspberry Pi. See Chapter 12 - Setting up Airplay on page
192 for instructions how to do this. To select Airplay either select it from the Sources drop-down box
or from the playlists in the search window.
Connect to the Raspberry Pi from an Airplay compatible mobile device or run an App such as
CloudBreak. The hostname to connect to is displayed when Airplay is first opened in the Display
Window as shown below:
One good personalisation is to use your own favourite holiday picture as the background.
wallpaper=<path to your photograph>
Window and label colours can be changed to your own preferences. In the above screen the
wallpaper option has been disabled, so the window_color option is used.
# Graphics (touch screen) screen settings
[SCREEN]
fullscreen=yes
window_title="Bob Rathbone Internet Radio Version"
window_color=turquoise
banner_color=black
labels_color=black
display_window_color=lightblue
display_window_labels_color=black
slider_color=purple
display_mouse=yes
switch_programs=yes
screen_saver=0
You may be interested how the screen-shots in this section were created. A Windows based
server called XMing was run on the Windows PC. X-Forwarding is then enabled in the SSH
program (Putty or Bitvise etc). A SSH terminal session was started and the gradio.py program
started which is then displayed on the PC desktop. Then clicking on the graphic radio window at
pressing Alt and PrtScn keys together copies the window to the system clip-board where it can be
pasted into a document. Operation is however very sluggish so the method is not recommended for
normal use.
As an alternative to the gradio.py program there is a touch-screen version of the radio called
vgradio.py. This radio program only can play radio stations and not other Media (USB stick for
example) or Airplay.
Note: This radio program can only play radio stations and not other Media such as a USB
stick or Airplay, nor are there currently any plans to change this. If you want to play media
you will need the full feature gradio.py program previously described.
This allows a radio to be constructed to look like a vintage radio with a sliding tuning dial.
The pages scroll through the stations so hundreds of stations can be added.
When you touch the name of a station on the tuner dial the green slider jumps to that location and
plays the selected station.
The double arrows at the top of the of the screen allow you to page through the stations.
At the bottom is the round volume slider. Under that is the title of the currently playing song.
The blue arrows are used to step through the stations one at a time.
The mute button is on the right-hand side of the screen. This design can also be combined with
rotary encoders or switches.
To run this radio, either run the configure_radio.sh program or amend the
/home/pi/.config/lxsession/LXDE-pi/autostart configuration file to run vgradio.py instead of
gradio.py.
This radio is designed to work with a single radio playlist. This is normally the _Radio playlist. You
should configure the radio to start with this playlist by amending the startup parameter in
/etc/radiod.conf.
However, this does not mean that you cannot have multiple radio playlists. If you have more than
one radio playlist then by using the page up button (Double right arrow) it is possible to scroll
through to the current playlist to the end and then onto the next playlist. In this case the new
playlist name will be displayed in the very top-left of the screen.
You cannot currently scroll back to the previous playlist but must continue scrolling through the
pages until you reached the desired playlist.
If using the FLIRC remote control dongle then it is only necessary to program the following keys:
pageup, pagedown, left, right, up, down.
switch_programs=yes
Restart the program. The switch icon on the left will appear towards the top of the
right-hand side of the screen. By clicking on it the program will switch between the
two versions of the desktop radio programs. There will be a very short pause in the
music stream whilst it is doing the switch-over.
Note: The xscreensaver program described here does not appear to work if the radio
program is in full screen mode. This will probably be addressed in a later release.
Modern LCD displays are not as susceptible to screen burnout as the old cathode ray tubes of old.
However continuous static screen displays will eventually cause shadowing. It is therefore a good
idea to install a screen saver. The standard one for Raspian is called xscreensaver. To install it run
the following:
$ sudo apt-get install xscreensaver
After installation of the screen saver it can be configured in the desktop preferences menu. This
allows configuration of time, screen saver or a blank screen. Choose a not too busy screen saver or
the blank screen option.
There is also a program called xscreensaver-command for command line manipulation of the screen
saver. However, the advice is not to use it as, at the time of writing, it causes severe problems with
both the console and desktop display.
Playlists for all of the above can be created using the the create_playlist.sh program.
$ cd /usr/share/radio
$ sudo ./create_playlist.sh
See the section on Creating Media playlists on page 143 for a detailed description of this program.
$ mkdir /home/pi/mymusic
Using FTP, copy the music from a PC to the /home/pi/mymusic directory and reload the library via
the options menu. Now run the create_playlist.sh program.Select option 3 (SD card).
In the above example the first directory is set up with the artist name and this will appear in the
search. The next directory “The 50 Greatest Hits Disc 1” is not used by the search routines. The file
name “That's All Right.mp3” without the mp3 extension becomes the track name in this example.
There are six levels of logging namely CRITICAL, ERROR, WARNING, INFO, DEBUG or NONE.
This is configured in the /etc/radiod.conf file.
# loglevel is CRITICAL,ERROR,WARNING,INFO,DEBUG or NONE
loglevel=INFO
There are some other configuration and status files in the /var/lib/radiod directory. These are:
It isn’t normally necessary to change most of these files. However, the stationlist, share, language
and rss file will need to be edited as required. The other files are maintained by the radio or
configuration programs. When the radio program starts up the it uses the last settings, for example,
the volume setting.
There is a timer (Snooze) and alarm function (LCD and OLED versions only). The timer and alarm can
operate individually or together. The timer when set will put the radio into Sleep Mode when the
timer expires. The Alarm can be set to either On, Repeat or “Weekdays only”.
On a four line LCD display the timer will be seen counting down after the Volume display on line 4.
On a two line LCD display the timer count down will be displayed on line 1 after the time display.
When the timer expires (reaches zero) the radio will enter SLEEP mode. Sleep mode can only be
exited by pressing the menu button.
To switch the timer off go back to the timer menu as described above and reduce the timer to 0
using the volume DOWN control. This will switch off the timer.
The timer function uses the /var/lib/radiod/timer file which will contain the value of the timer in
minutes when it was successfully fired. You do not need to change the contents of this file.
Press the Menu button until the “Menu Selection” is displayed. Press either the channel UP or
DOWN (Or rotate rotary encoder) until “Alarm off” is displayed on line 2 of the LCD screen. Using
the volume UP control cycle through the options which are
Now move to “Set alarm time:” using the channel UP control. The current alarm time will be
displayed on line 2 of the display. Using the volume UP and DOWN control adjust the alarm time
(Hours or Minutes) to the required setting. If you do not wish to put the radio into sleep mode at this
stage then use the channel UP/DOWN control to move away from the “Set alarm time:” option and
Bob Rathbone |Raspberry PI Internet Radio - Chapter 8 - Operation 138
press the Menu button. If you press the Menu button whilst in the “Set alarm time:” option and the
Alarm is set to anything except off then the radio will enter Sleep mode and display the alarm on line
2 for a two-line LCD or on line 4 for a four-line LCD.
Note: Sleep mode can only be exited by pressing the Menu button.
The alarm function uses the /var/lib/radiod/alarm file which will contain the current alarm type and
time. The format is t:hh:mm where t is type (0=off, 1=on, 2=repeat, 3=weekdays only) and hh:mm is
hours and minutes (24 hour clock). You do not need to change the contents of this file.
PLEASE NOTE THAT THE ALARM RELIES UPON THE SELECTED RADIO STREAM TO BE
AVAILABLE WHEN THE ALARM WAKES UP. THIS CANNOT BE GUARANTEED AS THE STATION
FEED MAY BE OFF AIR OR THERE IS A PROBLEM WITH THE INTERNET CONNECTION. YOU SHOULD
NOT THERFORE RELY SOLEY ON THIS ALARM FUNCTION IF YOU HAVE AN IMPORTANT
APPOINTMENT OR A PLANE OR TRAIN TO CATCH FOR EXAMPLE. ALSO SEE DISCLAIMER ON PAGE
211.
Log into the Raspberry PI using the console or SSH login. To start playing music run:
$ mpc play
Previous versions of the radio only allowed three playlists namely Radio, USB stick or Network share.
This has completely changed in version 6.0 onwards. It is now possible to define as many playlists as
you wish. For example:
The directories and files used by the create_stations.py program are shown in the following table:
The /var/lib/radiod/stationlist file is the file that should be maintained by you to create Radio
playlists. When this create_stations.py program is first run it copies the distribution file station.urls
to the /var/lib/radiod/stationlist file. You may then modify the /var/lib/radiod/stationlist file.
The above will create a playlist called _Radio.m3u and will contain the title and URLs for each
station. Now add or remove radio station definitions in the stationlist file. The first statement in the
station definition is the name of the playlist in brackets:
After modifying the stationlist file run the create_stations.py program to create the Music Player
Daemon playlists.
In the above example two Radio playlists are defined by the names in round brackets namely;
(Radio) and (Dutch radio).
The create_stations.py program itself is very easy to use. Just run it with sudo in the
/usr/share/radio directory:
$ cd /usr/share/radio
$ sudo ./create_stations.py
This will create the playlist files in the /var/lib/mpd/playlists directory. Using the example shown
above this will produce two files called _Radio.m3u and _Dutch_radio.m3u in the MPD playlists
directory. To create a log file of the program run the following:
$ sudo ./create_stations.py | tee playlist.log
You can examine the playlist.log file to see what actions the create_stations.py program carried out
and if there were any errors.
The program will ask if you wish to delete any old playlists:
Processed 46 station URLs from /var/lib/radiod/stationlist
There are 2 old playlist files in the /var/lib/mpd/playlists/ directory.
Do you wish to remove the old files y/n: y
Normally answer ‘y’ unless you don’t wish to remove the old files. Note that old playlists files with
the same name as the new ones will always be overwritten.
If you want to avoid the above prompt then there are two other parameters that you may use.
--delete_old Delete old playlist files in the MPD playlist directory
--no_delete Don’t delete old playlist files in the MPD playlist directory
Example:
$ sudo ./create_stations.py --no_delete
The program will suggest a name for the playlist but you may choose any name (But do not make it
too long).
===========================================================
58 tracks found in directory media (No filter)
mv /tmp/USB_Stick.m3u /var/lib/mpd/playlists/USB_Stick.m3u
sudo service mpd start
mpc stop
volume: 58% repeat: off random: off single: off consume: off
mpc update media
Updating DB (#1) ...
volume: 58% repeat: off random: off single: off consume: off
This will filter all songs from ZZ Top, The Beatles and Elvis or any other titles that contain these
names. However this may not be want is wanted. Maybe songs by Elvis are wanted and not songs
with ‘Elvis’ in the title. For example Dire Straits – Calling Elvis. In such a case use the / character to
only look for directory names beginning with ‘Elvis’ . The above filter becomes:
ZZ Top|Beatles|/Elvis
Restart the radio to reload all new playlists. Using the / character gives a more accurate playlist.
Please note that filters are not case sensitive. Filter ‘Elvis’ and ‘elvis’ will return the same result.
If you selected option 3 (SD card) you will be prompted for the location where you have installed you
music files. This location must pre-exist and have music files.
From version 6.5 onwards it is possible to create playlists from the Shoutcast database. See
http://www.shoutcast.com. Shoutcast provide what can best be described as “fringe” radio stations.
They do have a few stations by country but not many. If you are hoping, for example, to get all the
United Kingdom BBC radio stations you will be disapointed. However their support for radio stations
by genre is very good, for example: rock, jazz, country or classical. This version of software provides
two methods of creating playlists from the Shoutcast database:
Running the program with no parameters will produce the following usage message:
$ cd /usr/share/radio
$ ./get_shoutcast.py
This program must be run with sudo or root permissions!
If you see the following message then install python-requests as shown in the section called Install
python-requests on page 67.
Traceback (most recent call last):
File "./get_shoutcast.py", line 19, in <module>
import requests
ImportError: No module named requests
The program must be run with sudo. In the following example we want to get fifty jazz stations.
$ sudo ./get_shoutcast.py genre="jazz" limit=50
Extracting shoutcast stations: genresearch
Processing URL:
http://api.shoutcast.com/legacy/genresearch?k=anCLSEDQODrElkxl&limit=50&genr
e=jazz
Abc Lounge
Smoothjazz.com Global
:
:
Created 50 records in /usr/share/radio/playlists/_jazz.m3u
Do you wish to copy this playlist to /var/lib/mpd/playlists [y/n]: y
This will copy the new _jazz.m3u playlist to the /var/lib/mpd/playlists directory. The program will
also signal the radio program to reload its playlists so that the new playlist can be accessed straight
away.
If you answer ‘n’ to the above question your new playlist will be saved in /usr/share/radio/playlists
repository. You can copy it later, if so wished, to the MPD playlists directory.
$ cd /usr/share/radio/playlists
$ sudo cp _jazz.m3u to /var/lib/mpd/playlists
The program requires an authorisation key. This is embedded in the program and it is not necessary
to specify it. If it ever changes or expires a new authorisation key must be configured in
/etc/radiod.conf.
shoutcast_key=anCLSEDQODrElkxl
Note: Access to the Shoutcast is a free service made available through the goodwill of the
folks at Shoutcast. It can be withdrawn at any time if over-used or abused so please do not
set up any facility, such as scripting, which will stress their servers.
The radio web interface now has a Shoutcast tab. Click on Shoutcast tab to open the interface. Fill in
the search form and press the Submit button once and wait until the summary page is displayed.
The summary page will be displayed. You should see the Reload playlists: OK message which means
that the new playlist is available in the radio.
If you find upon running the Radio that you have a lot of radio playlists. Reduce the number by
removing title statements in the stationlist file as previously mentioned. These are the names in
brackets – for example (BBC Radio). Re-run the create_stations.py program.
http://www.listenlive.eu http://www.publicradiofan.com
http://bbcstreams.com/ http://www.radiofeeds.co.uk/
Copy and paste the URL into the /var/lib/radiod/stationlist file. Add the title in square brackets as
shown in the previous section. Other browsers may provide options such as ‘copy link’or ‘save link
as’. This is browser dependant.
1. A URL pointing to a M3U playlist file (MPEG3 URL). This format is used by MPD.
2. A URL pointing to a PLS playlist file (Shoutcast Play List)
3. A URL pointing to an ASX playlist file (Advanced Stream Redirector)
4. A URL which is an actual stream such as MP3 (MPEG 3) or AAC (Advanced Audio Coding)
1, 2 and 3 are so called redirector URLs and point to a playlist file containing one or more URLs to the
radio stream(s) itself. The create_stations.py program tries to figure out what type of URL that it is
and create a playlist from it. This is the facility you should use rather than trying to create your own
playlists which can be quite time consuming.
M3U Files
M3U stands for MPEG3 URL. This is the format that MPD itself uses. The following Wikipedia article
explains the M3U file format:
http://en.wikipedia.org/wiki/M3U
The Music Player Daemon uses m3u files. An example M3U file is shown below:
radio10.m3u playlist file
#EXTM3U
#EXTINF:-1, Radio 10 Gold NL
http://icecast.streaming.castor.nl:80/radio10
These playlist files have the m3u file extension. i.e. <filename>.m3u. The first line is the header and
must be #EXTM3U. The second line is #EXTINF: and is information about the radio stream. The -1
means unlimited play length. This is followed by a comma and then the name of the radio station
(Radio 10 Gold in this case). The third line is the URL (icecast in this case) for the radio stream. More
than one radio stream may be defined in the m3u file. You do not need to create this type of file
yourself. Modify the stationlist file and run create_stations.py.
M3U files may also contain a simple list of file paths to media files. For example:
media/Steve Miller Band/Album onbekend/0726 Steve Miller Band - The
Joker.mp3
media/Stories/Album onbekend/Stories - Brother Louie.mp3
:
In this version of the radio the program knows that these are media files as opposed to radio
playlists because they do not start with an underscore ‘_ ‘ which is the convention that the radio
program uses for a radio playlist (It is not a general convention).
Note that in the above example media is a directory (or a link to it) in the /var/lib/mpd/music
directory and that the ‘/’ character is omitted.
http://en.wikipedia.org/wiki/PLS_(file_format)
[playlist]
NumberOfEntries=2
Version=2
File1=http://206.217.213.16:8430
Title1=Blues Radio UK
Length1=-1
File2=http://205.164.62.13:8030
Title2=Absolute Blues Hits
Length2=-1
The PLS file always starts with the [playlist] statement. The NumberOfEntries statement must match
the number of streams defined in the PLS file (Two in the above example). Set the Version number
always to 2. There is a Filen, Titlen and Lengthn where n is the entry number.
ASX file
The Advanced Stream Redirector (ASX) format is a type of XML metafile designed to store a playlist
of Windows Media files for a multimedia presentation. An example ASX file is shown below.
<ASX version="3.0">
<ABSTRACT>http://www.bbc.co.uk/iplayer/radio/bbc_radio_bristol/</ABSTRACT>
<TITLE>BBC Bristol</TITLE>
<AUTHOR>BBC</AUTHOR>
<COPYRIGHT>(c) British Broadcasting Corporation</COPYRIGHT>
<MOREINFO
HREF="http://www.bbc.co.uk/iplayer/radio/bbc_radio_bristol/" />
<PARAM NAME="HTMLView"
VALUE="http://www.bbc.co.uk/iplayer/radio/bbc_radio_bristol/" />
<Entry>
<ref href="mms://wmlive-
nonacl.bbc.net.uk/wms/england/lrbristol?BBC-
UID=1523a2f20f858eb0ba0a4385918e6433df886bb650e021b4446ff486f8204e3a&SSO
2-UID=" />
</Entry>
</ASX>
http://mp3.streampower.be/radio1-high.mp3
http://7639.live.streamtheworld.com:80/977_MIX_SC
You can determine if a URL is a direct radio stream by using the wget program.
# cd /tmp
# wget http://mp3.streampower.be/radio1-high.mp3
--2014-03-14 13:08:10-- http://mp3.streampower.be/radio1-high.mp3
Resolving mp3.streampower.be (mp3.streampower.be)... 80.200.255.61
Connecting to mp3.streampower.be (mp3.streampower.be)|80.200.255.61|:80...
connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [audio/mpeg]
[ <=> ]
365,281 15.8K/s
If wget doesn’t exit and you see the <=> characters moving backwards and forwards then it is a URL
to the radio stream itself. You will also see Length: unspecified in the output. Press control -C to exit
wget. Remove the file that wget created (/tmp/radio-high.mp3 in this case).
Not only do these streams provide the live ATC conversations but also the in the station information
ATIS (Aerodrome Terminal Information Service). This consists of coded weather information which
all pilots can understand.
One way to add these stations to a radio playlist is to install WinAmp on a PC. Enter either the ICAO
or IATA code of the station in the search box on the Live ATC web site, for example EHAM or AMS
(Schiphol, Amsterdam, the Netherlands) .
Click on the MP3 player LISTEN option. The station will be loaded and shortly WinAmp will start
playing the stream.
Right click in the top left box (Display elapsed time of 1:05 in this example). The station information
will be displayed.
The URL for the stream is shown in the top box. http://d.liveatc.net/eham03_rdr_e_inb
The stream name is: EHAA Radar Sector 2 East Inbound
The station Title shows the ATIS information.
EHAM 130955Z 25016KT 9999 FEW020 BKN024 19/14 Q1021 NOSIG
Using the URL shown create a playlist to /var/lib/radiod/stationlist for the live traffic ATC as shown
in the following example.
Now restart the radio or use the menu to reload the radio stations (Select source option):
$ sudo service radiod restart
The protocol used for CIFs is SMB (Server Message Block – Microsoft). Previously connections to
SMB was via a product called SAMBA but has been largely replaced by the mount using the CIFS
option in the Linux. The steps to mount the network drive are as follows:
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.
Don’t 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.
-o username=guest,password=guest,uid=pi,gid=pi,sec=ntlm
Many NAS devices use older technology so they often only use ntlm authentication. There are other
authentication methods such as ntlmv2 but most are not currently supported with the Raspberry Pi
OS.
A few things to note here; the NFS mount command uses the volume name (volume1 – can vary),
The CIFS mount command doesn’t. 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.
The important thing apart from seeing the files is that you should see that the files are owned by pi
and group pi.
Note: If you decide to directly edit the /var/lib/radiod/share file instead of using the above
command then do not include quotations marks around the command.
Now press the Menu button. The program loads whatever playlists it has in its database, and will
most likely be only those from the USB stick if installed. However the playlist for the new share files
are not yet in the MPD database. The playlist needs to be updated in the following section.
Now press the Menu button. This will cause the MPD database to be 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).
Mount points
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. You may also see
a link called sdcard to the location of the music library on the SD card.
$ ls -la /var/lib/mpd/music/total 8
drwxr-xr-x 2 root root 4096 Jul 7 12:37 .
drwxr-xr-x 4 mpd audio 4096 Apr 7 11:02 ..
lrwxrwxrwx 1 root root 6 Jul 7 12:17 media -> /media
lrwxrwxrwx 1 root root 16 Jul 7 12:37 sdcard -> /home/pi/mymusic
lrwxrwxrwx 1 root root 6 Jul 7 12:17 share -> /share
These links are created automatically by the Radio program. If these are missing they can be re-
created with the ln -s command.
$ cd /var/lib/mpd/music
$ sudo ln -s /media
$ sudo ln -s /share
$ sudo ln -s /home/pi/mymusic sdcard
This shouldn’t normally be necessary as the links are created by the program when it creates the
media and share mount points.
MPDdroid allows you to control a MPD server (Music Player Daemon) and stream from it. It is a fork
from an earlier program called Pmix and adds various new features and streaming support. The
radio daemon is completely integrated with MPD clients such as mpc and MPDdroid
Load the MPDdroid App use the Keep pressing the back To switch to the play list drag
Google Play Store on your device. button to exit and then re- the play screen to the left.
Go to the settings menu and select start the MPDdroid App. The The current station list or
WLAN based connection. Select play screen should be play list will be displayed. Tap
Host and fill in the IP address of the displayed as shown below. on the desired station or
radio and press OK. Set up the Volume, pause, fast track to play it. Drag the play
Streaming url suffix to mpd.mp3. forward/back can all be screen to the right to return
controlled from this screen. to the play screen.
All other settings can be left at their
defaults.
Apple devices
Download mPod – MPD Remote Control Software from the Apple store or at following link:
http://antipodesaudio.com/mpd.html . Run mPod, it will automatically find the Raspberry Pi
running the Music Player daemon.
Installation problems
The Raspberry Pi will not boot
This is always worrying if this happens but doesn’t always mean that the situation is irrecoverable. It
often indicates a SD card corruption problem. Connect the HDMI output of the Raspberry Pi to the
HDMI input of a TV set and attach a USB keyboard. Reboot the Pi. If you see the following:
[....] An automatic file system check (fsck) of the root filesystem failed.
A manual fsck must be performed, then the system restarted. The fsck should
be performed in maintenance mode with the root filesystem mounted in read-on
[FAIL] ... failed!
[warn] The root filesystem is currently mounted in read-only mode. A
maintenance shell will now be started. After performing system maintenance,
please CONTROL-D to terminate the maintenance shell and restart the system.
... (warning).
sulogin: root account is locked, starting shell
root@raspberrypi:~#
With Raspbian Stretch you may are asked to press enter which brings up the dollar $ prompt
Cannot access console, press enter to continue
$
When reboot has finished you will be asked to enter the root password you just entered which will
take you to the # prompt.
This will, with luck, correct the file system. When fsck has finished reboot the system. Once
rebooted use vi or nano to modify /etc/default/rcS. Add the following line to /etc/default/rcS.
# automatically repair filesystems with inconsistencies during boot
FSCKFIX=yes
To correct this first install the missing packages as shown in the section Music Player Daemon
Installation on page 69. Now run the following:
$ sudo apt --fix-broken install
If you see this enter a Y to install the new file unless you have a good reason not to do so.
If it is not starting on reboot then re-run the configure_radio.sh program as shown in the section
Configuring the radio on page 70. Select the option to start the program at boot time.
Sound is heard but the graphical radio program will not start
This is almost certainly due to the fact that the radiod service is running. Either re-run the
configure_radio.sh program to reconfigure or run the following commands.
$ sudo systemctl stop radiod
$ sudo systemctl disable radiod
Check the audio jack cable first before doing anything else.
The /var/log/mpd/mpd.log file is the place to look first if all other things seem normal.
Remove the pulseaudio package unless required for Bluetooth audio devices.
Re-run the configure_audio.sh program as shown in the section Configuring the audio output on
page 79. You must do this to configure MPD to work with pulseaudio.
If using the onboard audio output there should not be a problem. The standard /etc/mpd.conf
settings should be OK. Only if pulse audio is not removed or the Alsa mixer volume is not set can it
lead to lack of sound. See Music Player Daemon Installation on page 69.
This is due to that an update was not previously carried out as shown in the section called SD card
creation on page 58. Perform the update and upgrade as shown and re-install MPD and MPC.
If this message is seen in the MPD log file this is simply because IP version 6 (IPv6) isn’t installed so
the message doesn’t affect operation of the MPD.
To prevent it from happening configure the bind_to_address parameter in the /etc/mpd.conf file to
“any”. The installation procedure should normally set this anyhow.
Change the zeroconf_enabled parameter in the /etc/mpd.conf file to “no” . This is normally set in
the radio package installation procedure. 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.
LCD Problems
LCD screen not showing anything
Check that the wiring conforms to the wiring list on page 15. Make sure that pin 3 is grounded (0V)
to give maximum contrast or if a contrast potentiometer is fitted then make sure it is at the
maximum setting. Make sure the correct Radio variant has been selected. Re-run the
configure_radio.sh program as shown in the section Configuring the radio on page 70.
Run the test_lcd.py program to see if the LCD displays anything. This runs independently of any
other software and can be used stand alone. Run the wiring.py program (See page 176).
Check the wiring conforms to the wiring list on page 15. In particular check the data lines to pins 11,
12, 13 and 14 (See LCD wiring on page 22). Retest the LCD using the test_lcd.py program.
If the wiring is correct run the configure_radio.sh script to select the correct revision of the board
and restart the program. Run the wiring.py program (See page 176).
Cause: There are no playlists found in /var/lib/mpd/playlists. Check to see if there are any playlists
in /var/lib/mpd/playlists. You should see files with the m3u extension.
$ ls /var/lib/mpd/playlists/
_Air_traffic.m3u Network.m3u _Radio.m3u USB_Stick.m3u
If no m3u playlist files are present then run the create_stations.py program.
The cause is that the python-smbus package has not been installed as shown in the section Installing
the Python I2C libraries on page 80.
The python-pil package has not been installed as shown in the section Install libraries for the Olimex
OLED on page 67.
This is due to the Raspberry Pi being unable to operate with the default speed of the SPI bus. Edit
spi.py program file as shown in the section Installing PiFace CAD software on page 82. Also update
the RPi firmware by running rpi-update.
If the above is seen then the libraries for the Olimex display have not been installed. Carry out the
instructions as shown in the section called Install libraries for the Olimex OLED on page 67.
If the problem is not missing libraries check wiring and connections to the OLED as these can be
easily damaged.
Button problems
This section applies to push button radios only.
This is due to an invalid URL (In the above example this is http://173.244.194.212:8078) in one of the
M3U files. Locate the offending URL in the play list file in the /var/lib/radiod/stationlist file. Either
correct the radio stream URL or remove it all together. Re-run the create_stations.py program. Also
check that the file URL is not the pointer to the playlist file (See section Creating and Maintaining
Playlist files on page 140.
Error:
mount.nfs: rpc.statd is not running but is required for remote locking.
mount.nfs: Either use '-o nolock' to keep locks local, or start statd.
mount.nfs: an incorrect mount option was specified
Cause:
You need to include the “–o noclock” option.
If the error isn’t in the above list then search the web for suggestions.
Sound problems
Noisy interference on the radio
If there is noise interference when playing the radio and this is still present even when the radio is
muted this can be for several reasons. This can happen with a wired Ethernet connection and a Wi-Fi
dongle are connected to the Raspberry Pi and the Ethernet activity is being picked up by the Wi-Fi
dongle. This can be cured by using either a wireless adapter or the Ethernet connection and not
both. Another common cause can be an inadequate power supply. See on Power supply
considerations on page 25. Unfortunately, the later 40 pin versions of the Raspberry Pi seem to be
more prone to interference. The recommendation is to use a USB DAC or a suitable DAC card.
This will stop MPD starting at boot time. Starting of the MPD daemon is completely controlled by the
radio software. The radio package installation procedure now automatically disables the Music
Player Daemon at boot time.
<date> : mixer: Failed to set mixer for 'My ALSA Device': failed to set ALSA
volume: Invalid argument
If problems are experienced with your USB device (Tenx Technology for example) then add the
mixer_type “software” parameter to the /etc/mpd.conf file.
audio_output {
type "alsa"
name "MyUSB DAC"
device "hw:0,0" # optional
format "44100:16:2" # optional
#mixer_device "default" # optional
#mixer_control "PCM" # optional
#mixer_index "0" # optional
mixer_type "software" # Add this line for USB devices
}
Check first if the card is visible using the aplay command. The DAC card should be visible.
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry
DAC+ HiFi pcm512x-hifi-0 []
Subdevices: 0/1
Subdevice #0: subdevice #0
If using version 5.6 or earlier the onboard devices will be seen as shown below.
# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
:
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry
DAC+ HiFi pcm512x-hifi-0 []
Subdevices: 0/1
Subdevice #0: subdevice #0
The reason is that the configure_audio.sh in version 5.8 onwards disables the on-board devices by
changing the dtparam in /boot/config.txt to off:
dtparam=audio=off
Re-run the configure_audio.sh program as shown in the section Configuring the audio output on
page 79.
Make sure that the /boot/config.txt file contains the following line.
dtoverlay=hifiberry-dacplus
If your card is configured as card 1 (Run aplay -l to determine this) then amend the device statement
to 1 as shown below. This is most likely if using a USB sound dongle.
device "hw:1,0"
The mixer volume ID can be identified as shown in the following command example.
$ amixer controls | grep -i volume
:
numid=4,iface=MIXER,name='Mic Playback Volume'
numid=8,iface=MIXER,name='Mic Capture Volume'
numid=6,iface=MIXER,name='Speaker Playback Volume'
Operational problems
Radio daemon doesn’t start or hangs
This is almost certainly a problem with either the MPD daemon or failed internet connection. Check
the network connection and run installation tests on the MPD daemon. Occasionally a bad playlist
file can also cause this problem. You can check that your Raspberry PI has an internet connection
with the ip addr command. The example below shows interface eth0 connected as IP 192.168.2.22.
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
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.22/24 brd 192.168.2.255 scope global eth0
Remove the # at the beginning of the line to enable software mixing and save the file. Restart the
radio software.
Note: This solution was provided by one of the constructors and is untested by the author.
This is because the existing /etc/lirc/lircd.conf has not been moved out the way. Run the following
command:
$ sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd.conf.org
See the instructions in the section called Installing the Infra Red sensor software on page 91.
Make a note of the pid (in this example it is 13299). Operate the volume up and down. The following
should be displayed:
KEY_VOLUMEUP
KEY_VOLUMEDOWN
To stop the program run using the previously noted pid (13299).
$ sudo kill -9 13299
A number of other programs are supplied and can also be used for diagnostics.
• display_model.py Display Raspberry Pi model information
• display_current.py Display current station or track details
• wiring.py Display wiring as configured in /etc/radiod.conf
All diagnostic programs are supplied in the /usr/share/radio directory. Change to this directory first!
$ cd /usr/share/radio
All programs require the ./ characters in front of the name to execute unless called by their full
pathname. All of those using the GPIO interface also require to be called with sudo.
The above program will display the following text on the LCD:
Bob Rathbone
Line 2: abcdefghi
Pressing the switches should show on the screen as shown in the above example.
$ sudo ./rotary_class.py
Test rotary encoder Class
Left switch GPIO 14
Right switch GPIO 15
Up switch GPIO 24
Down switch GPIO 23
Mute switch GPIO 4
Menu switch GPIO 17
Tuner event 1 CLOCKWISE
Tuner event 2 ANTICLOCKWISE
Volume event 1 CLOCKWISE
Volume event 2 ANTICLOCKWISE
Tuner event 4 BUTTON UP
Tuner event 3 BUTTON_DOWN
Volume event 4 BUTTON UP
Volume event 3 BUTTON_DOWN
Volume event 1 CLOCKWISE
Volume event 2 ANTICLOCKWISE
$ ./display_current.py
id: 32
pos: 7
name: Blues Radio UK
file: http://206.217.213.16:8430
title: 04 Billy Jones Blues - I'm A Bluesman
current_id 8
Status
songid: 32
playlistlength: 25
playlist: 31
repeat: 0
consume: 0
mixrampdb: 0.000000
random: 0
state: play
xfade: 0
volume: 75
single: 0
mixrampdelay: nan
nextsong: 8
time: 22:0
song: 7
elapsed: 22.400
bitrate: 96
nextsongid: 33
audio: 32000:24:2
uptime: 28
db_update: 1400354144
artists: 228
playtime: 23
albums: 132
db_playtime: 302046
songs: 1297
To find out the exact meaning of all these fields please refer to the standard python-mpd
documentation at https://pypi.python.org/pypi/python-mpd/ or http://pythonhosted.org/python-
mpd2/topics/getting-started.html.
Currently the wiring for the vintage radio RGB Led and Menu switch are not shown.
In the above output the connections are descriptive. The parameters found in /etc/radiod.conf can
be displayed with the -p option:
$ ./wiring.py -p
Radio wiring scheme based upon configuration in /etc/radiod.conf
$ ./wiring.py -h
Usage: ./wiring.py -p -h
Where -p print parameters, -h this help text
There is a way to run the software in foreground mode. In this case stop the radio and change to
/usr/share/radio directory and run the radio program with the nodaemon option.
$ cd /usr/share/radio
$ sudo ./radiod.py nodaemon
If the program crashes it will display a stack trace which will give the file name and line numbers
where the program crashed. Use Control-C to exit nodaemon mode (This will also display a stack
trace which is normal and is not an error).
In the case of gradio.py and vgradio.py, these are not daemons and can be run as shown in the
example for gradio.py below:
$ sudo ./gradio.py
Edit the /etc/radiod.conf file and switch on DEBUG mode as shown below.
# loglevel is CRITICAL,ERROR,WARNING,INFO,DEBUG or NONE
loglevel=DEBUG
Operate the radio including the operation you are having with.
Send the /var/log/radio.log file to [email protected]
Switch off DEBUG mode by editing the /etc/radiod.conf file and as shown below.
loglevel=INFO
The physical pins are shown in the center numbered 1 to 26 and 51 through 54 (for a model B2) in
this example. The above output is for a radio using a directly wired LCD and push buttons. For
example:
Physical pin 8 is BCM GPIO 14 and mode is configured as an input for the left switch and is currently
low (V column is 0).
Introduction to Icecast
You may wish to play the output of the Radio through your PC speakers or a mobile device such as a
tablet or telephone. This is possible to do this using Icecast. For more information on Icecast see the
following Wikipedia article: http://en.wikipedia.org/wiki/Icecast .
Please also refer to Intellectual Property, Copyright, and Streaming Media on page 210.
Installing Icecast
Install icecast2 using the install_streaming.sh script.
$ cd /usr/share/radio
$ sudo ./install_streaming.sh
Starting Icecast2 integration with the Music Player Daemon
The Icecast2 installation progra will ask if you wish to configure Icecast2.
Answer 'yes' to this. Configure Icecast as follows:
Icecast2 hostname: localhost
Icecast2 source password: mympd
Icecast2 relay password: mympd
Icecast2 administration password: mympd
Continue y/n: y
Enter ‘y’ to continue. The Icecast2 installation program will ask if you wish to configure Icecast2:
Bob Rathbone |Raspberry PI Internet Radio - Chapter 10 - Streaming to other devices 181
using Icecast2
It is important that you replace the default password ‘hackme’ with ‘mympd’ and that you leave the
Icecast2 hostname as ‘localhost’. The installation program continues configuration. The icecast2
server will be started:
Done Configuring icecast2..
Processing triggers for libc-bin (2.19-18+deb8u6) ...
Processing triggers for systemd (215-17+deb8u5) ...
Configuring Icecast2
Copying /etc/icecast2/icecast.xml to /etc/icecast2/icecast.xml.orig
Check that MPD has established a connection with the icecast2 server
$ netstat -tn | grep :8000
tcp 0 0 127.0.0.1:59096 127.0.0.1:8000 ESTABLISHED
tcp 0 0 127.0.0.1:8000 127.0.0.1:59096 ESTABLISHED
This completes the installation of Icecast2 however you may need to configure the clock speed.
Run raspi-config. Select option ‘Overclock’. After a warning screen about over-clocking has been
displayed, the following screen will be displayed:
Bob Rathbone |Raspberry PI Internet Radio - Chapter 10 - Streaming to other devices 182
using Icecast2
Select ‘Medium’ to start with. Reboot the Raspberry PI when prompted. Re-test the radio with
streaming switched on.
Icecast2 Operation
The radiod daemon has full control over the Icecast2 service and stops and starts it as required.
When the radio is first switched on the Icecast2 streaming service will not normally be enabled
unless it was enabled as shown below by an earlier run of the radio software.
Switching on streaming
Before you can listen to the streaming on the PC or mobile device it is necessary to start the Icecast2
streaming daemon. It must be switched on first.
Use the options menu (Press menu button three times). Step through the menu option using the
Channel up/down buttons until “Streaming off” is displayed in the LCD display (assuming Icecast is
installed). Press either Volume button and after a short delay the text should change to “Streaming
on” in the LCD display. Press the menu button again to exit the options menu.
This starts the Icecast2 service. It also writes the word “on” or “off” to a file called
/var/lib/radiod/streaming. This is file is used to enable or disable the Icecast streaming function at
boot time.
To stop it again:
$ sudo service icecast2 stop
Or
$ sudo systemctl enable icecast2
Bob Rathbone |Raspberry PI Internet Radio - Chapter 10 - Streaming to other devices 183
using Icecast2
Playing the Icecast stream on Windows
To play the Icecast2 radio stream on a PC point your web browser at the IP address of the radio on
port 8000 and the mpd mount point. In the following example the IP address of the radio is
192.168.2.8. So, this would be:
http://192.168.2.8:8000/mpd
This will normally open the default media player.
You will be prompted if you wish to save or open the radio stream. Always select open using the
configured media player. The selected radio station or music track should be heard through the PC
speakers. At this point you may wish to mute the sound from the radio itself. Simply reduce the
volume to almost zero.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 10 - Streaming to other devices 184
using Icecast2
Note: It is probably possible to configure Windows 10 Edge or Internet Explorer 11 to use
Windows Media player instead of TWINUI. Note: If the mute function is used it will stop
the Icecast stream.
http://192.168.2.8:8000
The following screen should be displayed. If not continue to the troubleshooting guide at the end of
this chapter:
Initially the server status screen is displayed. If you click on the Administration tab the you will be
prompted for the login credentials.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 10 - Streaming to other devices 185
using Icecast2
Log in as admin with user admin password mympd.
This should open the iTunes Player and after a short time should start playing the radio stream.
The Icecast stream should start playing. It is important not to key in mpd.m3u at the end of the URL.
It must be mpd only.
For the four line 20 character display the visual indicator is displayed after the time on the first line.
09:26 02/05/2014 *
For the two line by 16 character display there isn’t the room to do this so it is displayed after the
Volume or Mute message on the second line.
Volume 75 * or Sound muted *
Troubleshooting Icecast2
Help for general problems with icecast2 can be found on the forums at http://www.icecast.org/
Icecast2 has two log files in the /var/log/icecast2 directory namely access.log and error.log. The
error log may give a clue as to the problem.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 10 - Streaming to other devices 186
using Icecast2
Below is a simulated error caused by mis-configuring the shoutcast entry in /etc/mpd.conf file. Here
the hostname ‘piradio’ has been configured in the /etc/mpd.conf shoutcast entry instead of
‘localhost’.
$ tail -f /var/log/mpd/mpd.log
Apr 07 10:43 : output: Failed to open "PI Radio MPD Stream" [shout]: problem
opening connection to shout server piradio:8000: Couldn't connect
Try over-clocking the Raspberry PI using the raspi-config program. Medium over-clocking seems to
be sufficient. See Overclocking older Raspberry PI on page 182. The icecast streaming facility is a fun
thing to try out but if it doesn’t work properly or is causing you stress; switch the streaming facility
off.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 10 - Streaming to other devices 187
using Icecast2
Chapter 11 - Setting up Spotify
The radio can also be set up as a Spotify receiver. You will still need a Spotify App
on your telephone, PC or Tablet. You will also need a Premium Spotify account
and not just a free or trial version.
Spotify installation
As from version 6.7 onwards you can install Raspotify from Dave Cooper.
First carry a system update and upgrade as shown in Update to the latest the packages on page 60
Now download the Raspotify software with the curl command.
$ curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
This will both download and install Raspotify. In the /etc/default/raspotify configuration file you
will see the OPTIONS line for Spotify account details. It is not necessary to configure your account
details as these will be picked up from the connecting Spotify App on your PC or Mobile.
#OPTIONS="--username <USERNAME> --password <PASSWORD>"
The radio will automatically stop and start Raspotify but it may be started and with the following
commands:
$ sudo systemctl start raspotify
$ sudo systemctl stop raspotify
Disable Raspotify from starting at boot time. Starting and stopping Raspotify is done by the radio.
$ sudo systemctl disable raspotify
To start the Radio as a Spotify receiver either select Spotify from the Playlists (LCD or OLED versions)
or from the Sources window in the touchscreen version:
The following window will appear however a different message may appear on the second line of
the display window:
Press the Menu button again and the radio will stop the
MPD player and start raspotify.
The Spotify application will connect the Raspotify application on the Radio.
In the case of the touchscreen version of the program the following screen will be displayed:
In the case of the LCD or OLED version of the radio the title line above will be displayed on the
second line of LCD or OLED screen.
Note: Raspotify unfortunately does not supply the Artist information. Only the track name is
supplied by librespot which is used by Raspotify. There is currently no solution for this.
Exiting Spotify
For the LCD and OLED versions press the Menu button until the Select source: window is displayed.
Select any other source (playlist) to exit.
In the case of the touchscreen version of the radio, press the “Exit Spotify”button at the bottom of
the screen.
Troubleshooting Raspotify
Installation problems
If the curl command to install the Raspotify software fails then carry out a system update and
upgrade as shown in Update to the latest the packages on page 60.
Do not use the procedure in the above link. Use the procedure described below as it has
been greatly modified to work with the radio software.
Installation script
From version 6.5 onwards there is an installation script called install_airplay.sh.
$ cd /usr/share/radio
$ ./install_airplay.sh
This will install both shairport-sync and configure the radio to use it.
If the script fails with a dependency error for PHP. Run the following:
$ sudo apt-get -f install
Re-run install_airplay.sh.
Only if this script fails try the manual procedure below. Otherwise skip the next section.
Manual procedure
Install the necessary build library modules and the git program:
$ sudo apt-get install build-essential git xmltoman
Edit the /usr/share/alsa/alsa.conf file (use sudo nano). Scroll down a few pages until you see the
following line:
pcm.front cards.pcm.front
If autoreconf is missing for any reason install it with the following command:
$ sudo apt-get install dh-autoreconf
There is a problem with autoreconf which causes it to fail unpredictably. At the moment, it
seems very unreliable. Below are some suggestions if it exits with an error.
If autoreconf does fail with the following message then make sure that the latest packages are
installed. The autoreconf program can take several minutes.
autoreconf: 'configure.ac' or 'configure.in' is required
Carry out the procedure in section Update to the latest the packages on page 60 and retry.
If autoreconf still fails run the following command and then retry the above autoreconf command:
$ autoreconf -m
Note that the above command will fail but somehow it seems to (sometimes) cure the problem. Re-
run the autoreconf -vif command.
Now configure the package build files (It is the configure script which is created by autoreconf)
$ ./configure --sysconfdir=/etc --with-alsa --with-avahi --with-ssl=openssl
--with-metadata --with-systemd
The last command installs the shairport-sync-metadata program in the /usr/local/bin directory and
the distribution configuration file in /etc/shairport-sync.conf.
Now run Airplay on an Airplay mobile phone or tablet. Search for connected devices which should
include the raspberry pi. Play a music track which should be heard on the radio. Use control-C to
exit. Use Control-C to exit shairport-sync.
Below are the configuration parameters found the Airplay section of /etc/radiod.conf affecting the
Airplay (shairport-sync) function in the radio.
[AIRPLAY]
# Mixer preset volume for radio and media player if using sound card
# Set to 0 if using onboard audio or USB sound dongle.
# If using a sound card set to 100% initially and adjust as neccessary
mixer_volume=0
If upgrading from an earlier version of the radio and you selected “Do not update existing
configuration” during installation then the [AIRPLAY] section will be missing from
/etc/radiod.conf. If this is the case then copy the above lines to the end of the file.
Identify the ID (numid) for the playback volume for your device.
For sound cards or HDMI using digital volume control this is likely to be similar to the following.
numid=1,iface=MIXER,name='Digital Playback Volume'
Modify or add the mixer_volume_id for your device in /etc/radiod.conf. For example:
mixer_volume_id=6
The mixer_volume parameter has a very special use and is used to preset the mixer volume
(alsamixer) if using a DAC sound card or HDMI output. It is not relevant if using the onboard audio
jack as output and must be set to 0. The reason it is needed is that Airplay can only be controlled by
the mixer level unlike the radio which uses Music Player Daemon volume commands.
For on-board audio changing the mixer volume is not relevant as it is controlled by MPD. In this case
set it to 0:
mixer_volume=0
Now use the Airplay device to connect to the raspberry PI (varies according to device software). Start
playing the music tracks and this should start being heard on the radio which also displays the Artist,
Track and Album on the LCD display. The volume is adjustable if correctly set-up. The mute also
works in the normal way but does not pause or stop the Airplay stream as this can only be done
from the device running Airplay.
Log in as user pi and then run the ssh-keygen program. Just press enter when asked any questions.
$ ssh-keygen -t rsa -C “raspberrypi”
Generating public/private rsa key pair.
Enter file in which to save the key (/home/pi/.ssh/id_rsa):
Created directory '/home/pi/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/pi/.ssh/id_rsa.
Your public key has been saved in /home/pi/.ssh/id_rsa.pub.
The key fingerprint is:
c0:54:96:d9:2d:a5:d0:d0:7c:68:91:8a:5f:e2:a5:9d pi@pixelpi
The key's randomart image is:
+---[RSA 2048]----+
| ..=O.*. |
| o .o.X.o |
| o. o.o |
| ..o o |
| oS* . |
| + E |
| |
| |
| |
+-----------------+
Two keys are generated, one public and one private in the .ssh directory. The key id_rsa.pub is the
public key. The id_rsa file is the private key.
$ ls -la .ssh/
total 16
drwx------ 2 pi pi 4096 Feb 16 12:40 .
drwxr-xr-x 19 pi pi 4096 Feb 16 12:40 ..
-rw------- 1 pi pi 1675 Feb 16 12:40 id_rsa
-rw-r--r-- 1 pi pi 392 Feb 16 12:40 id_rsa.pub
Paste or copy the Public key created on the PC to the authorized_keys file. (Some output in the
following text omitted).
ssh-rsa
AAAAB3NzaC1yc2EAAAABJQAAAQEAuX+NEQoQECPN2d+Lu+qL2exMT/ICYbrNax6DVWBtKGzTxFOb
:
LeiaFbI3tWyi+ZPXg8Swhr1OaPN6l2E/fnAQPbGl2S+YMtcIXknNiwVGL8RB3D8N/Q== rsa-
key-20170216
Finally connect to the Raspberry Pi from the PC client using the publickey method. If this works OK
disable password login method. Edit vi /etc/ssh/sshd_config and disable PAM and Password
authentication.
PasswordAuthentication no
:
UsePAM no
Firewall set-up
Linux has a firewall facility built-in to the kernel called iptables. Rules may be added to iptables to
allow or deny access to system services as required. However, iptables is static and has to be
configured with any new rules. The fail2ban program enhances iptables by dynamically adding rules
as required. For example, if a hacker attempts five unsuccessful logins using SSH then fail2ban blocks
that IP address from connecting to the SSH port by adding a blocking rule to iptables. The following
commands install and enable fail2ban.
The following command can be used to make the iptables rules persistent after a reboot. Run the
following command before rebooting.
$ iptables-save
Why are the radio stations not in the order that they were defined?
Playlists are loaded by the radio daemon in alphabetic order using the playlist name.
When loading an individual playlist, MPD loads the stations in the order that they are defined in each
individual playlist. This has been improved by sorting the playlist.
It helps greatly to group stations of the same type into a single playlist. For example group all BBC
radio stations into a single playlist.
The only way to get all of the radio stations in the order that you define them is to define a single
playlist, for example myplaylist:
(myplaylist)
#
# United Kingdom
[BBC Radio 1] http://bbc.co.uk/radio/listen/live/r1.asx
[BBC Radio 2] http://bbc.co.uk/radio/listen/live/r2.asx
[BBC Radio 3] http://bbc.co.uk/radio/listen/live/r3.asx
:
:
[RAIradio3] http://www.listenlive.eu/rai3.m3u
This will produce a single playlist called myplaylist.m3u with the stations loading in the order that
they have been defined in the /var/lib/radiod/stationlist file. Make sure there are no blank lines
between station definitions otherwise this terminates the playlist. All remaining stations will end up
in there own single playlist file.
Why are some station names not being displayed in the web interface?
The reason for this is that some stations don’t send the name with the stream. If you run the mpc
playlists command you will see that some radio stations shows only the station URL and not the
name:
$ mpc playlist
RAIradio2
:
BBC Radio 4 extra
http://icestreaming.rai.it/1.mp3
BBC Radio 3
BBC Radio 6
BBC Radio 5 live
Bob Rathbone |Raspberry PI Internet Radio - Chapter 14 - Frequently asked questions 202
(FAQs)
The only way around this is to complain directly to the radio station to ask them to amend their
stream to include the station name and title details. The only way reason that the station name is
seen with the radio program is that it picks up the names out of the station list file.
The snoopy web interface can’t do this however.
Why doesn’t the web interface display URLs until a station is selected?
When the Snoopy web interface is loaded it loads the playlists found in the /var/lib/mpd/playlists/
directory. Snoopy displays the URLs but doesn’t appear to use any titles defined in the playlists. It
only displays the radio station information (if present) once it starts streaming from a particular
radio station. Snoopy is third party software over which this author has no control.
12:01 23/08/2015
Radio1
Station 37 96K
Volume 75
Bob Rathbone |Raspberry PI Internet Radio - Chapter 14 - Frequently asked questions 203
(FAQs)
Is there a reboot or shutdown option?
There is only a shutdown option. Hold the menu button in for at least three seconds. The radio will
stop and should display “Radio stopped” on the display. Wait ten seconds and then power off the
Raspberry Pi. Powering back on achieves the same effect as a reboot. Also see Fitting a wake-up
button on page 37.
Why do I see a different station name from the one in the playlist?
The station information displayed comes from the stream itself. The name entered in the playlist
definition is only used in the search function. This was a design decision because the station
information is only available once a particular radio station is selected so only the playlist name can
be initially used. If the station transmits the station title this is used instead.
Run the display_current.py program to see all the information that comes from the stream (It is
quite interesting).
The cheaper smaller rotary encoders are usually incremental encoders. Absolute rotary encoders are
usually bigger and more expensive as they house more electronics. If unfortunately, the seller
doesn't provide a specification then there is a small risk that they may not run with this software.
Note: Not all manufacturers’ rotary encoders will work with this project. If they work then
fine if not regrettably you will need to purchase the recommended rotary encoders. You
can also try the alternative rotary class which may just work with your encoders.
You do not need to ask permission to re-use this code or documentation as it is already permitted in
the licenses.
Bob Rathbone |Raspberry PI Internet Radio - Chapter 14 - Frequently asked questions 204
(FAQs)
Chapter 15 - Source files
This section is only of interest if you are considering developing your own version of the software or
wish to use one of the classes in your own software.
The source consists of several source modules all written in Python using Object Orientated
techniques. The source will be visible in the /usr/share/radio directory once the Radio package has
been installed. The radio Debian package is available at
http://www.bobrathbone.com/pi_radio_source.htm .
For those who want to develop their own product all source is also available from Github. See
Downloading the source from github on page 209.
Button press → IR remote control daemon → UDP message over network → Radio program.
Before you can download the source from Github it is necessary to install git. For more information
on git see http://en.wikipedia.org/wiki/Git_(software)
This will create a sub-directory called ‘piradio’ which will contain the entire source. Also in the
/home/pi/develop/piradio directory you will also see a directory called .git (dot-git). This is the
control directory for git.
Note: Don’t forget that if you use the service radiod stop|start commands that this will start
and stop the software in contained in /usr/share/radio (If you installed from the package).
You will not necessarily need to use git any further unless you wish to save your changes under git
control. To find out more about git and for general support and documentation see:
http://git-scm.com
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. This means that you may modify and distribute the software and documentation
subject to the conditions of the licences.
See http://www.gnu.org/licenses for further information on the GNU General Public License.
The licences for the source and documentation for this project are:
GNU General Public License. See http://www.gnu.org/licenses/gpl.html
GNU AFFERO General Public License. See http://www.gnu.org/licenses/agpl.html
GNU Free Documentation License. See http://www.gnu.org/licenses/fdl.html
In general Radio stations are providing a stream to promote their radio station. As media providers
they should have arrangements in place to make the content that they provide is legally streamed
across the Internet but not all do. The question is it legal to listen (or view) such content is a complex
one and subject to local and international laws and which vary considerably.
If you implement Icecast or any other streaming technology to re-stream content within your own
home then provided that this is not streamed back out to the Internet or a public location then one
would think that you will not encounter any problems (but you never know).
If you stream music tracks or relay radio stations back out onto the internet or public space then
almost certainly you will be infringing a copyright law or intellectual property rights somewhere. The
penalties for such an infringement can be severe.
WARNING: YOU USE THE ICECAST STREAMING IN THIS PROJECT AT YOUR OWN RISK ESPECIALLY IF
YOU MAKE THE STREAM CONTENT AVAILABLE ACROSS THE INTERNET OR PUBLIC SPACE, EVEN IF
YOU ARE JUST RELAYING AN EXISTING MEDIA STREAM, LEGAL OR OTHERWISE.
Technical support
Technical support is on a voluntary basis by e-mail only at [email protected]. If there are any
problems with this email address then also CC [email protected]. Before asking for support,
please first consult the troubleshooting section on page 160. I will always respond to e-mails
requesting help and will never ignore them. I only ask that you do the same (i.e. Did my suggestions
help or not?). Be sure to provide the following information:
• What have you built (Adafruit or normal LCD variants, sound cards etc)?
• Which program and wiring version are you running?
• A clear description of the fault.
• What you have already done to locate the problem?
• Is anything displayed on the LCD or Graphics screen?
• Did you run the test programs and what was the result?
• Switch on DEBUG logging as described on page 137, run the program and include the
/var/log/radio.log file. Also run sudo service radiod info.
• Did you vary from the procedure in the manual or add any other software?
• Please do not answer my questions with a question. Please supply the information
requested.
Please note that support for general Raspberry PI problems is not provided. Only issues
relating to the Radio software will be investigated.
For support on Music Player Daemon issues see the help pages at the following link:
http://www.musicpd.org/
For those of you who want to amend the code to suit your own requirements please note: I am very
happy to help people with their projects but my time is limited so I ask that you respect that. Please
also appreciate that I cannot engage in long email conversations with every constructor to debug
their code or to teach Python.
Bob Rathbone |Raspberry PI Internet Radio - Licences, acknowledgements and support 211
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.
The original instructions on how to use Rotary Encoders came from an excellent article by Guy
Carpenter. See:
http://guy.carpenter.id.au/gaugette/2013/01/14/rotary-encoder-library-for-the-raspberry-pi/
To Adafruit Industries for their excellent LCD plate and I2C code. See http://www.adafruit.com.
To Steffen Müller for his article on Streaming audio with MPD and Icecast2 on Raspberry Pi.
See http://www.t3node.com/blog/streaming-audio-with-mpd-and-icecast2-on-raspberry-pi/
To contributors such as Alan Broad who supplied photos of the Lego example of the radio plus code
contribution.
To Mike Whittaker for his contribution on how to drive the USB speaker set. To other contributors
such as Jon Jenkins for his excellent implementation using an old Zenith radio.
Thanks to Michael Uhlmann for the work he did testing various Android Apps for MPD. Also, Simon
O’Niel who carried out configuration and testing of Cmedia sound dongle.
To Open Electronics Magazine for their excellent article on the Raspberry PI radio using the Adafruit
LCD plate. See http://www.open-electronics.org/internet-radio-with-raspberry-pi/
To Joaquin Perez, Broadcast Engineer, Leeds for the backlight dimmer and circuit diagram.
To Luboš Ruckl for his work on the Rotary encoder class (adapted from code by Ben Buxton) and the
PCF8574 LCD class (adapted from code by an unknown author but believed to be from the Arduino
community).
To Béla Mucs from Hungary for his brilliant idea to support speech for visually impaired and blind
persons. This facility uses the espeak package.
Jim Downey from Mobile Alabama, the USA for his article on the backlight for Chinese 1602 I2C
LCDs. See http://mbvmc.org/LCD_Backlight.pdf
Tomás González, Sevilla, Spain for his changes to lcd_adafruit_class.py (Previously ada_lcd_class.py)
to switch on the Chinese 1602 I2C LCD backlight.
To the authors of the SGC Widget routines. Copyright (c) 2010-2012, Sam Bull and Michael Rochester
Icons used in the graphic versions of the radio. Clipart library http://clipart-library.com
and IconSeeker http://www.iconseeker.com
Bob Rathbone |Raspberry PI Internet Radio - Licences, acknowledgements and support 212
Thanks to Olimex Limited for their SSD1306 OLED routines which were used in the oled_class.py
program and for their excellent technical support. See http://www.olimex.com. Original source
https://github.com/SelfDestroyer/pyMOD-OLED.git
Thanks to Gordon Garrity at IQaudIO http://iqaudio.co.uk for his help and sponsorship to develop
the radio to support the IQaudIO Cosmic Controller and SSD1306 OLED display.
Thanks to Pimoroni for their excellent Pirate radio using pHat BEAT software and hardware. See
http://pimoroni.com for further information.
Thanks to PiFace UK for their PiFace CAD product. This makes a very easy entry level radio using this
software. See http://www.piface.org.uk/
To all constructors of this project who have sent in photos of their radio’s and their ideas for
improvement and the many appreciative e-mails that I have received from them.
Bob Rathbone |Raspberry PI Internet Radio - Licences, acknowledgements and support 213
Glossary
DOS Denial of Service – Attack software aimed at taking down an Internet service (Web etc)
DDOS Distributed Denial of Service – DOS attack from hundreds or thousands of computers
DNS Domain Name System. Converts a URL such as google.com to a IP address or addresses
FLIRC A USB device and software which maps an IR remote control to the keyboard
HDMI High-Definition Multimedia Interface for audio and video plus Ethernet interface.
I2C Industry standard serial interface (Philips now NXP) using data and clock signals
I2S Inter-IC Sound (Used in DAC interface) from Philips (Now NXP)
Bob Rathbone |Raspberry PI Internet Radio - Glossary 214
IP Internet Protocol
IR Infra-Red (sensor) for use with infra-red devices such as remote controls
PC Personal Computer
PCM Pulse-Code Modulation is a method used to digitally represent sampled analogue signals
PID Process ID
SSID Service Set Identifier. An SSID is the public name of a wireless network.
TCP/IP The common name for network protocols used by the Internet and computer networks.
USB OTG USB On-The-Go, software to support USB devices (Not supported with this radio)
VLC Media player used by Pimoroni software (Not used by this radio software)
VU Volume Unit – Volume meter/indicator also known as SVI (Standard Volume Indicator)
WEP Wired Equivalent Privacy (WEP) is a security algorithm considered less secure than WPA
WPA2 Wi-Fi Protected Access version II, an enhanced, more secure version of WPA.
XML Extensible Mark-up Language. A web technology used for transmitting data structures
[RADIOD]
# Remote control UDP server listen host either 0.0.0.0 (All interfaces) or
localhost
remote_listen_host=localhost
Bob Rathbone |Raspberry PI Internet Radio - Appendix A - System Files used by the Radio 217
Program
rgb_green=0
rgb_blue=0
rgb_red=0
# Menu rotary switch (optional) Normal values are 24,8 and 7 respectively.
Value 0 disables
menu_switch_value_1=0
menu_switch_value_2=0
menu_switch_value_4=0
# The i2c_address overides the default i2c address. 0x00 = use default
# Some backpacks use other addresses such as 0x3F, then set i2c_address=0x3F
i2c_address=0x00
# I2C normaly uses bus 1 on the I2C interface. However the very first
Raspberry
# used bus 0. If you are using a very old Pi then set i2c_bus=0
# Run ./display_model.py to see what model Pi you are running
i2c_bus=1
# Display types
# NO_DISPLAY = No display connected
# LCD = directly connected LCD
# LCD_I2C_PCF8574 = Arduino (PCF8574) or Adafruit I2C backpack
# LCD_I2C_ADAFRUIT = Adafruit I2C backpack
# LCD_ADAFRUIT_RGB = LCD I2C RGB plate with buttons
# GRAPHICAL = Graphical or touch screen display
# OLED_128x64 = 128x64 pixel OLED
display_type=GRAPHICAL
Bob Rathbone |Raspberry PI Internet Radio - Appendix A - System Files used by the Radio 218
Program
lcd_data7=13
# Some rotary switches do not work well with the standard rotary class
# Rotary encoder driver. Set to "alternative" to use the alternative rotary
encoder class
rotary_class=standard
#rotary_class=alternative
# Shoutcast ID
shoutcast_key=anCLSEDQODrElkxl
# OLED parameters
# Flip display vertically (yes or no) OLED only at present
flip_display_vertically=no
# Splash screen
splash=bitmaps/raspberry-pi-logo.bmp
[AIRPLAY]
# Mixer preset volume for radio and media player if using sound card
# Set to 0 if using onboard audio or USB sound dongle.
# If using a sound card set to 100% initially and adjust as neccessary
# Old name was mixer_volume
mixer_preset=100
Bob Rathbone |Raspberry PI Internet Radio - Appendix A - System Files used by the Radio 219
Program
/etc/logrotate.d/radiod
This file causes the /var/log/radio.log to be rotated so that it doesn’t continue to grow and fill the
disk.
/var/log/radio.log {
weekly
missingok
rotate 4
compress
notifempty
maxsize 150000
copytruncate
create 600
}
Old log files are compressed and renamed, for example /var/log/radio.log.1.gz.
/etc/init.d/radiod
This is the start stop script for the radio daemon. The NAME parameter must be changed to point to
the correct radio program. This is done by the configure_radio.sh shell script which is called during
the installation procedure.
# Change NAME parameter this next line to the version of the daemon you are
using
# Choices are radiod.py, radio4.py, rradiod.py, rradio4.py, ada_radio.py,
# rradiobp4.py or rradiobp.py
# No spaces around the = character
NAME=radio4.py
This script is linked to the start stop run levels in the /etc directory.
For example:
ls -la /etc/rc2.d/S03radiod
lrwxrwxrwx 1 root root 16 Nov 8 14:28 /etc/rc3.d/S03radiod ->
../init.d/radiod
/lib/systemd/system/radiod.service
This file is part of the new systemd startup services and has been added from version 5.8 onwards to
increase compatibility with the new systemd start-up and shutdown routines.
# Radio systemd script
:
[Unit]
Description=Radio daemon
After=network.target
[Service]
Type=simple
ExecStart=/usr/share/radio/radiod.py nodaemon
[Install]
WantedBy=multi-user.target
/etc/init.d/asound.conf
This file is only added if a DAC or USB sound device is added and is needed for espeak and aplay
Bob Rathbone |Raspberry PI Internet Radio - Appendix A - System Files used by the Radio 220
Program
# Set default mixer controls
ctl.!default {
type hw
card 0
}
/etc/init.d/irradiod
This is the service start stop script for the remote control daemon. This starts and stops the
/usr/share/radio/remote_control.py program which handles the remote control for the IR
interface.
/etc/lirc/lircrc
This file contains the button definitions for the remote control to Pi radio interface.
begin
prog = piradio
button = KEY_VOLUMEUP
config = KEY_VOLUMEUP
repeat = 1
end
begin
prog = piradio
button = KEY_VOLUMEDOWN
config = KEY_VOLUMEDOWN
repeat = 1
end
begin
prog = piradio
button = KEY_CHANNELUP
config = KEY_CHANNELUP
end
begin
prog = piradio
button = KEY_CHANNELDOWN
config = KEY_CHANNELDOWN
end
begin
prog = piradio
button = KEY_MUTE
config = KEY_MUTE
end
begin
prog = piradio
button = KEY_MENU
config = KEY_MENU
end
begin
Bob Rathbone |Raspberry PI Internet Radio - Appendix A - System Files used by the Radio 221
Program
prog = piradio
button = KEY_LEFT
config = KEY_LEFT
end
begin
prog = piradio
button = KEY_RIGHT
config = KEY_RIGHT
end
begin
prog = piradio
button = KEY_UP
config = KEY_UP
end
begin
prog = piradio
button = KEY_DOWN
config = KEY_DOWN
end
begin
prog = piradio
button = KEY_OK
config = KEY_OK
end
begin
prog = piradio
button = KEY_LANGUAGE
config = KEY_LANGUAGE
end
begin
prog = piradio
button = KEY_INFO
config = KEY_INFO
end
# End
Bob Rathbone |Raspberry PI Internet Radio - Appendix A - System Files used by the Radio 222
Program
Encoding=UTF-8
Terminal=false
Categories=None;
Bob Rathbone |Raspberry PI Internet Radio - Appendix A - System Files used by the Radio 223
Program
A.2 System files modified by the installation
All files to be modified by the installation process are first copied to <filename>.orig.
/etc/modules
If the i2C interface is installed then the i2c-dev module definition is added to this file. A reboot is
required to load the module.
snd-bcm2835
i2c-bcm2708
i2c-dev
# Original file stored as /etc/modules.orig
/boot/config.txt
This is amended if installing the IR software by adding the lirc-rpi device definition. For example:
dtoverlay=lirc-rpi,gpio_in_pin=9
It may also be modified to support HiFiBerry DAC and DAC+. For example:
dtoverlay=hifiberry-dacplus
From version 5.8 onwards the configure_audio.sh program disables the onboard sound devices
when configuring a sound card by changing the following line in /boot/config.txt from:
dtparam=audio=on
To:
dtparam=audio=off
Bob Rathbone |Raspberry PI Internet Radio - Appendix A - System Files used by the Radio 224
Program
Appendix B – Cheat sheets
The following cheat sheet is a list of the basic commands to install MPD and the radio software.
Configure /boot/config.txt for lirc-rpi overlay to match the wiring for the IR sensor.
dtoverlay=lirc-rpi,gpio_in_pin=25,gpio_in_pull=high
Copy the button definitions to /etc/lircrc and reboot the Raspberry Pi.
$ cd /usr/share/radio
$ sudo cp lircrc.dist /etc/lirc/lircrc
Configure the remote activity LED in /etc/radiod.conf to match the wiring for the LED.
Please note that this is not a consumer product. No claims are made to suitability for all
users. It is solely intended as a fun construction project. Please also see Disclaimer on
page 211.
Bob Rathbone |Raspberry PI Internet Radio - Appendix C – Technical specification and 228
other notes
C.2 -Elecrow 7-inch touch-screen notes
Below are some notes on how to set up the Elecrow 7 inch TFT Capacitive touch screen display, with
1024x600 Resolution.
Please note, much of this information was supplied by a third-party and has not been
tested by the author. Therefore, any support by the author is limited.
hdmi_force_hotplug=1
max_usb_current=1
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_cvt 1024 600 60 6 0 0 0
hdmi_drive=1
If when running in full screen mode (fullscreen=yes in /etc/radiod.conf) you see a small window
surrounded by a thick black border then in /boot/config.txt file amend the following:
framebuffer_width=1280
framebuffer_height=720
To
framebuffer_width=800
framebuffer_height=480
screen_size=800x480
https://www.elecrow.com/wiki/index.php?title=7_Inch_1024*600_HDMI_LCD_Display_with_Touch
_Screen
Bob Rathbone |Raspberry PI Internet Radio - Appendix C – Technical specification and 229
other notes
C.3 Sound card DT Overlays
The following table contains the known Device Tree (DT) overlays for various sound cards. The third
column contains the DT overlay statement that needs to be added to the /boot/config.txt
configuration file. This is either done by running the configure_audio.sh program or by directly
editing /boot/config.txt.
In all cases, disable the on-board sound system by modifying the dtparam=audio=on parameter in
the /boot/config.txt configuration file to off:
dtparam=audio=off
Bob Rathbone |Raspberry PI Internet Radio - Appendix C – Technical specification and 230
other notes
C.4 UDP messages
This section is only of interest to developers wishing to interface with the radio program.
These are messages (events) sent to the UDP listener in the radio_class.py program. These are sent
from the IR remote control program and from the Shoutcast program & web interface.
Bob Rathbone |Raspberry PI Internet Radio - Appendix C – Technical specification and 231
other notes
Appendix D – Wiring diagrams and lists
The following tables shows the wiring for the various versions of the radio. These configurations are
normally set up by the configure_radio.sh program with the exception of the Vintage radio.
See Configuring the radio on page 70. It is also necessary to set the pull_up_down parameter in
/etc/radiod.conf depending on wiring.
Bob Rathbone |Raspberry PI Internet Radio - Appendix D – Wiring diagrams and lists 232
D.4 Pimoroni Pirate Radio wiring
The following table shows the wiring for the Pimoroni Pirate radio (pHat BEAT). Orientation is with
the basic push buttons on the left-hand side. The menu button is on the top left-hand side.
The On/Off button used in the Pimoroni Radio software re-assigned as the menu switch with the
Rathbone radio software. All LCD outputs are set to zero (No display).
Set pull_up_down=up in /etc/radiod.conf
Combining the above switch values gives a composite switch value of 0 through 7.
0=Idle, 1=Speak current station/track, 3=Search mode, 4=Source menu, 5=Options Menu 6,7 unused
Bob Rathbone |Raspberry PI Internet Radio - Appendix D – Wiring diagrams and lists 233
D.6 Raspberry Pi Rotary Encoder version with backlight dimmer
The following wiring diagram was provided by Joaquin Perez, Broadcast Engineer, Leeds. He also
shows the circuitry to dim the backlight using a BS170 Mosfet transistor (Software to support the
LED dimmer to follow in a later release).
Index
1602 I2C LCD, 33 ASX, 150, 151, 214
26 way ribbon cable, 27, 28 audio jack plug, 42
AAC, 150, 151, 214 AV, 10, 11
activity LED, 7, 17, 39, 92, 95, 110, 111 backup, 107
Adafruit, 5, 6, 17, 23, 24, 28, 32, 33, 34, 35, Bitvise, 58, 62, 200
36, 38, 39, 53, 80, 92, 110, 112, 113, 140, Bluetooth speakers, 91
165, 167, 174, 205, 211, 212, 228 breakout boards, 31
AdaFruit, 5, 17, 93, 110, 125, 203 CAD, 8, 41, 110, 214
AdaFruit industries, 5 CGI, 101, 214
AdaFruit RGB plate, 17, 110, 125, 203 CIFS, 155, 156, 157, 214
airflow, 17 CloudBreak, 131, 197
Airplay, 131, 192, 194, 195, 196, 208, 228 colours, 112, 140
Alarm, 124, 125, 137, 138, 139, 228 COM-09117 12-step rotary encoder, 22
alsamixer, 85, 87, 88, 90, 117, 195 configure_radio.sh, 15, 18, 35, 45, 70, 72, 75,
amplifier, 7, 25, 26, 28, 51 91, 108, 109, 111, 134, 137, 162, 164, 165,
aplay, 54, 86, 105, 106, 163, 169, 170, 220 205, 207, 208, 217, 220, 232
Arduino, 34, 35, 80, 81 constructor’s gallery, 16
asound.conf, 105, 116, 117, 220 cooling fans, 51