Spotify Control Center

by olib3 in Circuits > Raspberry Pi

36 Views, 0 Favorites, 0 Comments

Spotify Control Center

unnamed.jpg

If you’ve ever wanted a dedicated/always-on Spotify control center, something you can tap like a car stereo, display album art, switch songs, adjust volume, and watch your music progress in real time, this project is for you.

This guide will show you how to build a standalone Spotify dashboard using a Raspberry Pi, a 7-inch touchscreen, and some lightweight Python code. The final result is a clean, modern interface that displays:

  1. The current song playing, the artist name and the album art
  2. A live and accurate progress bar
  3. Touch-friendly play/pause, next, previous, and volume buttons

Everything is designed to be simple, responsive, and perfect for mounting on a desk, wall, nightstand, or even inside a custom enclosure.

This is a great project whether you’re into home automation, tinkering, or just want a sleek way to control your music without needing your phone. No special hardware is required besides the Pi and touchscreen, and the software is all free.

Supplies

  1. Raspberry Pi 4 Model B - Buy Here
  2. 7" Touchscreen Display - Buy Here
  3. MicroSD card (16 GB or larger recommended) - Buy Here
  4. Power supply for the Pi (any 5V+ USB-C cable should work.)
  5. Optional: USB/3.5mm Speakers - Buy Here (any speaker(s) with a USB/3.5mm connection will work.)

Installing Raspberry Pi OS

The first step in preparing your Raspberry Pi is installing an OS onto the SD card. The Raspberry Pi Imager software can be downloaded from the attached link.

  1. Download your respective OS from this link.
  2. Create an image on your SD card with the Imager software.
  3. Insert the SD card into your Raspberry Pi.
  4. After installing and booting into the OS, set up internet and login details.

Create a Spotify Developer App

Screenshot 2025-12-11 191030.png

This project requires access to Spotify's API to retrieve accurate song data. Navigate to the Spotify for Developers website and log in with your Spotify account.

  1. Click on "Create app"
  2. Note your "Client ID" and "Client secret". These will be used later during setup.
  3. Customize your app name and description
  4. Add a redirect URI (http://127.0.0.1:8000/callback). You can use the previous link for yours as well.
  5. When prompted to choose an API/SDK, choose Web API.
  6. Save your app.


Installing Libraries

This project uses many libraries to function, and we will install them now.

  1. First, update your software by running sudo apt update
  2. Install the necessary libraries with this command: sudo apt install python3-pygame python3-pil python3-numpy python3-requests python3-alsaaudio
  3. Lastly, install spotipy with pip3 install spotipy

Creating the Dashboard

  1. Within your terminal, run the command mkdir ~/spotify-dashboard to create the directory.
  2. Navigate to this folder with the cd ~/spotify-dashboard command.
  3. Create a config file with the command nano config.py. Within this file, you will define your client ID, client secret, redirect URI, and device name. (You can name your device whatever you would like!)
SPOTIFY_CLIENT_ID = "YOUR_ID_HERE"
SPOTIFY_CLIENT_SECRET = "YOUR_SECRET_HERE"
SPOTIFY_REDIRECT_URI = "http://127.0.0.1:8000/callback"
DEVICE_NAME = "anyname"

Importing Libraries

We will create our code file by running the nano dashboard.py command.

  1. Within the dashboard.py file, we will begin the code by importing the libraries the dashboard will use.
import pygame
import requests
import io
from PIL import Image
import time
import spotipy
from spotipy.oauth2 import SpotifyOAuth


Spotify Authorization

Next, we will configure Spotipy to authorize our client ID, secret and URI from the Spotify for Developers site.

# -----------------------------
# SPOTIFY AUTH
# -----------------------------
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
client_id="YOUR_ID_HERE",
client_secret="YOUR_SECRET_HERE",
redirect_uri="http://127.0.0.1:8000/callback",
scope="user-read-playback-state user-modify-playback-state"
))


Configuring Pygame

The next few steps of the code will address Pygame, which creates the window our dashboard will run in. This code creates the window and defines its' title, resolution, font and font size.

# -----------------------------
# PYGAME SETUP
# -----------------------------
pygame.init()
screen = pygame.display.set_mode((800, 480))
pygame.display.set_caption("Spotify Dashboard")

font_large = pygame.font.SysFont("Arial", 32)
font_small = pygame.font.SysFont("Arial", 22)

clock = pygame.time.Clock()


Defining the Buttons

This step will define the size and shape of the control buttons for our dashboard.

# -----------------------------
# BUTTON DEFINITIONS
# -----------------------------
BTN_PLAY = pygame.Rect(680, 50, 80, 60)
BTN_NEXT = pygame.Rect(680, 120, 80, 60)
BTN_PREV = pygame.Rect(680, 190, 80, 60)

