Skip to content

About

Spotify BAG CHARM

Resources

Stars

74 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

Spotify Deck - ESP32 Bag Charm & Desktop Companion

A compact physical Now Playing display powered by an ESP32 and a 1.8" ST7735 SPI TFT screen. Designed in the style of the iOS Lock Screen music player, it displays song title (with smooth marquee scrolling), artist, album artwork, a live progress bar, and connection status.

The device operates in two distinct modes:

  1. Standalone Bag Charm Mode: Connects directly to your phone's mobile hotspot or home Wi-Fi via ESP32 Wi-Fi, calling the Spotify Web API directly with zero computer connection required.
  2. USB Desktop Companion Mode: Connects via USB to a Mac, Windows, or Linux machine running a Python background service that streams track info from Spotify, YouTube, or Apple Music.

Bill of Materials

Component Specification Notes
Microcontroller ESP32 Dev Module (ESP32-WROOM-32) Standard 30-pin or 38-pin board
Display 1.8" ST7735 SPI TFT (128x160) 8-pin SPI interface (black tab / red tab)
Connecting Wires Female-to-Female Dupont jumpers 8 wires for display
Power Source 5V Powerbank or 3.7V LiPo + TP4056 Powers board via Micro-USB or 5V/GND pins
Buttons Built-in BOOT button (GPIO 0) Optional external tactile buttons for Next / Prev

Wiring & Pinout

Connect the display directly to the ESP32 pins as defined in platformio.ini:

Display Pin ESP32 Pin Function
VCC 3.3V Power (3.3V regulated)
GND GND Ground
CS GPIO 5 Chip Select
RESET / RST GPIO 4 Hardware Reset
A0 / DC GPIO 2 Data / Command select
SDA / MOSI GPIO 23 SPI Data out
SCK / SCLK GPIO 18 SPI Clock
LED / BLK 3.3V Backlight power

Hardware Controls

Internal pull-ups are enabled in firmware. Connect tactile pushbuttons between the GPIO pin and GND:

Pin Function Wiring
GPIO 0 (BOOT) Play / Pause Built-in on ESP32 board (no wiring needed)
GPIO 13 Next Track Pushbutton to GND (optional)
GPIO 14 Previous Track Pushbutton to GND (optional)

Standalone Bag Charm Setup

This mode lets the ESP32 run independently using your phone's personal hotspot or home Wi-Fi.

Step 1: Spotify Developer Application

  1. Go to the Spotify Developer Dashboard and log in.
  2. Click Create app:
    • App name: Spotify Deck
    • App description: ESP32 Now Playing Charm
    • Redirect URI: http://127.0.0.1:8888/callback
    • APIs used: Web API
  3. Save the app, open Settings, and note down your Client ID and Client Secret.

Step 2: Generate Refresh Token

Install the Python dependencies and run the token helper:

pip install -r requirements.txt
python3 get_token.py

Enter your Client ID and Client Secret when prompted. Your browser will open for a one-time Spotify authentication. Once authorized, the terminal prints pre-formatted configuration definitions.

Step 3: Configure Firmware

Copy the configuration template:

cp src/config.example.h src/config.h

Edit src/config.h and supply:

  • WIFI_SSID_1 and WIFI_PASS_1: Your phone's hotspot name and password.
  • WIFI_SSID_2 and WIFI_PASS_2: (Optional) Home Wi-Fi credentials.
  • Paste the SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, SPOTIFY_REFRESH_TOKEN, and SPOTIFY_AUTH_BASIC definitions produced by get_token.py.

src/config.h is excluded by .gitignore to prevent credentials from being committed.

Step 4: Flash Firmware

Using VS Code with the PlatformIO extension:

  1. Open the project folder in VS Code.
  2. Connect the ESP32 using a data-capable USB cable.
  3. Click the PlatformIO Upload button in the bottom status bar.

Alternatively, using the PlatformIO command-line tool:

pio run --target upload

Once flashed, turn on your phone's personal hotspot. The ESP32 will connect automatically, fetch playback data from Spotify, download album artwork, and update the screen.


USB Desktop Companion Mode

If you prefer to keep the device connected to your computer via USB, use the Python companion script to capture media playback locally:

python3 spotify_deck.py

Options

Flag Description
python3 spotify_deck.py Auto-detects playback from active apps
--player spotify Force Spotify desktop app capture
--player youtube Force YouTube browser capture (Chrome / Safari / Edge)
--player apple Force Apple Music capture (macOS only)
--demo Offline simulation mode
--port <PORT> Explicitly define serial port (e.g., /dev/ttyUSB0 or COM3)

Keyboard Shortcuts

While spotify_deck.py is running in terminal:

  • Space: Play / Pause
  • n: Next track
  • p: Previous track
  • q: Quit

OS-Specific Notes

  • macOS (YouTube timeline tracking):
    • Chrome: View -> Developer -> Allow JavaScript from Apple Events.
    • Safari: Develop -> Allow JavaScript from Apple Events.
  • Windows: Install pywin32 and pyautogui for media detection (pip install pywin32 pyautogui).
  • Linux: Requires playerctl for MPRIS support (sudo apt install playerctl).

Hardware & Stability Design Notes

  • Current Spike and Flicker Mitigation: The ESP32 Wi-Fi radio draws up to 450-500 mA during high-power 802.11b/g/n transmission bursts. On a shared 3.3V rail, this causes voltage drops that reset the ST7735 internal charge pump, resulting in white screens or flickering. This firmware sets WiFi.setTxPower(WIFI_POWER_8_5dBm) and disables modem sleep (WiFi.setSleep(false)), providing clean, continuous power to the display.
  • Optimized Viewing Angle: The ST7735 panel has directional contrast. The display is initialized with tft.setRotation(1) (180-degree flip) to provide high contrast when viewed from the left or head-on.
  • Direct JPEG Decoding: Album art is streamed directly from Spotify CDN into memory and rendered on the 128x160 panel using TJpg_Decoder without writing to flash.

Troubleshooting

Issue Cause Solution
White screen / flickering Insufficient power or voltage sag Ensure TX power capping is present; verify display VCC is on 3.3V and GND is secure
Wi-Fi dot stays gray Cannot connect to hotspot Ensure hotspot is enabled and SSID/password in src/config.h are exact; on iPhone, toggle "Maximize Compatibility"
"Waiting" or "Not Playing" No active Spotify session Start playback on any device linked to your Spotify account (phone, web player, desktop)
Port not detected during flash Missing USB-to-UART driver Install CH340 or CP2102 driver for your operating system
Upload stuck on Connecting ESP32 bootloader mode Hold the BOOT button while PlatformIO displays Connecting..., then release

About

Spotify BAG CHARM

Resources

Stars

74 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages