Music to Neopixel using Python3 on Raspberry pi

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Scope

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

https://join.slack.com/t/brisbaneroboticsclub/shared_invite/zt-efcrj9gh-lgeDXdtuc6ONfbE5dRkxvA

Application

Raspberry pi Zero

Neopixels

Linux Raspbian with X GUI (desktop)

Python 3

USB Microphone

References

Pre requisits knowledge

Raspberry Pi CLI from X GUI (desktop).

Connect neopixels to a Raspberry pi.

Python 3

pip3 installation

Github

https://github.com/brisbaneroboticsclub/audio-reactive-led-strip

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.

http://brisbaneroboticsclub.id.au/raspberry-pi-3b-pinout/

Determine your architecture

uname -a
lscpu

Install the libraries

Install neopixel library

cd

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

sudo git clone https://github.com/jgarff/rpi_ws281x.git

cd rpi_ws281x
sudo scons

cd python
sudo python3 setup.py 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 strandtest.py file.

cd rpi_ws281x/python/examples/

sudo python3 strandtest.py -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.

cd

sudo git clone https://github.com/brisbaneroboticsclub/audio-reactive-led-strip.git

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.

Change
```
defaults.ctl.card 0
defaults.pcm.card 0
```
To
```
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).

startx

Open a terminal window and enter the following command.

cd audio-reactive-led-strip/python/

sudo python3 visualization.py

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.

https://github.com/brisbaneroboticsclub/audio-reactive-led-strip/issues

Contributors

Marty.

Errors

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

Solution

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

Error (Nvidia Nano)

sudo python3 strandtest.py -c
[sudo] password for marty:
Traceback (most recent call last):
File “strandtest.py”, line 91, in
strip.begin()
File “/usr/local/lib/python3.6/dist-packages/rpi_ws281x-1.0.0-py3.6-linux-aarch64.egg/neopixel.py”, 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)

Solution

No solution yet. See our Slack channel for more info. https://app.slack.com/client/T013G365GF5/C013SRJME9G

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.