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).
Listed below are the bare minimum parts required for a functioning Raspberry Pi RFID Spotify jukebox, with associated links:
-
There are several Raspberry Pi's that can be used, but ultimately depend on the implementation
-
It is best to use a RC522 RFID due to its supported Python library module. You can pick one up here.
-
- 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
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
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
Click here for more RC522 Data
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.
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.
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:
- Navigate to https://developer.spotify.com/dashboard
- Sign in with a Spotify Premium Account
- Click "Create an App"
- Click on your app
- Click on "Edit Settings"
- Add the following callback URIs
http://localhost:8888/callback
http://localhost:8080
- 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
- On a phone or laptop, open Spotify and connect to "Raspotify"
- Navigate to https://developer.spotify.com/console/get-users-available-devices/
- Click get token
- Check all the boxes under "Required Scopes for this endpoint"
- Click "Request Token"
- Underneath the Get token option, click "Try It" to make an API call and get the list of Spotify devices on your home network
- In the json response, find the ID for the Raspotify (Raspberry Pi) device
- Write/copy the Device ID
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.
- In your main folder, open parseSpotify.py
- Change the Device ID, Client ID, and Client Secret to the tokens provided by Spotify
- Execute this script
- A Spotify webpage will open where you have to agree/accept to authenticate. Click agree, this is a one-time setup
- Once authenticated, the song in parseSpotify.py will start playing through the Raspberry Pi speakers
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:
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 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
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.
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
Ensure that PullSpotifyData is False if you want custom album art
genPhotos.py
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.
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.
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.
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]