Giter VIP home page Giter VIP logo

spotify-player's Introduction

Raspberry Pi - RFID Spotify Jukebox

Cover Photo

Description

Ths project employs the spotipy Python library to interface with the Spotify web application to create a functional RFID Spotify Jukebox. This Github repository will contain the steps towards creating a functional spotify application as well as containing links to the thingiverse repository of the .stl files that I 3D printed as well as the Bill of Materials (BOM).


Table of Contents


Bill of Materials

Listed below are the bare minimum parts required for a functioning Raspberry Pi RFID Spotify jukebox, with associated links:

  • Raspberry Pi

    There are several Raspberry Pi's that can be used, but ultimately depend on the implementation

  • RFID Card Reader

    It is best to use a RC522 RFID due to its supported Python library module. You can pick one up here.

  • Miscellaneous Parts

    • Speaker: in this build I used a JBL Flip 3 that I purchased on a Black Friday Deal for $30, any speaker will suffice - edits to the 3D prints will be needed with a different speaker configuration
    • Button: to skip tracks, play/pause tracks I used Tactile Push Button Switch or a suitable alternative
    • Audio Jack Splitter: To allow external speaker player I got this audio jack that will mount into the 3D printed frame Audio Jack Splitter
    • RFID Tags: Link here
    • Blank Cards: Link here
    • Threaded inserts: Link here
    • Dupont Connectors: Link here
    • Protoboard: Link here
    • Rubber Standoffs: Link here
    • Raspberry Pi PS Cable: Link here

Installation and Setup

Initial Set-up

After a clean install of Raspberry Pi Dameon Linux

sudo apt-get update
sudo apt-get upgrade

Next type the following

sudo raspi-config

Raspi-config will open a window, from here select "Interfacing Options" and select "SPI" and enable "SPI"

sudo reboot

RC522 Card Reading

To allow the reading of RFID tags, connect the MFRC522 module to the Raspberry Pi via the following pin out schematic

  • SS pin connects to GPIO8 pin
  • SCK pin connects to GPIO11 pin
  • MOSI pin connects to GPIO10 pin
  • MISO pin connects to GPIO9 pin
  • IRQ pin does not connect to anything
  • GND pin connects to GND pin
  • RST pin connects to GPIO23 pin
  • VCC pin connects to 3.3V Power pin

Refer to the pins and connections below MFRC522 RFID Card Reader Pin Out Click here for more RC522 Data

Raspberry Pi 3/4 GPIO Pin Outs

To allow for the RFID reading, install the following dependencies

sudo apt-get install python3-dev python3-pip
sudo pip3 install spidev mfrc522

This will enable the Raspberry Pi to access the GPIO pins and read the HASH ID values from the RFID tags that can be used to link to playlists/albums/tracks later on. With these dependencies installed readCard.py should be able to run and will output the HASD ID values.

Connecting Raspberry Pi to Spotify

To enable the Raspberry Pi to be a valid connection on Spotify, the Raspotify - Spotify Connect client will need to be installed - be sure that all dependencies are met else connect will not work- to install use the folllowing command

sudo apt-get -y install curl && curl -sL https://dtcooper.github.io/raspotify/install.sh | sh

While the Raspberry Pi is on and connected to internet, it should be recognized by Spotify as a valid connection device (analogous to a bluetooth speaker, a separate device, etc). Test functionality by opening Spotify on a phone or laptop and click the Connect button and search for "Raspotify" in the options.

Setting up Developer Spotify API

Next step is too allow the Raspberry Pi to interface with Spotify's web API and allow the Raspberry Pi to change music per the RFID values. To allow spotipy to integrate with the Spotify web API, API tokens are required, to obtain them do the following:

  1. Navigate to https://developer.spotify.com/dashboard
  2. Sign in with a Spotify Premium Account
  3. Click "Create an App"
  4. Click on your app
  5. Click on "Edit Settings"
  6. Add the following callback URIs
http://localhost:8888/callback
http://localhost:8080 
  1. On the dashboard, write/copy the Client ID and Client Secret, they are needed later

