Thirtytwopixels Save

🖼️ wireless LED album art display for spotify, mpd+ncmpcpp and other players.

Project README

thirtytwopixels

Finished build in a dark room

wireless LED album art display

Supported players:

  • mpd+ncmpcpp
  • spotify
  • other players via the command-line interface

Hardware

  • Raspberry Pi Zero WH
  • Adafruit RGB Matrix Bonnet
  • A 32x32 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.

Setup

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.

Client

Clone this repo:

git clone https://github.com/fspoettel/thirtytwopixels

Install required modules:

pip3 install -r requirements.txt

Command-line interface (CLI)

  • python3 scripts/show.py <path_to_image> displays an arbitrary image
  • python3 scripts/clear.py clears the display

MPD integration

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 its get_cover method in ./scripts/on_song_change.py. The method should return an absolute file system path to an image.

Server (Raspberry Pi)

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

Spotify

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

Pictures

Finished build in a light room
Back of finished build

In the wild

Open Source Agenda is not affiliated with "Thirtytwopixels" Project. README Source: fspoettel/thirtytwopixels
Stars
49
Open Issues
0
Last Commit
2 years ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating