Music to Neopixel using Python3 on Raspberry pi

Spread the love


Play that Funky Music!!! Play music on a Raspberry Pi which has NeoPixels (led’s) connected. Have the NeoPixels dance to the music.

Slack Channel

Join our slack channel to follow the projects progress. #musictoneopixel


Raspberry pi Zero


Linux Raspbian with X GUI (desktop)

Python 3

USB Microphone


Pre requisits knowledge

Raspberry Pi CLI from X GUI (desktop).

Connect neopixels to a Raspberry pi.

Python 3

pip3 installation


Connect the NeoPixels to the Raspberry Pi

Check the labels on the NeoPixels to make sure you have the correct wires.

NeoPixelRaspberry Pi
VCCPin 2 – 5V VCC
SignalPin 12 – GPIO 18
GNDPin 6 – GND

To see the Raspberry Pi pinout, click on the link below.

Determine your architecture

uname -a

Install the libraries

Install neopixel library


sudo apt-get -y install build-essential python-dev git scons swig

sudo git clone

cd rpi_ws281x
sudo scons

cd python
sudo python3 install

sudo reboot

Check neopixel was installed

Enter the following commands in the Linux CLI. This must be executed from the directory which has the file.

cd rpi_ws281x/python/examples/

sudo python3 -c

The neopixels should be lit. Only the first 16 pixels will work. To engage more pixels, open the file and change the settings. Press ‘Ctrl + C’ twice to stop.

Install SciPy.

We found it easier to install packages over SSH. There are less installation errors.

sudo pip3 install scipy

Check scipy was installed.

python3 -c "import scipy; print(scipy.__version__)"

Install pyaudio

sudo apt-get install python3-pyaudio

Check pyaudio was installed.

python3 -c "import pyaudio; print(pyaudio.__version__)"

Install pyqtgraph

sudo pip3 install pyqtgraph

Check pyqtgraph was installed.

python3 -c "import pyqtgraph; print(pyqtgraph.__version__)"

Install Github files

Clone the Brisbane Robotics Club github. Credit to Scott Lawson for creating the original. The github below was forked from the original and modified to fix issues.


sudo git clone

Edit the sound config files.

Open the sound config file using the following command.

sudo nano /etc/asound.conf

Now add the following code below to the config file.

pcm.!default {
    type hw
    card 1
ctl.!default {
    type hw
    card 1

To save and exit, press ‘Ctrl + X’, then ‘y’ to save.

Edit the USB device settings.

Now open the also config file using the command below.

sudo nano /usr/share/alsa/alsa.conf

Now make the changes as shown below.

defaults.ctl.card 0
defaults.pcm.card 0
defaults.ctl.card 1
defaults.pcm.card 1

To save and exit, press ‘Ctrl + X’, then ‘y’ to save.

Run the visualisation code

The visualisation will not run over SSH. You will need to run the program from the pi X GUI (desktop).

If your pi boots to the command line interface, enter the following to start the X GUI (desktop).


Open a terminal window and enter the following command.

cd audio-reactive-led-strip/python/

sudo python3

Place your USB microphone near any sound source.

The first 50 led’s will work. To change, edit the config file on line 52.

Did it work for you?

If this didn’t work, please message us or raise an issue on our github.




Error: Traceback (most recent call last):
File “”, line 368, in
File “/home/pi/dancyPi-audio-reactive-led-master/python/”, line 143, in update
File “/home/pi/dancyPi-audio-reactive-led-master/python/”, line 107, in _update_pi
strip._led_data[i] = rgb[i]
File “build/bdist.linux-armv6l/egg/”, line 49, in setitem
TypeError: in method ‘ws2811_led_set’, argument 3 of type ‘uint32_t’


Change line 108: “strip._led_data[i] = rgb[i]” to “strip._led_data[i] = int(rgb[i])”

Error (Nvidia Nano)

sudo python3 -c
[sudo] password for marty:
Traceback (most recent call last):
File “”, line 91, in
File “/usr/local/lib/python3.6/dist-packages/rpi_ws281x-1.0.0-py3.6-linux-aarch64.egg/”, line 106, in begin
raise RuntimeError(‘ws2811_init failed with code {0} ({1})’.format(resp, message))
RuntimeError: ws2811_init failed with code -3 (Hardware revision is not supported)


No solution yet. See our Slack channel for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.