Raspberry Pi with Spotify Connect

Have you ever wanted to setup your hi-fi or speaker system with Spotify Connect functionality? Well, now you can with a Raspberry Pi and some extra bits. This post explains how to do that from scratch.

Please note that this works as of November 2017. Things can change, in particular Spotify’s API. This implementation makes use of raspotify which makes use of librespot which, as of 3 October 2017, is no longer being maintained by the original developer. Should my setup break I will attempt to fix it and adjust this blog accordingly.

What you’ll need

  • Raspberry Pi 3 B
  • A Spotify PREMIUM account
  • An USB sound card (like this one from Amazon)
  • A micro USB power supply
  • An Ethernet cable that connects to the wonderful world wide web
  • A screen that supports HDMI and an HDMI cable
  • A micro SD Card (2GB works but 4GB would be better)
  • A Windows machine that can access micro SD cards
  • Raspbian Jessie (from here)
  • SD Card Formatter(from here)
  • Win32 Disk Imager (from here)

Initialising the Raspberry Pi

  1. Connect the SD Card to your Windows machine and startup SD Card Formatter
  2. Select your SD Card and select to Overwrite Format.
  3. Extract the files from the Raspbian Jessie zip file that was downloaded, there will be a .img file.
  4. Open Win32 Disk Imager and select the .img file referenced in the previous step. Select to write this file to the SD Card.
  5. Insert the SD Card into the Raspberry Pi. Connect the Ethernet cable, the micro USB power supply,the USB sound card and the screen. If all goes well, your Raspberry Pi should boot up and you’ll be requested to login.
  6. Login with username “pi”, password “raspberry”.
  7. Get the latest updates for your pi by running:
    sudo apt-get update
    sudo apt-get dist-upgrade
  8. Wait patiently while updates are completed.
Note that I particularly chose to setup the Raspberry Pi in “headless” mode which saves system resources. Feel free to set it up in “headed” mode (with a UI) if you prefer, this version of Jessie can be found here
If you want to be able to setup your Raspberry Pi without a monitor, this page can help. And here you’ll find details on how to setup the wifi.

Checking the Audio output

To ensure that the USB sound card is available for audio output, type in the following command:

amixer -l

You should be able to see your USB audio device listed. Here’s what mine shows:

From this you can see the 3,5mm and the HDMI outputs listed as sub-devices of card 0. Then by card 1 you can see my USB Audio Device. If your device doesn’t show up this might be helpful. In my case it just worked :D

If your USB audio device does show up as shown above and you want to do a sound test, try running the following command:

speaker-test -c2 -D plughw:1,0

Installing and configuring Raspotify

  1. Install Raspotify by running:
    curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
  2. After the install is completed, edit the configuration of raspotify by typing:
    sudo nano /etc/default/raspotify
  3. In the raspotify file, fill in your Spotify user name in place of <USERNAME> and your Spotify password in place of <PASSWORD>. Also, add in the parameter --device hw1,0 This ensures that the sound is output to your USB Audio Device.
  4. Select Ctrl+X to exit.
  5. Type “Y” to save then select Enter
  6. Reboot your Pi:
    sudo reboot
  7. You should now be able to see your raspotify device available for Spotify Connect.

Additional Optional Steps

Change the password

A good security practice is to change the default password of your Pi. To do this, login to your Pi and then type

sudo raspi-config

The first item in the list will allow you to change your password

Change the bitrate

It’s possible to set a higher bit rate for Spotify playback. You can set this in the raspotify setting file (where you set OPTIONS above).

Thanks

Much thanks to David Cooper for raspotify and Paul Liétar for librespot.