Skip to content
This is a project putting together Raspberry Pi capabilities together with Spotify. The result is an eink bedside clock featuring a remotely controllable Spotify alarm with Spotify connect capabilities.
Python Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
img
README.md
autoamp
box.svg
cron
mopidy_mpd
pialarm.py
snooze_mpd
weather_icons.tar

README.md

Raspberry E ink clock & Spotify alarm

Prerequisites

  • Files description:
    • pialarm.py - core file handling eink display and alarm
    • autoamp - script for switching the amp relay on and off
    • snooze_mpd - snooze script - "red button"
    • mopidy_mpd - turn off script - "green button"
    • cron - copy of my cron file scheduling jobs for display, buttons and wifi dongle (to keep it alive)
    • box.svg - Inkscape file with the box design
    • weather_icons.tar - weather icons

Core stuff

  • Raspberry Pi (RPI Zero in my case)

  • Network capabilities

  • E-ink display (Waveshare 4.3inch in my case)

  • microSD card to put weather icons on, any size will work

  • Weather icons (originally taken from: https://www.webpagefx.com/blog/web-design/free-icon-set-weather/)

  • Free OpenWeatherMap Account

  • All python libraries specified in the main file (note that epd library has to be configured separately)

  • Mopidy and Mopidy Alarm Clock plugin configured and working, make sure your Spotify account and audio work

Sound system

  • Apart from the Raspberry itself, it is necessary to get some other things in order to get the sound working.
    In my case that meant:

  • USB hub + Wifi dongle as Raspberry Pi Zero doesn’t have wifi

  • DAC

  • Amplifier – I’m using a cheap 2x3 W stereo amp based on pam8403 chip, powered on 3,3 V

  • Speakers – two 9 x 5 cm speakers

  • Ground loop isolator – after putting all the stuff together I encountered some serious issues with noise – I could hear the power supply, wifi dongle and CPU in speakers. Thus I bought a ground loop isolator (specifically Audac TR-2070), which solved most of the noise issues. The rest got solved by powering the amp on 3,3 V instead of 5 V (powered directly from RPI GPIO pins).

After fulfilling the prerequisites, there’re basically just few things that need to be modified in the python script.

  • Change GPIO pin number, url where Mopidy runs, OWM api key and the location where alarmLog should be saved if necessary
  • It order to get the icons work, copy them on FAT 32 formatted memory card, insert the card into the display and uncomment the epd_set_memory_sd(), epd_import_pic() and edp_set_memory_nand() parts in the script, wait for a minute or run the script manually. After that the icons should work and you can remove these parts.

I’ve attached icons that I already processed myself, they’re cropped, converted and are verified to be working.

GPIOs Layout

GPIOs layout as I'm using them can be found here: https://github.com/generalStepes/Waveshare-eink-raspberry/blob/master/img/gpios.svg

Box & Design

I'm attaching an SVG file created in Inscape with the box design I use. Laser cutter Trotec Speedy 300 was used for the creation together with a 4 mm poplar plywood.

Optional stuff

  • Amp Relay - I've added an amp relay, which turns on amp when music is played and turns it off after 30 seconds of inacitivity. The script can be found in the autoamp file (not that you'll likely have to modify the GPIO pin). Original source is: http://www.runeaudio.com/forum/auto-amplifier-on-off-t928.html - you can also find there a guide how to set it up as a service.
  • Spotify Connect - I reccomend to install a Spotify connect client (e.g. https://github.com/dtcooper/raspotify), so that you can use this bedside clock as a wireless Spotify speaker.
  • Buttons - I'm using two buttons - red one for snoozing and a green one to turn the alarm off. Also pressing the red one whilst there's no alarm set up, will set up an alarm in 15 minutes. Note that the display has to be refreshed twice to react to button press. Also don't forger to change GPIO pin number if necessary. .

Known, expected issues and to-dos

  • I’m sure that there’re some issues with getting the playlist name correctly displayed, especially when foreign accents are used. I implemented a function to remove the ones used in Czech language as I didn’t want to waste time trying to import any fonts to the E-ink display.
  • I'd like to add an equalizer to tune up the sound a bit. However this has turned out to be a bit of a hassle so far.

How does it work

The whole thing is divided into two parts: the day version and night version. The “Day” version displays clock, current date, day of week and weather information. The “night” version displays information about Spotify alarm.

  • Stuff is displayed on E-ink display via epd library. I use an E-ink display from Waveshare.
  • The display is updated once per minute, this is ensured by a cron job, after it gets updated, it’s put sleep and waken again during the next update
  • The display is cleared when the current time (minute specifically) divided by 5 is 0, i.e. every 5th minute.
  • Weather information – are fetched via pyowm library from OpenWeatherMap, thus it’s necessary to create an OWM account.
  • Spotify is provided by Mopidy, alarm clock capabilities by Mopidy Alarm Clock plugin: https://github.com/DavisNT/mopidy-alarmclock.
  • The tricky part was how to know if there’s an alarm set up. I just fetch the webpage (e.g. http://192.168.2.110:6690/alarmclock/) and check if content is more than 3000 bytes. I’m able to tell if there’s an alarm set up or not as the page size differs significantly. Nothing to be proud about, but if it looks stupid and it works, it ain’t stupid, right? :-D
  • If there’s an alarm set up, I parse the downloaded webpage and find strings for the time and playlist, which then get displayed.
  • In case RPI is rebooted, alarm is restored from the "alarmLog" file.

Changelog

30th July - added support for alarm restoration if RPI is rebooted, clearer code, other fixes
19th August - added sound system info
6th September - added box info and new photos
12th September - added GPIOs layout

alt text alt text alt text alt text alt text

You can’t perform that action at this time.