-
Notifications
You must be signed in to change notification settings - Fork 68
Installation Guide
This installation guide will help you to install your own MLSC on your Raspberry Pi.
-
Install Server
- Download and install dependencies
- Setup Microphone
- Install Music LED Strip Controller (MLSC)
- Configure Music LED Strip Control
- Add MLSC to the autostart.
-
Install Client/Output
- Local Raspberry Pi for Output
- ESP8266 Client
I used a fresh installation of "Raspberry Pi OS Lite" 2021 11th January with the Kernel version 5.4. The hostname and password were changed and SSH was activated to connect it via Putty.
-
Update the libraries:
sudo apt-get update
sudo apt-get upgrade
-
Install Audio Driver
sudo apt-get install libatlas-base-dev
sudo apt-get install portaudio19-dev
-
Install python
sudo apt-get install python3
-
Install all python libraries. I use pip for most packages:
sudo apt-get install python3-pip
- Install Pip
pip3 install --upgrade pip
- Upgrade Pip to the newest version.
sudo pip3 install -I numpy==1.17.0
- Offers a lot of mathematic functions and matrix manipulation. We need this version because 1.16 has a memory leak by using queues.
sudo pip3 install cython
Needed to build rpi_ws281x.
sudo pip3 install scipy==1.3.0
Offers a gaussian filter.
sudo pip3 install flask
The webserver component.
sudo pip3 install pyaudio
- Offer the audio input stream, which will be processed. -
Build and install ws281x library.
Search for the place you want to install the program. I will use the following location:/share
. Navigate to the root dir with:
cd /
You can create a new folder with
sudo mkdir share
Navigate to your new location with
cd /share
If you have not yet installed git you can do so with the following command:
sudo apt-get install git
Install the dependencies for ws281x library:
sudo apt-get install build-essential python3-dev git scons swig
Ensure you are in the/share
folder and clone the repository:
sudo git clone https://github.com/jgarff/rpi_ws281x.git
Move inside the cloned repository and build the project:
cd rpi_ws281x
sudo scons
The Terminal output should look like this:
Now move inside the python folder and install the python package:
cd python
sudo python3 setup.py install
Please plug-in your microphone.
Create/edit /etc/asound.conf
sudo nano /etc/asound.conf
Set the file to the following text
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
You can save changes by pressing "Ctrl+X", "Y" and "Enter".
Next, set the USB device to as the default device by editing /usr/share/alsa/alsa.conf
sudo nano /usr/share/alsa/alsa.conf
Enable the Default Card.
Change
defaults.ctl.card 0
defaults.pcm.card 0
To
defaults.ctl.card 1
defaults.pcm.card 1
Disable unused interfaces
And Change:
#
# PCM interface
#
# redirect to load-on-demand extended pcm definitions
pcm.cards cards.pcm
pcm.default cards.pcm.default
pcm.sysdefault cards.pcm.default
pcm.front cards.pcm.front
pcm.rear cards.pcm.rear
pcm.center_lfe cards.pcm.center_lfe
pcm.side cards.pcm.side
pcm.surround21 cards.pcm.surround21
pcm.surround40 cards.pcm.surround40
pcm.surround41 cards.pcm.surround41
pcm.surround50 cards.pcm.surround50
pcm.surround51 cards.pcm.surround51
pcm.surround71 cards.pcm.surround71
pcm.iec958 cards.pcm.iec958
pcm.spdif iec958
pcm.hdmi cards.pcm.hdmi
pcm.dmix cards.pcm.dmix
pcm.dsnoop cards.pcm.dsnoop
pcm.modem cards.pcm.modem
pcm.phoneline cards.pcm.phoneline
To
#
# PCM interface
#
# redirect to load-on-demand extended pcm definitions
pcm.cards cards.pcm
pcm.default cards.pcm.default
pcm.sysdefault cards.pcm.default
#pcm.front cards.pcm.front
#pcm.rear cards.pcm.rear
#pcm.center_lfe cards.pcm.center_lfe
#pcm.side cards.pcm.side
#pcm.surround21 cards.pcm.surround21
#pcm.surround40 cards.pcm.surround40
#pcm.surround41 cards.pcm.surround41
#pcm.surround50 cards.pcm.surround50
#pcm.surround51 cards.pcm.surround51
#pcm.surround71 cards.pcm.surround71
#pcm.iec958 cards.pcm.iec958
#pcm.spdif iec958
#pcm.hdmi cards.pcm.hdmi
#pcm.dmix cards.pcm.dmix
#pcm.dsnoop cards.pcm.dsnoop
#pcm.modem cards.pcm.modem
#pcm.phoneline cards.pcm.phoneline
Move the the /share
folder with:
cd /share
Clone the repository:
sudo git clone https://github.com/TobKra96/music_led_strip_control.git
All dependencies should be installed and the MLSC program was downloaded from git. Now we can execute the program and configure the main settings.
Navigate to the server folder with:
cd /share/music_led_strip_control/server
Start the program manually with:
sudo python3 main.py
You will get a terminal output like this:
The error we saw is caused by the missing microphone config.
We see:
Found the following audio sources:
1 - USB PnP Audio Device: Audio (hw:1,0) - 44100.0
2 - default - 44100.0
********************************************************
* Error *
********************************************************
Could not find the mic with the id: 0
Use the first mic as fallback.
Please change the id of the mic inside the config.
Selected ID: 1
Use 1 - USB PnP Audio Device: Audio (hw:1,0) - 44100.0
Start open Audio stream
This console output means, it found two audio inputs with the ids 1 and 2. 1 is the USB Audio Device and 2 is the default audio device.
We want to use "2 - default - 44100.0" as input device.
Keep the program running and open a web-browser on a device in the same network.
Enter http://<IP_OF_RASPBERRY_PI>
replace <IP_OF_RASPBERRY_PI> with the IP or hostname of the raspberry pi.
The Dashboard should appear. Select the General Settings in the navigation bar.
Now you should see the General Settings with "Audio Source ID" and "Default Sample Rate".
Change it to the matching entry, we saw in the console output. "2 - default - 44100.0"
--> Audio Source ID = 2 and Default Sample Rate = 44100
Press save and the entries should be applied.
Restart the program by pressing "CTRL+C" and restart it with sudo python3 main.py
. The error should be dissapeard and the program selects the input device with the id 2.
You can easily create an autostart script for the program. Every time you start the raspberry pi, the program will run. Stop MLSC if it still running.
Create the autostart script:
sudo nano /etc/init.d/mlsc
Paste the following script and change the location of mlsc if neccessarry (/share/music_led_strip_control/server):
#! /bin/sh
### BEGIN INIT INFO
# Provides: mlsc
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Music LED Strip Control
# Description:
### END INIT INFO
case "$1" in
start)
echo "Start Music LED Strip Control"
cd /share/music_led_strip_control/server
sudo python3 main.py
;;
stop)
echo "MLSC will be stopped"
# Stop program
sudo killall python3
;;
*)
echo "User: /etc/init.d/mlsc {start|stop}"
exit 1
;;
esac
exit 0
Change the rights of the script
sudo chmod 755 /etc/init.d/mlsc
Now you can test the script with:
sudo /etc/init.d/mlsc start
The server should start.
You can stop the script with:
sudo /etc/init.d/mlsc stop
To add the script into the autostart enter:
sudo update-rc.d mlsc defaults
If you want to remove the script you can enter:
sudo update-rc.d -f mlsc remove
The LED Strip, the Power Supply for the LED Strip, and the Raspberry Pi have to share the same GND. This is important for the signal. Connect all three ground connections together (Black wire in the scheme). The signal data cable will be connected between the Raspberry PI and the LED Strip. Use a resistor or potentiometer to reduce the Signal Ringing (see Wikipedia Signal Ringing). The value of the resistor depends on the cable quality and the signal cable length. It will be between 120 Ohm and 220 Ohm. I would recommend to use a potentiometer and adjust the resistance on the fly.
Use the following Pinout on the Rasberry Pi:
Pin 6: Ground Pin for the ground cable.
Pin 40 (GPIO 21): Data Pin for the data cable.
Start MLSC and open the web interface: http://<IP_OF_RASPBERRY_PI>
replace <IP_OF_RASPBERRY_PI> with the IP or hostname of the raspberry pi.
Switch to the Device Settings:
Create a new device:
Now enter the following changes:
- Switch to the newly created device. It should appear as "Default Device".
- Enter a name for the device.
- Set the max FPS. More FPS cause higher CPU usage. I would recommend using 60 frames per second.
- Enter the LED count.
- Define the mid of the LED Strip. If you use your LED strip around a corner, you can enter the number of LEDs before the corner.
- Select as "Used Output Type" "Output Raspberry Pi".
- Adjust the brightness of the LEDs.
- The GPIO Pin. Use GPIO 21.
- Save the changes.
Now you can switch back to the Dashboard and select an effect. The LED strip should start to shine.