Piano LED Visualizer


This project was inspired by the likes of Patrik Pietschmann and Rousseau, who create awesome videos of themselves playing piano covers and arrangements of popular songs. However, they don't just play them, they have their video synced to what looks like a real life Guitar Hero, or Piano Hero if you will. On top of the scrolling notes, which they seem to be hitting perfectly on time, they have LEDs that light up their hands when they hit each note, which creates the effect of the notes spilling over onto their hands. 

When I first saw Patrik Pietschmann playing a Pirates of the Caribbean medley, I knew I had to try making this setup for myself. Though I'm nowhere near as good on the piano, it will still be fun to show this project to my friends and family, and of course my youtube audience!

For this project, I followed the instructions provided by Alexander Evening, and updated them to work with the newest versions of all the required libraries. His project can be found here: github.com


1. Flash the SD card with Raspberry Pi OS (32-bit) Lite
1. Download the Lite OS from https://www.raspberrypi.org/downloads/raspberry-pi-os/
2.  Download Balena Etcher 
- https://www.balena.io/etcher/
3. Insert SD card and flash RPi OS to it using Etcher.
2. Create blank SSH file on SD Card
1. You will need to remove and reinsert the sd card
2. The SSH file should have no extension and no contents
3. This file will be deleted when the Pi boots up, but it will enable SSH
3. Create `wpa_supplicant.conf`
1. Add the file to the SD card with the contents:
2. Replace `ssid` with your WiFi network and `psk` with your password
4. Insert the SD card onto the pi and boot it up
5. SSH into the Pi
ssh pi@ip-address
2.  Username: pi
3. Password: raspberry
6. Open Raspi Config
sudo raspi-config
2. Enable SPI
1. `Interfacing Options -> SPI -> Enable` 
3. Configure auto-login to the console 
1. `Boot Options -> CLI/Console -> Auto Login to the Console` 
4. Expand the file system
1. `Advanced Options -> Expand File System`
5. Restart the system 
1. `Finish -> Restart (yes)`
7. Run the following commands
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ruby git libjack0 libjack-dev libasound2-dev python-pip libjpeg-dev zlib1g-dev
8. Create `connectall.rb` script
sudo nano /usr/local/bin/connectall.rb
2. Paste in the following:
t = `aconnect -i -l`
ports = []
t.lines.each do |l|
  /client (\d*)\:/=~l
  port = $1
  # we skip empty lines and the "Through" port
  unless $1.nil? || $1 == '0' || /Through/=~l
    ports << port
ports.each do |p1|
  ports.each do |p2|
    unless p1 == p2 # probably not a good idea to connect a port to itself
      system  "aconnect #{p1}:0 #{p2}:0"

4. Adjust permissions for connectall.rb
sudo chmod +x /usr/local/bin/connectall.rb
5. Test Connection with:
6. Check results with:
aconnect -l
9.  Configure auto MIDI connection/disconnect on USB device connect/disconnect
sudo nano /etc/udev/rules.d/33-midiusb.rules
2. Add the following to the file:
ACTION=="add|remove", SUBSYSTEM=="usb", DRIVER=="usb", RUN+="/usr/local/bin/connectall.rb"
10. Restart services 
sudo udevadm control --reload
sudo service udev restart
11. Configure MIDI connection at Boot
sudo nano /lib/systemd/system/midi.service
2. Paste the following into the file

Description=Initial USB MIDI Connect

12. Reload Daemons
sudo systemctl daemon-reload
sudo systemctl enable midi.service
sudo systemctl start midi.service
13. Clone the Repo
git clone https://github.com/onlaj/Piano-LED-Visualizer
14. CD in the Repo
cd Piano-LED-Visualizer
15.  Install all requirements in `requirements.txt`
pip install -r requirements.txt --no-cache-dir
16. Try running the visualizer 
sudo -E python visualizer.py
17.  Configure Visualizer to run at boot
sudo nano /etc/profile
2. Paste in the following at the bottom of the file:
sudo -E python /home/pi/Piano-LED-Visualizer/visualizer.py &
4. Make sure you configured the pi to auto-login to console, that is what executes the profile script.