This is my Raspberry Pi-powered e-ink display to play song music.
You might also be interested in my projects which:
- Display high resolution album art on a Raspberry Pi-powered display
- Play albums on Sonos by tapping the album art on a hidden NFC reader
This project uses a Raspberry Pi and an e-ink display to produce a small, autonomous, low power display of what you are listening to at the moment, sourced either from Sonos or last.fm.
The Sonos implementation is much better. It runs entirely on your home network with no internet connection required. It's faster and polls the API more frequently: once ever 0.5 seconds when music is playing and once every 8 seconds when it's in "sleep mode" to conserve power. When you're not listening to music it displays a neat Sonos logo if you like:
A note on the Raspberry Pi Zero: I have set this up and got it running using a Raspberry Pi Zero, but I have run into intermittent issues on it. Unless you are super cash or space constrained I would pay the extra £10 for a Pi 3a as it'll be a much quicker development process and is much more reliable. If you are dead set on using a Zero then one workaround to get more reliable performance is to use a separate Pi somewhere else on your network to run the Sonos API and just have the Zero running the display script.
Disclaimer: this is a hobby project, unconnected with Sonos or last.fm. Use at your own risk.
Step 1: Set up your Raspberry PiIf you have a setup and running Raspberry Pi then skip to Step 2.
If you don't, then go through my super-simple, no-prior-knowledge-assumed, every-single-step-explained tutorial on how to set one up here. It takes max one hour and assumes zero prior knowledge (promise). See you back here when you're done.
Ok, on to Step 2.
Step 2: Connect the hardwareYou can use a Pi Zero or Pi 3 for this project. I haven't tried it with the Pi 4 but it does supposedly work.
The Inky wHAT will stick right on top of the Pi. No soldering or messing around is required. Pimoroni know how to make cool kit.
What is required is that you unplug it from the power first to protect yourself and the hardware.
You can also use the included spacers if you are using a B+ model or want more space.
Run these commands at the command line to ensure everything is up to date on your Raspberry Pi:
sudo apt update
sudo apt upgrade
Then type sudo raspi-config to enter the configuration menu. Enable I2C in the Interfaces menu.
Step 4: Install required software for the screenInstall the inky library with the following command:
curl https://get.pimoroni.com/inky | bash
(Note for advanced users: don't be tempted to use the pip install for the inky library - it needs to be run from the script)
Then clone the music-screen-api library from github:
git clone https://github.com/hankhank10/music-screen-api.git
sudo reboot
Step 5: Install node-sonos-http-api (assuming you want to use Sonos)The http-sonos-http-api is the bit of software that actually interfaces with our Sonos system.
Open up a Raspberry Pi command line and type the following to install the pre-requisites.
sudo apt install nodejs npm
Now let's install the actual Sonos API code:
git clone https://github.com/jishi/node-sonos-http-api.git
cd node-sonos-http-api
npm install --production
npm -- start
This should install and start the Sonos API server. Let's check if it's working.
Open a web browser on your Raspberry Pi desktop and navigate to http://localhost:5005/
(Note this will only work on the Pi itself. If you want to connect from your PC/Mac/iPhone then replace localhost with the IP address of your Pi.)
You should see a nice Sonos interface in your web browser, which shows that the API is working:
Let's check the ink-music-screen library works.
Open a new command line. Use this command for Sonos:
python3 music-screen-api/go_sonos.py
or this command for last.fm:
python3 music-screen-api/go_last.py
This will prompt you for either a Sonos room name or a last.fm username (you can use test if you like, as that is a user) and will - after a few moments of gathering information from the API - display the output on the e-ink screen.
This will run forever if we let it so press CONTROL-C to break.
FYI you can also run the command without a prompt with the following syntax:
python3 music-screen-api/go_sonos.py Kitchen
python3 music-screen-api/go_sonos.py "Dining Room"
python3 music-screen-api/go_last.py USERNAME
Step 7: Make everything run on startup and all the timeLet's do a reboot to ensure that nothing is running.
sudo reboot
Now we will install something called PM2 which will start the server every time we boot our system.
sudo npm install -g pm2
cd node-sonos-http-api
pm2 start npm -- start
This should start the Sonos server again, but this time in the background. Check it's working by going to http://localhost:5005/ in your web browser again.
Now let's get the music-screen-api to run on startup too.
From a new command line enter:
pm2 start music-screen-api/go_sonos.py --interpreter=python3 -- ROOMNAME
or the following for last.fm:
pm2 start music-screen-api/go_ink.py --interpreter=python3 -- LASTFMUSERNAMETOCHECK
Two points to note:
- There is no space between -- and interpreter; there is a space between -- and the next argument
- Don't try to run both at the same time. That way madness lies.
It should show you a status screen which shows go_sonos and npm (if you're running Sonos) both as running.
Assuming pm2 is all good let's tell pm2 to run itself on start:
pm2 startup systemd
This last command generate something which looks a bit like:
sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi
Copy what your Pi generates (not the exact text above - yours may be different) and enter it into the command line. This instructs the system to run PM2 on boot every time, which we can then use to start the programs we want to run all the time.
Then save it down to pm2:
pm2 save
You should be done. Let's reboot and try it.
sudo reboot
You're done
THANK YOU!Thank you so much for the incredible response to this and my other projects! I'm so excited that so many of you are building these cool little toys.
I've had a lot of questions about whether I will be building and selling these. The answer is definitely not: this is a hobby for me and part of the fun is the elbow grease that goes in. I think I've made the instructions possible for everyone, and I'm always here to help (reddit: u/vinylemulator) if you get stuck.
I don't accept donations but if you are inspired by my projects and want to recognise the work then you can buy me a coffee here.
Extra credit: make it beautifulYou might want to think about a cool place to put your display. These 3D printed cases look pretty neat.
Comments