wireless LED album art display
Supported players:
- mpd+ncmpcpp
- spotify
- home assistant
- other players via the command-line interface
- Raspberry Pi Zero WH
- Adafruit RGB Matrix Bonnet
- A 32x32 (or 64x64) LED matrix with a HUB75 connection (available on e.g. Adafruit, Pimoroni, Aliexpress). I used this one.
- A 5V 4A power adapter
Refer to the Adafruit instructions to set it up. I recommend to do the PWM mod, it removed noticeable flicker for me. This requires minor soldering.
The project is split into two parts:
- a
server
script that runs on a raspberry pi connected to the LED matrix - a client script that is invoked from
ncmpcpp
's config hooks and a CLI. Communication between client and server is handled by a 0MQ TCP socket.
Clone this repo:
git clone https://github.com/fspoettel/thirtytwopixels
Install required modules:
pip3 install -r requirements.txt
python3 scripts/show.py <path_to_image>
displays an arbitrary imagepython3 scripts/clear.py
clears the display
Add the following lines to ~/.ncmpcpp/config
:
# errors and output is appended to syslog
execute_on_song_change="(path_to_repo/scripts/on_song_change.py &> /dev/null &)"
execute_on_player_state_change = "(path_to_repo/scripts/on_player_state_change.py &> /dev/null &)"
Make sure that our hooks are executable:
chmod +x scripts/on_song_change.py
chmod +x scripts/on_player_state_change.py
If your pi is not using the host name raspberrypi.local
, you will need to adjust ZMQ_HOST
in ./client/matrix_connection.py
.
ℹ️ It is assumed that
cover.{jpg,png}
files are stored in the album folders alongside music files. If that is not the case, you'll need to implement a module analogous to./client/mpd.py
and call itsget_cover
method in./scripts/on_song_change.py
. The method should return an absolute file system path to an image.
Install raspbian on your pi and connect it to your network. ssh into it and make sure the following packages are installed:
sudo apt install python3 pip3 git libjpeg-dev
Clone this repo recursively to include the rpi-rgb-led-matrix submodule:
git clone --recursive https://github.com/fspoettel/thirtytwopixels
Install required modules. Note that the script needs to use sudo to interface with the hardware:
cd thirtytwopixels
sudo pip3 install -r requirements.txt
Setup rpi-rgb-led-matrix. This may take a while to complete.
cd matrix
make build-python PYTHON=$(which python3)
sudo make install-python PYTHON=$(which python3)
Set / adjust panel options in server/matrix_factory.py
:
def matrix_factory(width):
options = RGBMatrixOptions()
# ...
panel = RGBMatrix(options=options)
return panel
Run the server:
sudo python3 server/server.py
You can now send test images to the panel via the cli. Once you are happy with the panel config, you can add the server as a systemd
service which is started at startup. To do that, create the following file at /etc/systemd/system/thirtytwopixels.service
:
[Unit]
Description=thirtytwopixels tcp server
[Service]
ExecStart=/usr/bin/python3 /usr/local/lib/thirtytwopixels/server/server.py
[Install]
WantedBy=default.target
and move the repo to /usr/local/lib/
:
mv thirtytwopixels /usr/local/lib/
sudo chown root:root /usr/local/lib/thirtytwopixels/server/server.py
sudo chmod 644 /usr/local/lib/thirtytwopixels/server/server.py
You can then enable the service via:
sudo systemctl enable thirtytwopixels.service
Caution: the cli and socket interface currently will not work if you are using spotify. If this is an issue for you, please open a feature request.
Create a spotify application. As redirect_url, set http://localhost:9090/callback
. (feel free to change, it doesn't matter)
Then run:
export SPOTIPY_CLIENT_ID=<app client id>
export SPOTIPY_CLIENT_SECRET=<app client secret>
export SPOTIPY_REDIRECT_URI="http://localhost:9090/callback"
./scripts/spotify_login.py
Open the displayed URL in your local browser and log into spotify. It redirects you to a non-existing http://localhost:9090/callback
URL with some query params. Copy the URL and past it into the ssh terminal. If it worked, the message Succesfully logged in as user {you} should be displayed and a file .cache
should be added in the repository root.
Edit the service to include spotify credentials. Run sudo systemctl edit thirtytwopixels.service
and set enter the
[Service]
WorkingDirectory=/usr/local/lib/thirtytwopixels
Environment="SPOTIPY_CLIENT_ID=<app client id>"
Environment="SPOTIPY_CLIENT_SECRET=<app client secret>"
Environment="SPOTIPY_REDIRECT_URI=http://localhost:9090/callback"
Edit ./server/server.py
, comment out the line provider = SocketBinding(panel)
and uncomment the line provider = SpotifyBinding(panel)
.
Restart the server:
sudo systemctl restart thirtytwopixels.service
If you are using Home Assistant, and optionally Music Assistant, this can also be used to provide album art for your media.
Edit the service to include HomeAssistant credentials. Run sudo systemctl edit thirtytwopixels.service
and set
[Service]
WorkingDirectory=/usr/local/lib/thirtytwopixels
Environment="HA_BASE_URL=http://<ha_ip>:8123"
Environment="HA_ENTITY_ID=media_player.<name>"
Environment="HA_TOKEN=<long_lived_ha_token>"
Edit ./server/server.py
, comment out the line provider = SocketBinding(panel)
and uncomment the line provider = HomeAssistantBinding(panel)
.
Restart the server:
sudo systemctl restart thirtytwopixels.service
- Hackaday article
- flipflip's AlbumArtDisplay using ESP32 and Arduino
- Built something? Add it!