Skip to content

Kwanjk/SpotifySpotlight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽต Spotify Spotlight

MKR IoT Carrier + Flask + Spotify Web API


๐Ÿ“– Overview

Spotify Spotlight connects a Spotify account to an Arduino MKR IoT Carrier using a Python Flask backend as a bridge.

The system:

  • Authenticates with Spotify using OAuth
  • Retrieves live playback information (song, artist, play/pause state)
  • Maps music characteristics (genre, popularity, explicit flag, tempo) into RGB LED colors
  • Displays a smooth, scrolling โ€œNow Playingโ€ UI on the IoT Carrier
  • Allows playback control via both capacitive touch buttons and Arduino IoT Cloud

๐Ÿ—๏ธ System Architecture

๐ŸŽต Spotify Web API

  • Provides current playback state and metadata
  • Uses OAuth 2.0 Authorization Code Flow
  • Requires a Spotify Premium account for playback control

๐Ÿ’ป Python Flask Backend (Laptop)

The Flask server acts as the central logic engine.

Authentication

  • Opens a local browser for Spotify login

  • Uses redirect URI:

    http://127.0.0.1:8888/callback
    
  • Access tokens are cached locally using Spotipy

Responsibilities

  • Receives temperature + humidity from Arduino
  • Fetches current Spotify playback state
  • Maps music context โ†’ RGB color values
  • Exposes REST endpoints for Arduino control

API Endpoints

Endpoint Description
/update_context Returns JSON with song info, playback state, and RGB values
/playpause Toggle play / pause
/next Skip to next track
/previous Go to previous track
/volume?set=XX Set volume (0โ€“100)

๐Ÿค– Arduino MKR IoT Carrier

  • Network: Connects to the same Wi-Fi network as the laptop

  • Inputs:

    • Capacitive touch buttons
    • Arduino IoT Cloud switches
  • Sensors: Reads ambient temperature and humidity

  • Outputs:

    • RGB LEDs (solid color or animated patterns)
    • TFT display with smooth scrolling song + artist text
    • Play / pause status icon

โœ… Prerequisites

  • ๐ŸŽง Spotify Premium account
  • ๐Ÿ”‘ Spotify Developer account + registered app
  • ๐Ÿ Python 3.9+
  • ๐Ÿ”Œ Arduino MKR WiFi 1010
  • ๐Ÿ“Ÿ MKR IoT Carrier
  • ๐Ÿ“ก Shared Wi-Fi network or personal hotspot (recommended)

๐Ÿš€ Setup Instructions

1๏ธโƒฃ Spotify Developer Configuration

  1. Create an app in the https://developer.spotify.com/dashboard

  2. Copy:

    • Client ID
    • Client Secret
  3. Add this Redirect URI:

    http://127.0.0.1:8888/callback
    

2๏ธโƒฃ Python Flask Backend

Create .env

SPOTIPY_CLIENT_ID=your_client_id
SPOTIPY_CLIENT_SECRET=your_client_secret
SPOTIPY_REDIRECT_URI=http://127.0.0.1:8888/callback

Install Dependencies

pip install -r requirements.txt

requirements.txt

flask
spotipy
python-dotenv
requests

Run Server

python spotify_token_server.py
  • A browser will open for Spotify login

  • Server listens on:

    http://0.0.0.0:5000
    
  • Note your laptopโ€™s LAN IP (e.g. 192.168.1.157)


3๏ธโƒฃ Arduino Configuration

Wi-Fi Credentials

Create arduino_secrets.h:

#define SECRET_SSID  "your_wifi_ssid"
#define SECRET_PASS  "your_wifi_password"

Update Server IP

In the Arduino sketch:

IPAddress serverIP(192, 168, 1, 157); // CHANGE TO YOUR LAPTOP IP

Upload Sketch

  • Board: Arduino MKR WiFi 1010
  • Upload the provided sketch

๐ŸŽฎ Running the System

  1. Start the Flask server
  2. Open Spotify on any device and start playback
  3. Power on the MKR IoT Carrier
  4. Arduino polls the server every ~10 seconds

Touch Controls

Touch Button Action
TOUCH0 Previous Track
TOUCH2 Play / Pause
TOUCH4 Next Track

๐Ÿ–ฅ๏ธ Display Features

  • Smooth horizontal scrolling for long song titles
  • Play / pause icon synced with Spotify playback
  • Minimal redraw strategy (no flicker or ghosting)
  • Color-coded song mood display

๐Ÿ’ก LED Behavior

  • TEMP Mode: Color influenced by temperature + genre
  • PATTERN Mode: Pulse / Blink animations
  • BPM Mode: Color derived from tempo and energy
  • Cloud Color Override: Manual color selection via IoT Cloud

๐Ÿ”ง Troubleshooting

Arduino Canโ€™t Connect to Server

  • Ensure same Wi-Fi network
  • Confirm IP address matches laptop
  • Check firewall allows port 5000

Spotify OAuth Errors

  • Redirect URI must match exactly
  • .env file must match Spotify dashboard
  • Restart Flask server after changes

๐Ÿง  Notes

  • Spotify playback control requires an active device
  • If playback commands fail, open Spotify manually once
  • OAuth tokens are cached to avoid repeated logins

๐Ÿ“„ License

Open source for educational use.


๐Ÿ‘ฅ Contributors

  • Joshua Kwam
  • Joseph Cin
  • Benjamin Donkor
  • Cadell Otoo
  • Oluwaemi Abiodun

INST347 โ€” Group Project Arduino + Flask + Spotify Integration

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors