Real-time LED strip music visualization using a Raspberry Pi 3 B+ used for a Handcart. Watch Video1/2 for example.
You cannot power the LED strip using the Raspberry Pi GPIO pins, you need to have an external 5V power supply.
The connections are:
- Connect GND on the power supply to GND on the LED strip and GND on the Raspberry Pi (they MUST share a common GND connection)
- Connect +5V on the power supply to +5V on the LED strip
- Connect Pin 18 (PWM GPIO) on the Raspberry Pi to the data pin on the LED Strip.
Install python dependencies using apt-get
sudo apt-get update
sudo apt-get install python-numpy python-scipy python-pyaudio qt5-default pyqt-dev pyqt5-dev-tools
sudo apt-get install build-essential python-dev git scons swig
git clone https://github.com/jgarff/rpi_ws281x.git
cd rpi_ws281x
scons
cd python
sudo python setup.py install
For the Raspberry Pi, a USB audio device needs to be configured as the default audio device.
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
}
Next, set the USB device to as the default device by editing /usr/share/alsa/alsa.conf
sudo nano /usr/share/alsa/alsa.conf:
Change
defaults.ctl.card 0
defaults.pcm.card 0
To
defaults.ctl.card 1
defaults.pcm.card 1
- cd rpi_ws281x/python/examples
- sudo nano strandtest.py
- Configure the options at the top of the file. Enable logic inverting if you are using an inverting logic-level converter. Set the correct GPIO pin and number of pixels for the LED strip.
- Run example with 'sudo python strandtest.py'
In config.py
, set the device to 'pi'
and configure the GPIO, LED and other hardware settings.
If you are using an inverting logic level converter, set LED_INVERT = True
in config.py
. Set LED_INVERT = False
if you are not using an inverting logic level converter (i.e. connecting LED strip directly to GPIO pin).
- Audio cable connected to the audio input jack (requires USB sound card on Raspberry Pi)
Once everything has been configured, run visualization.py to start the visualization. The visualization will automatically use your default recording device (microphone) as the audio input.
There is a setting to enable/disable the GUI display in config.py.
This project was developed by Scott Lawson and is released under the MIT License.