This project utilizes an ESP32 module and a small OLED display to showcase the album art of the currently playing song on Spotify.
The ESP32 module connects to a Python Flask server which will process the Spotify API data and send it back with a specific format. It will then take the given data and display it on the OLED display in real-time.
- ESP32 module with WiFi connectivity. I used the ESP32 WROOM 32.
- A 1.5inch OLED Display. Here are some links: amazon.ca, adafruit.com.
- Spotify Premium account. You will need this to create a developer account and get API access.
- Arduino IDE or Visual Studio Code with the Arduino extension. You can find many tutorials to set them up to work with the ESP32.
- Go to https://developer.spotify.com/dashboard
- Press the "Create app" button
- Give your app and name and a short description
- Copy and paste the following url into the "Redirect URI" field: https://alecchen.dev/spotify-refresh-token
- Check Web API under "Which API/SDKs are you planning to use?"
- Check the I understand box to accept Spotify's Developer Terms of Service and Design Guidelines
- Next, press the "Save" button
- Now, click the "Settings" button
- Click "View client secret"
- Save the "Client ID" and "Client secret" somewhere for now, we will need them for the next step and future steps.
- Open the following website https://alecchen.dev/spotify-refresh-token/
- Here you will see fields for the Client ID and Client secret, paste them in.
- Under Scope, select the following options: 'user-read-playback-state', 'user-read-currently-playing'
- finally, click submit and the page will redirect you to a spotify login and you can click the Agree button.
- After agreeing, it will take you back to the website and you will see a new field that says 'Refresh Token'. You want to copy this to clipboard and save it for future use.
- Clone or download the repository.
- Open the
server
directory and open.env.template
- Rename the file to
.env
- Here you will see fields that will correspond to the Spotify API Tokens we just got. Paste them in after the '=' equal sign in their respective place.
- Now you can run the server in 2 different ways:
- Run using Flask
- Open terminal in the server directory
- Install packages using:
pip install -r requirements.txt
- Run the server using:
flask --app server.py --debug run --host=0.0.0.0
- The server should start up and it will tell you IP addresses that the server is running on
- On the third line of output it will say something like:
* Running on http://x.x.x.x:5000
where the x's represent any number (this will be random based on your IP address) - Copy the IP address
http://x.x.x.x:5000
and save for later use to setup the ESP32
- Run using Docker
- Make sure Docker is running
- Open a terminal in the server directory
- Run the server using:
docker image build -t flask_docker . && docker run -p 5000:5000 -d flask_docker
- Run using Flask
- Clone or download the repository.
- Open the
embedded
directory and opentemplate.env.h
- Rename the file to
env.h
- Paste your server IP address from earlier into this
- Also paste in your WiFi name and password into the corresponding fields
- Open
embedded.ino
inside your Arduino or Visual Studio Code IDE - Download and install the following Arduino libraries: Adafruit_GFX, Adafruit_SSD1351, ArduinoJson. You can find tutorials on how to install libraries online
- Run the verify command to make sure everything is running properly
- Finally run the upload command