MKR IoT Carrier + Flask + Spotify Web API
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
- Provides current playback state and metadata
- Uses OAuth 2.0 Authorization Code Flow
- Requires a Spotify Premium account for playback control
The Flask server acts as the central logic engine.
-
Opens a local browser for Spotify login
-
Uses redirect URI:
http://127.0.0.1:8888/callback -
Access tokens are cached locally using Spotipy
- Receives temperature + humidity from Arduino
- Fetches current Spotify playback state
- Maps music context โ RGB color values
- Exposes REST endpoints for Arduino control
| 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) |
-
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
- ๐ง 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)
-
Create an app in the https://developer.spotify.com/dashboard
-
Copy:
- Client ID
- Client Secret
-
Add this Redirect URI:
http://127.0.0.1:8888/callback
SPOTIPY_CLIENT_ID=your_client_id
SPOTIPY_CLIENT_SECRET=your_client_secret
SPOTIPY_REDIRECT_URI=http://127.0.0.1:8888/callbackpip install -r requirements.txtrequirements.txt
flask
spotipy
python-dotenv
requestspython 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)
Create arduino_secrets.h:
#define SECRET_SSID "your_wifi_ssid"
#define SECRET_PASS "your_wifi_password"In the Arduino sketch:
IPAddress serverIP(192, 168, 1, 157); // CHANGE TO YOUR LAPTOP IP- Board: Arduino MKR WiFi 1010
- Upload the provided sketch
- Start the Flask server
- Open Spotify on any device and start playback
- Power on the MKR IoT Carrier
- Arduino polls the server every ~10 seconds
| Touch Button | Action |
|---|---|
| TOUCH0 | Previous Track |
| TOUCH2 | Play / Pause |
| TOUCH4 | Next Track |
- 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
- 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
- Ensure same Wi-Fi network
- Confirm IP address matches laptop
- Check firewall allows port 5000
- Redirect URI must match exactly
.envfile must match Spotify dashboard- Restart Flask server after changes
- Spotify playback control requires an active device
- If playback commands fail, open Spotify manually once
- OAuth tokens are cached to avoid repeated logins
Open source for educational use.
- Joshua Kwam
- Joseph Cin
- Benjamin Donkor
- Cadell Otoo
- Oluwaemi Abiodun
INST347 โ Group Project Arduino + Flask + Spotify Integration