-
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.
Check out the tutorial video I created for the installation:
-
Install Server
-
Install MLSC
- Automatic Setup Script
-
Manual Setup
- Download and install dependencies
- Setup Microphone
- Install Music LED Strip Controller (MLSC)
- Configure Music LED Strip Control
- Add MLSC to the autostart.
-
Install MLSC
- Install Client/Output
Preconditions
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.
You have two options for installing MLSC. You can use the automatic setup script or do a manual setup.
Run the following command in your terminal:
curl -sSL https://raw.githubusercontent.com/TobKra96/music_led_strip_control/master/setup.sh | sudo bash
After the installation was successful, continue with the following steps:
Let's start
-
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
Now reboot.
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>:8080
replace <IP_OF_RASPBERRY_PI> with the IP or hostname of the raspberry pi.
Default Port: 8080
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 34: Ground Pin for the ground cable.
Pin 12 (GPIO 18): Data Pin for the data cable.
Start MLSC and open the web interface: http://<IP_OF_RASPBERRY_PI>:8080
replace <IP_OF_RASPBERRY_PI> with the IP or hostname of the raspberry pi.
Default Port: 8080
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 18.
- Save the changes.
Now you can switch back to the Dashboard and select an effect. The LED strip should start to shine.
- Raspberry Pi 4
- WS2815 with 144 LED/m
- Power Supply with 12V 10A. Minimum needed current: 144 LEDs * 15mA = 2,16A --> 5A is the next common power supply with 12V.
- Potentiometer 0-2k Ohm
- TONOR Conference Microphone. You can use every Linux compatible USB Microphone or USB Soundcard with a connected microphone.
Use an ESP8266 as a client. The Raspberry Pi will work as a server.
For the Server and Client Architecture, we will create our own Wifi Access Point on the Raspberry Pi. This LED Wifi Network will be used for the LED Output data, which will be received by the ESP8266 clients. The Web Interface can be accessed by default Home Network via Ethernet (LAN Port with cable).
We start with the installation of the Accesspoint. It contains hostapd (the Access Point Software), dnsmasq (the DNS Server/Cache and DHCP Server) and dhcpcd (the DHCP Client).
Update the libraries:
sudo apt-get update
sudo apt-get upgrade
Install the packages
sudo apt install dnsmasq hostapd
Configure the packages
We start with the dhcp settings.
Open/create the following file:
sudo nano /etc/dhcpcd.conf
Paste the following content to the end of the file:
interface wlan0
static ip_address=172.24.26.1/24
It should look like this:
In this file, we set the static IP address of the interface wlan0
. You can choose your own static IP address.
Confirm the changes with "Ctrl+X", "Y" and "Enter".
Restart the DHCP Client Service:
sudo systemctl restart dhcpcd
We want to check if the wlan0 interface is available. Enter the following command:
ip l
You should see something like this:
Now we continue with the DNS Server. Backup the current configuration:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
Create a new config file:
sudo nano /etc/dnsmasq.conf
Enter the following lines:
# Activate the DHCP-Server for the Wifi-Interface
interface=wlan0
# DHCP-Server not active for Ethernet Network
no-dhcp-interface=eth0
# IPv4 Address Scope and Lease-Time
dhcp-range=172.24.26.0,172.24.26.255,255.255.255.0,24h
# DNS
dhcp-option=option:dns-server,172.24.26.1
Change the IP address if needed. Ensure it matches with the static IP you set before.
You can check the config with:
dnsmasq --test -C /etc/dnsmasq.conf
It should return "dnsmasq: syntax check OK."
Restart DNSMASQ:
sudo systemctl restart dnsmasq
Show the status of dnsmasq:
sudo systemctl status dnsmasq
We will see something like this:
It will be active and there should be no error.
The service should start with the system start:
sudo systemctl enable dnsmasq
Now we can configure the access point software. Create a new config file:
sudo nano /etc/hostapd/hostapd.conf
Enter the following settings:
# Interface and driver
interface=wlan0
#driver=nl80211
# Wifi Configuration
ssid=MLSC-Wifi
channel=1
hw_mode=g
ieee80211n=1
ieee80211d=1
country_code=DE
wmm_enabled=1
# Wifi Encryption
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=wifipassword
You have to change country_code
with your own country code.
Change the Wifi channel
if the network performance is low.
Change the password wpa_passphrase
Change the file rights. Only the admin should see the wifi password:
sudo chmod 600 /etc/hostapd/hostapd.conf
Check if the configuration worked:
sudo hostapd -dd /etc/hostapd/hostapd.conf
You can stop it with "Ctrl+C".
If hostapd won't start, you can try to unblock the wifi with sudo rfkill unblock all
and start hostapd again sudo hostapd -dd /etc/hostapd/hostapd.conf
.
Add hostapd to the autostart:
sudo nano /etc/default/hostapd
Add the following parameter:
RUN_DAEMON=yes
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Start hostapd and check the status:
sudo systemctl unmask hostapd
sudo systemctl start hostapd
sudo systemctl enable hostapd
sudo systemctl status hostapd
The service should be active (running).
If you are using the autostart of MLSC, we have to modify it. MLSC will start before the Access Point finished the initialization.
Open the autostart service:
sudo nano /etc/init.d/mlsc
Add sleep 30s
between cd /share/music_led_strip_control/server
and sudo python3 main.py
. This will delay the start of MLSC. I know, it's not the most elegant solution, but it works. Increase/Decrease the waiting time of 30s if you see, MLSC will start before hostapd finished the initialization.
The autostart service should look like this:
Restart the system and check if everything works.
Flash the firmware.
I am using the Ardiono IDE for flashing the software. Ensure you have installed the right board packages.
My Boardmanager URL is https://dl.espressif.com/dl/package_esp32_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json
. You can add this to the "Files/Preferences" Menu. Install the ESP Board Package inside the Board Manager and configure the Serial connections. This setting depends on your ESP Microcontroller you are using. In my case it's a NodeMCU with the following settings:
Now we have to install the needed libraries. Use the library manager for it:
ESP8266WiFi
WiFiUdp
NeoPixelBus
(NeoPixelBus by Makuna)
Open the following file: music_led_strip_control/client/udp/esp/nodemcu_client/nodemcu_client.ino
We have to modify the following variables:
-
NUM_LEDS
Number of LEDs you are using. -
ssid
The Wifi SSID of your Access Point. -
password
The password of your Access Point. -
ip
The IP, that the ESP will use. -
gateway
The Gateway IP of your Raspberry Pi. This should be the static IP you set before. -
subnet
The Subnet Mask that your Access Point use.
Now you can build the program and flash it to the ESP.
The LED of the ESP should blink during the Upload Process and the console of the Arduino IDE should show this:
Now we can start with the wiring.
Pinout
Use a Ground Pin, to share the same Ground with LED Strip and Power supply.
Use the GPIO 3 Pin (RX) for the Data Signal cable.
Start MLSC and open the web interface: http://<IP_OF_RASPBERRY_PI>:8080
replace <IP_OF_RASPBERRY_PI> with the IP or hostname of the raspberry pi.
Default Port: 8080
Switch to the Device Settings:
Add a new device with the following Settings:
- 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 Network via UDP".
- Set the IP Address of the ESP.
- The port of the UDP connection. 7777 is the default setting.
- Save the changes.
Now you can turn on the LED Strip and check if the Network Connection and the LED strip works.
There are multiple logging mechanisms implemented. The ESP Led Strip shows an LED Code during the connection phase.
LED 1: Connecting - The LED Stip tries to connect. The LED will blink.
LED 2: Reconnected - Indicates if the LED Strip reconnected to the Network.
LED 3: WL_CONNECTED - ESP connected to the Wifi Network.
LED 4: WL_NO_SHIELD - Could not find a wifi shield.
LED 5: WL_IDLE_STATUS - The wifi is in the idle state.
LED 6: WL_NO_SSID_AVAIL - Could not find the Wifi with the configured SSID.
LED 7: WL_SCAN_COMPLETED - Network scan completed.
LED 8: WL_CONNECTED - Connected to the Wifi.
LED 9: WL_CONNECT_FAILED - The connection failed.
LED 10: WL_CONNECTION_LOST - The connection to the wifi network was lost.
LED 11: WL_DISCONNECTED - The ESP disconnected from the network.
Additionally, you can monitor the serial output of the ESP. It will show you the current state.
There is a hardware limitation of the maximum amount of clients that could connect to the raspberry pi.
On the Raspberry Pi 4 it's ~8 clients. The Raspberry Pi 3b+ supports ~20.
You can use a USB WiFi Dongle with the RT5370 Chipset to increase the limit to 100+.
Download the 3D Printer Files here:
Thingiverse Download
Revision 1.0