BTN_VOL_UP = pygame.Rect(680, 260, 80, 60)
BTN_VOL_DOWN = pygame.Rect(680, 330, 80, 60)


Album Art Loader

To retrieve the album art, we will define a function to take the data from the Spotify URL. The size can be changed depending on your display, but this will fit as it is defined.

# -----------------------------
# ALBUM ART LOADER
# -----------------------------
def load_album_art(url):
try:
img_data = requests.get(url).content
image = Image.open(io.BytesIO(img_data)).convert("RGB")
image = image.resize((260, 260))
return pygame.image.fromstring(image.tobytes(), image.size, image.mode)
except:
return None


Creating a Progress Bar

To create our progress bar, Pygame takes the data from Spotify to define where the song starts, ends, and pauses. We will create a function to draw the progress bar onscreen.

# -----------------------------
# PROGRESS BAR
# -----------------------------
def draw_progress(progress, duration):
if duration == 0:
return
pct = progress / duration
pygame.draw.rect(screen, (80, 80, 80), (20, 440, 760, 20))
pygame.draw.rect(screen, (255, 255, 255), (20, 440, int(760 * pct), 20))


Spotify Helpers

This step will address the actual Spotify control within the dashboard. This code creates functions to retrieve playback data, detect volume changes, and it tells the onscreen buttons what to do.

# -----------------------------
# SPOTIFY HELPERS
# -----------------------------
def get_playback():
try:
return sp.current_playback()
except:
return None

def adjust_volume(change):
pb = get_playback()
if pb and pb["device"]:
new_vol = pb["device"]["volume_percent"] + change
new_vol = max(0, min(100, new_vol))
sp.volume(new_vol)

def toggle_playback():
pb = get_playback()
if pb and pb["is_playing"]:
sp.pause_playback()
else:
sp.start_playback()

def handle_buttons(pos):
if BTN_PLAY.collidepoint(pos): toggle_playback()
elif BTN_NEXT.collidepoint(pos): sp.next_track()
elif BTN_PREV.collidepoint(pos): sp.previous_track()
elif BTN_VOL_UP.collidepoint(pos): adjust_volume(+5)
elif BTN_VOL_DOWN.collidepoint(pos): adjust_volume(-5)

Drawing the Buttons

This step will actually draw our control buttons onscreen, and label them with their corresponding function. The labels can be customized as long as they fit within the box it sits in.

# -----------------------------
# DRAW BUTTONS
# -----------------------------
def draw_buttons():
pygame.draw.rect(screen, (40, 40, 40), BTN_PLAY)
pygame.draw.rect(screen, (40, 40, 40), BTN_NEXT)
pygame.draw.rect(screen, (40, 40, 40), BTN_PREV)
pygame.draw.rect(screen, (40, 40, 40), BTN_VOL_UP)
pygame.draw.rect(screen, (40, 40, 40), BTN_VOL_DOWN)

screen.blit(font_small.render("PLAY", True, (255,255,255)), (695, 70))
screen.blit(font_small.render("NEXT", True, (255,255,255)), (695, 140))
screen.blit(font_small.render("PREV", True, (255,255,255)), (695, 210))
screen.blit(font_small.render("VOL+", True, (255,255,255)), (695, 280))
screen.blit(font_small.render("VOL-", True, (255,255,255)), (695, 350))

Main Loop

The final step in the code is creating the while loop that will draw our dashboard completely. It will open our Pygame window, retrieve playback data, display our album art, artist name, progress bar and control buttons.

# -----------------------------
# MAIN LOOP
# -----------------------------
current_art_url = None
album_image = None

while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
if event.type == pygame.MOUSEBUTTONDOWN:
handle_buttons(event.pos)

screen.fill((0,0,0))

pb = get_playback()
if pb and pb.get("item"):
track = pb["item"]["name"]
artist = pb["item"]["artists"][0]["name"]
progress = pb["progress_ms"] / 1000
duration = pb["item"]["duration_ms"] / 1000

art_url = pb["item"]["album"]["images"][0]["url"]
if art_url != current_art_url:
current_art_url = art_url
album_image = load_album_art(art_url)

if album_image:
screen.blit(album_image, (20, 20))

# Text
screen.blit(font_large.render(track, True, (255,255,255)), (20, 300))
screen.blit(font_small.render(artist, True, (180,180,180)), (20, 340))

# Progress bar
draw_progress(progress, duration)

# Buttons
draw_buttons()

pygame.display.update()
clock.tick(30)

Opening the Dashboard

unnamed (1).jpg
  1. Save your changes with CTRL+O and close GNU nano with CTRL+X.
  2. Open a new terminal window and run the command cd ~/spotify-dashboard.
  3. Open the virtual environment with source venv/bin/activate.
  4. Start the dashboard script with python3 dashboard.py.
  5. Your dashboard should now be open! The window will be blank (seen above) until music is playing.
  6. Once music plays, you are all set!