Next is to get the Device ID of the Raspberry Pi, this can be found after connecting the Raspberry Pi via Spotify Connect

  1. On a phone or laptop, open Spotify and connect to "Raspotify"
  2. Navigate to https://developer.spotify.com/console/get-users-available-devices/
  3. Click get token
  4. Check all the boxes under "Required Scopes for this endpoint"
  5. Click "Request Token"
  6. Underneath the Get token option, click "Try It" to make an API call and get the list of Spotify devices on your home network
  7. In the json response, find the ID for the Raspotify (Raspberry Pi) device
  8. Write/copy the Device ID

Installing Spotipy

Spotipy is a lightweight python library for the Spotify web API, click here for Spotipy Documentation

pip install spotipy

Once that installs, we can start writing our first python program to control Spotify on Raspberry Pi.

  1. In your main folder, open parseSpotify.py
  2. Change the Device ID, Client ID, and Client Secret to the tokens provided by Spotify
  3. Execute this script
  4. A Spotify webpage will open where you have to agree/accept to authenticate. Click agree, this is a one-time setup
  5. Once authenticated, the song in parseSpotify.py will start playing through the Raspberry Pi speakers

Adding Playlists/Songs to RFID Cards

With everything up to this point being completed, the Raspberry Pi is ready to play music! Change the token values in main.py to match the tokens provided to you from Spotify. From here songs/albums/playlists can be added to the CardData.json through the following format shown below:

{
    "HASH ID #1 FROM RFID CARD":{
        "name":"Road Trips",
        "url":"spotify:playlist:1LxEqGRyNV5yB67e6mwGgH",
    },
    "HASH ID #2 FROM RFID CARD":{
        "name":"California 37",
        "url":"spotify:album:5zseibu9WEsPaZmkJUMkz1",
    },
    "HASH ID #3 FROM RFID CARD":{
        "name":"Beautiful Mistakes",
        "url":"spotify:track:5zFglKYiknIxks8geR8rcL",
    },
}

Where HASH ID can be found by running the readCard.py script and copying/pasting the RFID HASH ID into CardData.json and where "type" can be either Playlist, Album, or Track as per the Spotify URL. Obtaining the URL can be done simply by: Spotify Song Links

Copying this link gives https://open.spotify.com/track/4HlFJV71xXKIGcU3kRyttv?si=b945f2f735874dd0 but all that is is needed can be spliced is after the spotify.com/"type"/ up to the "?" such that this track's ID is 4HlFJV71xXKIGcU3kRyttv. Hence, the value for the card's URL is

{
    "name":"Hey, Soul Sister",
    "url":"spotify:track:4HlFJV71xXKIGcU3kRyttv",
    "type": "Track"
}

Note: The type must be correct as album/playlist use a different API call than track, the name can be left blank

Enabling Spotipy Script on Boot

Enabling the python script to auto-run on boot can be done by using crontab to run a shell script that starts the script on boot. For detailed instructions, refer to Raspberry Pi Launch Python Script on Startup


Printing Album Art

Included in this repository is the genPhotos.py file that will automatically generate the album art to be printed, cut out and pasted onto a blank card to pose as a modern record. All that is required is enabling the boolean to automatically pull the album art from Spotify - else you'll have to manually populate the album cover art folder with photos of your choice.

Custom Art

To print custom artworks (not the album art from Spotify), place your artwork into the cover_art folder shown below with the associated name that can be found in the CardData.json

Image Layout

Ensure that PullSpotifyData is False if you want custom album art

genPhotos.py Boolean

genPhotos.py

3D Printing Jukebox

All the 3D printing CAD files can be found under the associated CAD folder in this repository. These are in the .stl file format to be used during .gcode generation. Additionally, the drawing with the bill of materials (BOM) can be found in this folder as well.

Bill of Materials

The parts that end in an -0XX are those that are printed and not bought locally (exception of the rubber feet if preferred). Additionally, to enable the previous/play & pause/skip track buttons electrically wiring the buttons with soulder will be required. The electrical configuration is as follows.

Button Electrical Configuration

Credits

This repository and project is based upon the work of talaexe's Sptoify-RFID-Record-Player and expanded upon to allow more features and scalability. Additionally, this work extensively uses Spotipy of which is the Python library that allows Web API calls to Spotify. Finally, this also extensively uses the Raspotify library to integrate with Raspberry Pi and Spotify to allow music playing.

License

Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) prohibits the use of this for commercialization, but allows downloading editing/sharing amongst the community. If there is a request to commercialize, contact me personally via email at [email protected]

spotify-player's People

Contributors

dancard32 avatar

Stargazers

Markus Hedenborn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.