Skip to content

alexthescott/ePaper-Spotify-Clock

Repository files navigation

RaspberryPi E-Paper Spotify Clock

🕰️ Quick Project Overview

This is a E-Paper Clock built with Python3 to display two users' recent Spotify history, and the local weather. Written for Waveshare's 4.2 e-paper display, the E-Paper Clock uses Spotify's API via Spotipy to display the recent listening information, and the OpenWeathermap API to get the current and forecasted local weather. Email me, atscott@ucsc.edu, if you have any questions regarding the implementation, suggestions to improve the project, or if you built one yourself!

2024 rewrite notes

Install imagemagick via sudo apt-get install imagemagick as it's used in dither_image()

⌛ Quick Install Guide

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 forecast, and the Spotipy wrapper interfaces with Spotify's API

Drive the EPD, call necessary functions -> mainSpotifyClock.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, place the generated Spotify Client Id, Client Secret and openWeatherMap key into config/keys.json

  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