ePaper-Spotify-Clock icon indicating copy to clipboard operation
ePaper-Spotify-Clock copied to clipboard

ePaper Clock with two user's Spotify info and the weather using Waveshare's 4.2inch EPD

4.2in E-Paper Spotify Weather Clock

This project uses Python3 to display two users' recent Spotify history, weather for two cities (local and away), and the current time

Written for Waveshare's 4.2 e-paper display, this project connects with Spotify's API to display the most recent listening information, including the title, artist, context, and time since the track was played. There is a left and right panel so that two folk's listening can be displayed at the same time. The forcast and current weather are also displayed via the OpenWeatherMap api. The e-paper display updates in full every 3 minutes per Waveshare's recommendations. After 8pm, the display updates every 5 minutes, and does not update from 2am - 6am. Before you ask, I am using the Nintendo DS BIOS font for this project because it looks beautiful. Email me, [email protected], if you have any questions regarding the implementation, suggestions to improve the project, or if you built one yourself!

⌛ Quick Overview

Waveshare provides a set of instructions under the Hardware/Software setup tab to install the libraries required to drive the display. I'm using a Raspberry Pi Zero W running this bash script in rc.local to run mainSpotifyClock.py. Three custom Python modules were used, Spotipy, Requests, and Pillow aka PIL, all of which can be installed using Pip. Openweathermap gets the current weather and forcast, and the Spotipy wrapper interfaces with Spotify's API

Drive the EPD, call necessary functions -> mainSpotifyEPD.py

Image and Front Resources -> Icons and Fonts

⏳ Full Instillation Guide

  1. In the 'Hardware/Software setup' tab of Waveshare's 4.2inch wiki, use the GPIO guide to attach the display to the Pi

  2. Enable SPI interface by launching raspi-config, choosing 'Interfacing Options', 'SPI', Yes to enable SPI interface

sudo raspi-config
# Interfacing Options -> SPI -> Yes
  1. Install Python libraries
sudo apt-get update
sudo apt-get install git python3-pip python3-pil python3-numpy
sudo pip3 install RPi.GPIO
sudo pip3 install spidev
sudo pip3 install spotipy
sudo pip3 install requests

As an aside, sudo pip install is generally frowned upon, but these are popular and vetted packages which won't pose security threats to your system

  1. Download Waveshare Examples and Python Libraries
sudo git clone https://github.com/waveshare/e-Paper
  1. Navigate to Pi/Python folder, and Install 'waveshare-epd' Python module from setup.py
cd e-Paper/RaspberryPi\&JetsonNano/python
sudo python3 setup.py install
  1. Navigate to Pi/Python/examples folder, and run the Waveshare's provided example file to make sure the wiring is correct
cd examples
sudo python3 epd4in2.py
  1. Clone this repository into the examples folder
sudo git clone https://github.com/alexthescott/ePaper-Spotify-Clock
  1. Use a text editor such as Vim, Emacs or nano open launch_epaper.sh and replace YOUR_USERNAME, then move file into your home directory
# If you choose Vim, first open the file
vim launch_epaper.sh
# Press i for insert mode, replace USERNAME, then write and quit with :wq
:wq
# Move to launch_epaper.sh to home directory
mv launch_epaper.sh /$HOME
  1. For both Spotify users, login to the Spotify Developer Portal, create an app, write down the Client ID and Client Secret as we will use these later

  2. On the Spotify Developer Portal, add http://www.google.com/ as the Redirect URI, and save at the bottom

  3. Create a free OpenWeatherMap account, and navigate to your profile, and then API keys. Generate and store a new key as it will be inserted into mainSpotifyEPD.py

  4. Using a text editor, at the bottom of mainSpotifyEPD.py, insert both Spotify user's username, Client Secret, and Client ID. Additionally, in the getWeather function, insert your OpenWeatherMap API, and City Id's which can be found here

  5. Navigate to your home directory, make launch_epaper.sh an executable, and then run it as the super user

cd $HOME
chmod +x launch_epaper.sh
sudo ./launch_epaper.sh
  1. You will be asked to paste two URLs into a web browser to link the Spotify accounts to the project. The first request corresponds with the user on the left, and the second request corresponds with the user on the right. After accepting Spotify's terms, copy and paste the full Google url back into the terminal.

  2. If everything runs well, consider adding launch_epaper.sh to rc.local which runs at boot

sudo vim /etc/rc.local
# above exit 0, add 'bash /home/YOUR_USERNAME/launch_epaper.sh &'
  1. Give yourself three cheers for following along and building the project! Huzzah 🎉

If you made this project, I'd love to see it! Send me an email with a photo of your finished project