Introducing the PiFace radio

So, we spent some time manually building an Internet radio. This is awesome, but when you start to look at alternative LCD displays, such as the PiFace, you start to realize that there are some easier solutions. The following image shows the PiFace command and control:

Introducing the PiFace radio

We talked about this alternative earlier in the book, so I won't go into the details again. We will jump right into working with it.

As I'm sure you will have already guessed, we will start by installing the PiFace packages:

sudo apt-get install python3-pifacecad

Once they are installed, we will need to reboot:

sudo reboot

After the Banana Pi has rebooted, we can try out the display to make sure it actually works. We will change directories to the examples folder:

cd /usr/share/doc/python3-pifacecad/examples

We will need to make sure that we have the SPI module enabled under raspi-config. You may get an error like this:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pifacecommon/spi.py", line 40, in open_fd
    self.fd = posix.open(spi_device, posix.O_RDWR)
OSError: [Errno 2] No such file or directory: '/dev/spidev0.1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "sysinfo.py", line 61, in <module>
    cad = pifacecad.PiFaceCAD()
  File "/usr/lib/python3/dist-packages/pifacecad/core.py", line 40, in __init__
    super(PiFaceCAD, self).__init__(hardware_addr, bus, chip_select)
  File "/usr/lib/python3/dist-packages/pifacecommon/mcp23s17.py", line 91, in __                                           init__
    super(MCP23S17, self).__init__(bus, chip_select)
  File "/usr/lib/python3/dist-packages/pifacecommon/spi.py", line 32, in __init_                                           _
    self.open_fd(spi_device)
  File "/usr/lib/python3/dist-packages/pifacecommon/spi.py", line 44, in open_fd
    % (spi_device, SPI_HELP_LINK)
pifacecommon.spi.SPIInitError: I can't see /dev/spidev0.1. Have you enabled the                                            SPI module? (http://piface.github.io/pifacecommon/installation.html#enable-the-s                                           pi-module)

By opening the raspi-config menu in the terminal, we can go to the advanced options and enable the module. It will require a reboot; after the reboot, the error should be cleared up. If that doesn't work, you may need to reinstall the Python packages or the PiFace common package.

We can run the sysinfo example, which will enable the display and show us our local IP address and temperature:

python3 sysinfo.py

The output of the PiFace will look like this:

Introducing the PiFace radio

Now that we have this working, you can stop it by pressing Ctrl + C. We can now set up the Internet radio side of things.

The PiFace radio

We need to install mplayer on the Pi to set up the radio. We will run the following command and press Y whenever we are asked:

sudo apt-get install mplayer

We can now unzip the radio examples, which are in the same directory as the sysinfo example:

sudo gunzip /usr/share/doc/python3-pifacecad/examples/radio.py.gz

We can now run the PiFace radio:

python3 /usr/share/doc/python3-pifacecad/examples/radio.py

We have multiple controls on the PiFace. We can use these to change the radio stations and pause the stream.

Adding stations

Now we have a radio with some fancy buttons, but we have some stations we don't like. We can easily edit the software to add the stations we like. We will first need to copy the program from the examples directory to our home directory:

cp /usr/share/doc/python3-pifacecad/examples/radio.py ~
cp /usr/share/doc/python3-pifacecad/examples/radiolircrc ~

We will need to edit the radio .py file:

nano radio.py 

We will look for the section of the code that identifies the stations as an array:

{'name': "station name",'source': 'station web address','info': 'station info web address' or None},

I'll add the station I added in the first radio:

{'name': "Jupiter Broadcasting",'source': http://jbradio.out.airtime.pro:8000/jbradio_a ','info': None},

Now, just add as many stations as you like. When you run the program again, you will be able to switch between these stations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.167.241