Spotify Car Thing_v1
A designated spotify display that can control playback, fetch track information including song duration, song artist, song album and displays lyrics. This spotify display is specially modified to fit in among non-coders by logging in wifi credentials throughout captive portal.
However for the one-time authentication part from Spotify API have to done it through a serial monitor by running the given code.
**Note this device requires Spotify Premium and external sound system e.g. phone, laptop, speaker

Why I want to build this?
- A spotify car thing manufactured from Spotify costs over 30 USD, and for aesthetics reasons, I think that it is cool to have one sitting right in front of the car dashboard.
- The original spotify car thing doesn't support lyrics display and whenever I heard a song playing in my Spotify, I have the curiosity to seek for the lyrics. But I doesn't want the lyrics to pop out in the corner of my desktop. Instead I wanted a seperate display device for this.
- Spotify discontinued their Car Thing in 2022 which then I think there is a lot of potential with this product it can bring to the car interior industry and music industry.
Why you should prefer this and not other products?
- Cheap and affordable. Products like this only uses microcontrollers to access the API through internet to get lyrics and fetch track information and display it through a friendly budget display screen.
- Doesn't have to be a "car thing", it can be a display on your table for decorating purposes.
- Flexibility. Instead of using bluetooth, this device requires wifi which is much more wider and higher bandwidth compared to bluetooth.
- Low power required. This device only borrows a little port from your device to operate, and doesn't requires a power plug for this device to work.
How to setup? (one-time setup)
- Download the sketch file code into Arduino IDE or other code editor platforms that support sketch files.
- Go to https://developer.spotify.com/dashboard and click create apps to have access to the API.
- For the redirect url, enter this url https://spotifyesp32.vercel.app/api/spotify/callback
- Copy the client ID and client secret in the developer page.
**image from developer.spotify.com
- Enter the client ID and client secret at the 16th and 17th row.

- Plug in the Spotify Car Thing into your laptop or desktop.
- Compile and upload the code into the esp32 devkit_v1.
- Open the serial monitor.
- Connect to the wifi called "SpotifyCarThing" with the password "spotify123".
- It will bring you to a captive web portal for you to enter your wifi credentials.

- Enter your wifi credentials in the text box, it can be a home wifi or your personal hotspot from your device. (the wifi have to be in 2.4 GHz Band) (IOS user have to turn on maximise compatibility)
- From the serial monitor, copy the authentication url provided and copy it into your browser to login and authenticate your spotify account.
- Play something on your Spotify app!
How to use it (in the long run)
- Powering it up
- Connect this to a 5v power supply through the micro usb slot in the left hand side of the device. A USB port from your laptop/desktop or a standard 5v USB wall charger will do.
- Play/Pause toggle switch
- Locate the middle from top to bottom switch to play or pause the current track.
- Skip track switch
- Locate the most bottom from top to bottom switch to skip forward the current playing track.
- Previous track switch
- Locate the toppest from top to bottom switch to skip backwards the current playing track.
- Reset WiFi hidden switch
- Long press on all 3 switch for 3 seconds the reset the WiFi.
- Repeat the process to enter wifi credentials
How it works
- Authentication mode
**image from developer.spotify.com
- Refresh token is the permanent credential while access token expires every hour but Spotify ESP32 library handles renewal automatically.
- Spotify ESP32 library will generate an authentication url with random state tokens that cant be duplicated and print it in the serial monitor.
- After authentication, spotify redirects to vercel.app callback which also handled by spotify ESP32 library.
- Callback exchanges authentication code for refresh token and access token.
- ESP32 receives these tokens by using this sp.handle_client() function and refresh token will be saved by using SPIFFS library in the flash memory.
- Controlling playback flow
- By setting the scopes from https://developer.spotify.com/documentation/web-api/concepts/scopes, it allows us to make a few requests to spotify api and obtain information, for this specific project I've set the scopes to user-read-playback-state, user-modify-playback-state and user-read-currently-playing.
- Refresh token is loaded and access token is constantly be renewed by Spotify ESP32 library on first API call.
- API will be called for every 1 second to obtain the real position of the specific track position.
- Obtained data from the web api will be in Json document form and will be parsed into each variable.
- Obtaining lyrics from lrclib API
- ESP32 will make HTTP requests to obtain the lyrics in Json document form containing synced lyrics and unsynced lyrics.
- Synced lyrics
- Lrclib API is a free open source lyrics API, and obtained synced lyrics comes with the format of milisecond timestamp where convertions will be handled locally by ESP 32.
- ESP32 will create it's own timestamp to match with the synced lyrics' timestamp whenever the current track started playing.
- Wifi login
- ESP32 will first check if there is any saved networks in the flash memory, if no it will execute captive portal.
- ESP32 will create a Wifi hotspot "SpotifyCarThing" by switching mode to Access point mode.
- DNSServer intercepts all DNS queries and redirect to the IP address of your ESP32.
- Browser automatically opens the setup page for user to type in their wifi credentials.
- After user types their wifi credentials, it will be saved into the flash memory of ESP32 using the Prefences library.
- ESP32 switches to station mode, and the captive portal will be closed.
- Right now, ESP32 will already have the saved wifi credentials in their flash memory, ESP32 will restart and check then connects to the wifi in the flash memory.
- TFT display management
- Rewriting the entire screen every second will cause constant visible flickering. Instead, each displayed element in NowPlayingInfo is being tracked by the variables locally.
- If the displayed elements doesnt match the current element, it will be updated.
- Text sizing is dynamic as size 2 is used by defauly and will automatically drop the size to 1 if the text is wider than the screen width which is 480px.
Parts needed
Bill of Materials
How to assemble?
- Prepare all the parts stated in the BOM
- Solder the keyboard switches onto the pcb according to the silkscreen layer.
- We'll start with attatching the ESP32 into the PCB via the connector sockets.
- Secure the PCB into the 4 tower screws with 4x 4mm m3 self-tapped screws.
- Insert and attach the 3.5'' rpi display throgh the hole of the case and into the pcb's connector header pins.
- Attach the keycaps to the keyboard switch for easier control of buttons.
Libraries installed
- Spotify Esp32 - https://github.com/FinianLandes/SpotifyEsp32.git
- Arduino Json - https://github.com/bblanchon/ArduinoJson.git
- TFT_eSPI - https://github.com/Bodmer/TFT_eSPI.git
Schematics
PCB

3D view of the PCB
To make the device more compact, I decided to add the ESP32 below the PCB.
Case
The case is being held by 4 cantilever snaps at the four corners of the case.

The PCB is being screwed into these 4 screw towers using 4x M3 screws

I got the inspiration from a retro tv specifically this type.

The case looks boxy and have slight rounded edges on the side but, for the bottom of the case, I won't make it curved as it can't be tumbling down from bumpy roads. The controls are on the right hand side and the screen is on the left hand side of the case.