scottlawsonbc / audio-reactive-led-strip Goto Github PK
View Code? Open in Web Editor NEW:musical_note: :rainbow: Real-time LED strip music visualization using Python and the ESP8266 or Raspberry Pi
License: MIT License
:musical_note: :rainbow: Real-time LED strip music visualization using Python and the ESP8266 or Raspberry Pi
License: MIT License
I have noticed that I can't go above 417 pixels on my regular home network even modifying the experimental branch to suit. I believe I have determined the issue to be the Maximum Transmit Unit (MTU) on my network. Even increasing BUFFER_LEN = 1024
to BUFFER_LEN = 4096
has no effect. Wireshark confirms that the python code is sending the correct packets, but nothing is receiving them.
As it is not very common to be sending packets this large, it might be necessary to incorporate a fragmentation routine to break up packets into something reasonable.
Buffer overflows. Poor performance/
Tried cutting the fps to 30 and freq bins to 12. Runs incredibly slow for some reason. RPI2
Very nice project!
Is it possible to convert your code to work with the WS2801 LED's?
I've some left from a Hyperion-project and would like to use them with a Pi ZeroW.
Hi,
I love your project and added already support for WS2801 controller with fastled, so it could possibly support even more.
But now I want to grap playing music instead of the mic input because I want to let the software run my nas. Can you give me a hint how to do that with pyaudio?
Any value over 250 throws, not 255:
pi@raspberrypi:~/src/audio-reactive-led-strip/python $ sudo python visualization.py
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
Traceback (most recent call last):
File "visualization.py", line 344, in <module>
microphone.start_stream(microphone_update)
File "/home/pi/src/audio-reactive-led-strip/python/microphone.py", line 13, in start_stream
callback(stream)
File "visualization.py", line 218, in microphone_update
led.update()
File "/home/pi/src/audio-reactive-led-strip/python/led.py", line 140, in update
_update_pi()
File "/home/pi/src/audio-reactive-led-strip/python/led.py", line 102, in _update_pi
if np.array_equal(p[:, i], _prev_pixels[:, i]):
IndexError: index 250 is out of bounds for axis 1 with size 250
pi@raspberrypi:~/src/audio-reactive-led-strip/python $ grep -ir N_PIXELS *
config.py:N_PIXELS = 251
I have a 5m strip with 300 pixels I'd quite like to get working
Hi Scott,
first of all, great project - well done!
Unfortunately, I'm stuck. A few LEDs of the strip are shining in slightly different colors, nothing else.
Everything worked fine, I've used an Wemos D1, and console shows FPS values between 59 and 61. Visualizing is working fine, it acts according to the music, that is playing with vlc (even without jack, that's hard to get up with a 3 sound devices setup...)
The LED strip is the usual 1M 18W WS2812B 5050 RGB LED, hence it fits the config out of the box. The LAN setup was easy, and worked immediately..
Hmm, leaves the Wemos as the culprit, but after loading the WebSocketsServer lib, all worked fine. The D1 is quite nice, as it contains the USB with UART controller out of the box..
Here's a picture of the wiring:
No need to do a video, it's a still image anyway ;)
Any idea, what's going wrong here?
So after trying to port this to the esp32 (Which I was successful ;) I was having issues with it complaining about the ethernet library which I figured shouldn't be in there anyway so i looked to see what was requiring it, and it was the websocketserver library. I commented that line out(where it's included) and it still compiles, and works, both on the esp8266 and the esp32...Is there a reason we're including it, or is it just left over from something in the past? if it's truly not necessary, let me know and i'll submit a pr.
Hi, I'd like to disable dynamic gain โ could you give me some pointers where should I look (I haven't yet read nor understood whole implementation)?
Any help would be appreciated.
Hello scottlawsonbc,
I browsed your other issues and found the following:
#30
Is there a fix to it yet?
I'm not using a GUI version, and it seems to me that green is not really used in the visualization.
(Though it might be, but blue/red also light in those cases thus rendering it white)
I'd like to know whether there is anything new to it.
Somebody also talked about different modes of which I do not see any. (Supposed to be commented out)
Thanks in advance!
I'm running this code on a headless RPI3 in an inaccessible location (above kitchen cabinets).
It would be great to have a systemd service as part of the git repo to allow it to begin as soon as it boots.
Trying to upload the ws2812_controller code to the ESP8266 gives an error that no such file or directory can be found for #include<WebSocketServer.h>. Is there another library or Github file that needs to be installed for this?
Running the controller program on the esp8266 will print "Connected to [network name]" and the IP address underneath in the serial monitor, however the board does not appear on the router's list of connected devices and led.py will not display on the LEDs. Any ideas? I also have one other, possibly related question: Is there a method to picking an IP address for the esp8266, or is it pretty much up to you?
New versions of the ESP8266 arduino firmware have ArduinoOTA support. This allows flashing over WiFi, and removes the need to plug in the ESP8266 into a computer each time for upgrades.
This feature may be a security risk but would be useful for testing. Ideally it would be disabled/enabled at user request.
First off, this is incredible, I'm very impressed this can all be pushed so fast over the network - really nice work.
I have a similar yet different issue to the other post, video here: https://www.youtube.com/watch?v=KS-C76DlhUA
I can't quite place my finger on what's wrong, but it's flickering a lot through random colors, and doesn't "burst" out from the center as in the demo video. Is this correct? Or is my audio analysis thing misbehaving? It does seem to focus on the center rather than show a full range. I'm using "Loopback" for OSX for a virtual audio pipe, but it was the same when I tried with a microphone.
I tried the led.py test, and it mostly seemed fine .. RGB pixel travelling down the strip, albeit with some white flickrs before and after it.
Using NodeMCU12E, standard 30led/m WS2812B strip with external psu.
thanks!
I'm really new to this so I'm not sure why it won't compile.
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
...fatal error: WebSocketsServer.h: No such file or directory
#include <WebSocketsServer.h>
^
compilation terminated.
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
Would be nice to just be able to have a 0-1v input on the ESP8166 to drive the whole thing.
Would something like this be adaptable?
http://yaab-arduino.blogspot.com.au/2015/02/fast-sampling-from-analog-input.html
Is there a way to make it use the entire LED strip? I have 150 leds and it only seems to use about half of the LED strips, no matter the song.
Scroll/spectrum seems to use all LEDS. i have the correct amount of leds in the config.py and the arduino controller
I am using the ES8266 connected to the LEDs, and have the python script set to run at startup so that all my computer sound is visualized, wether that be listening to music or playing a game or something. However, after there is no sound output for a few seconds, the led strip will start to glow blue and eventualy a white color. The visualizer shows the blue color "freaking out" per se. I am using Voicemeeter to collect the sound input, could this be causing it, or is it an issue with the visualization?
My pi seems to be running a bit slow for some reason. I'm running in CLI and I'm getting about 10 overflows a second. I set the FPS down to 10 FPS and still had the same issue. Does the pi zero normally have enough processing power to run at a higher fps?
When I run visualization.py all leds are lighting up mostly white but there are colors and they do move around? the screen shows the wave of the music and it does change a little when you switch it on the bottom? Any help would be appreciated I am new at this!
Hey!
I was messing with some of the code and I noticed that the max frequency slider disappears at lower sampling frequencies.
If MIC_RATE is set 29,400 the max frequency slider still shows, but at 22,050 that is no longer the case. This is probably because of the slider value is initiated at a fixed value, I can't look at it right now, so I'm writing it here so there's a record of it.
Thanks,
Manuel
I even played your video as the source but all i could get to happen was this: https://www.youtube.com/watch?v=VuvbHSrnNu0
I am testing on the experimental branch. When I set 60 pixels the program works flawlessly. However with 553 pixels (one of my strips got its end fried), I get a crash with ERROR_ALLOCATING_MEMORY on the ESP8266. I'm looking into the I2S module, but I am not sure what exactly causes this to fail and for what quantity.
I want to use it in a windows tablet, which doesn't have "Stereo Mix".
It shows only the Microphone.
Is there any way ?
Currently using a Pi 3 Model B with a 150 LED WS2812B strip.
When I run visualize.py, it sets all the LEDs (or as many as I set in config) to full brightness/white light. FPS is >60 which looks to be fine. It looks like it does respond to music (the middle section at least flashes different lights responding to mic input sound), but I don't think there's a spectrum effect, but this could be because there's no temporal dithering. Just ordered an ESP8266, so I'll try that tomorrow.
Only change that I did make was installing alsa-lib-1.0.25 instead of the default alsa-lib-1.1.2, since it caused some errors like this guy
I have 2 problems the first one is that I cant get the pi to recognize the usb audio? the 2nd one is when I run the sudo python strandtest.py only half of the leds come on but have no pattern just ramdom blinking doesn't start at the beginning of the strip or at the end also stops blinking then turns back on?
Hello,
thank you, this project works great overall. However it is not possible for me to use an uneven amount of LEDs in the python program. It returns this index out of bounds error:
IndexError: index 50 is out of bounds for axis 1 with size 50
Thought this would be helpful for debugging.
Thank you!
Hi @scottlawsonbc,
First of all I have to say that the work you produced is really a brilliant one, congratulations.
When I investigate this work, I figured out that an additional audio DAC/CODEC circuit would be awesome for playing audio synchronous with the RGB LED visualization. I noticed that WS2812B chip uses I2S protocol for data input and ESP8266 chip only one I2S data output pin.
First Configuration
In this case it seems that it is not possible with one I2S data output pin. Am I correct? Are there any options to drive both WS2812B and DAC/CODEC chips at the same time with ESP8266 I2S data output pin? (maybe with some kind of multiplexing)
Second Configuration
If it is not possible could we drive two synchronous ESP8266's?
Note: I know that ESP8266 recieves not raw audio data but processed data. I assumed ESP8266 recieves audio data and processed audio data from server computer
The Raspberry Pi has a hardware accelerated way to do FFT:
http://www.aholme.co.uk/GPU_FFT/Main.htm
And there are a few different ways to do this from Python:
https://github.com/colin-guyon/rpi-audio-levels
For example lightshowpi uses this for its FFT calculations:
https://bitbucket.org/togiles/lightshowpi/src/94e76f67cb9df59990acfe9a4e7eb4a443d1668c/py/fft.py?at=master&fileviewer=file-view-default
Using that would certainly would be helpful for this too.
Absolutely love this project so far, and I've been trying to add a different configuration to look something along the lines of this: https://www.youtube.com/watch?v=IXrsiUs37Jg&feature=youtu.be
Can you give me some pointers on how to navigate your code (which is already extremely well documented) to maybe figure something like this out?
Thanks!
Originally when I first tried to set this up, I could only get adafruit/neopixel examples working with my strip. I ended up remaking the code for that library and I was wondering if you wanted me to also add a neopixel example (makes it much simpler as there aren't 8 files with every sketch)
#1 --- on initial install, need to add notes to blacklist snd_bcm2835
#2 --- on initial install, need to add notes to install pyqtgraph ... e.g.:
cd /tmp
wget http://www.pyqtgraph.org/downloads/python-pyqtgraph_0.9.10-1_all.deb
sudo dpkg -i python-pyqtgraph*.deb
#3 MY PROBLEM.... I cannot get audio to work. my error is as follows:
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
ALSA lib pcm_hw.c:1667:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_hw.c:1667:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pyqtgraph/graphicsItems/AxisItem.py", line 535, in paint
self.picture.play(p)
KeyboardInterrupt
thoughts, please? Im sorry for being stupid.
When a professionally arranged lights encounter a bass drop they tend to get really bright, and I think it would be pretty cool and pretty easy to add this as a feature. Just when the lower frequencies drop out tone down the brightness and length of the display of the high pitches and have it come in harder when the low frequencies are re-introduced.
-Thanks
It looks like the GPU is much faster processing FFT.
http://www.aholme.co.uk/GPU_FFT/Main.htm
https://www.raspberrypi.org/blog/accelerating-fourier-transforms-using-the-gpu/
I just want to thank you so much for this project and my room is looking awesome with the addition of sound reactive lights.
My future request for the 'Scroll' button to have Left and Right audio stream option, so the left audio output comes through left side of the centre lights and the right side audio comes through with the right side from the centre lights.
Best way to address limit on LEDs is to change protocol to accommodate a 16bit integer value(or short) for number of LEDs.
Current format of |I|R|G|B|
, if I understand correctly is being decoded by the ESP as 8bit or 1 byte integers which have a maximum value of 255, so the I
can be a maximum of 255.
The following will format a python integer into a 16bit binary representation suitable for being placed on the wire:
Python 2.7.9 | 3.4.2
>>> '{0:016b}'.format(1)
>>> '0000000000000001'
>>> '{0:016b}'.format(255)
>>> '0000000011111111'
>>> '{0:016b}'.format(1000)
>>> '0000001111101000'
>>> '{0:016b}'.format(65535)
>>> '1111111111111111'
On the ESP sketch need to change N
to be a unsigned 16bit integer instead of 8bit:
uint16_t N = 0;
Also will now need to loop over 5 bytes at a time to incorporate the extra byte in the LED value:
for(int i = 0; i < len; i+=5) {
N = (((uint_16t)packetBuffer[i])<<8) | packetBuffer[i+1];
pixels[N].R = (uint8_t)packetBuffer[i+2];
pixels[N].G = (uint8_t)packetBuffer[i+3];
pixels[N].B = (uint8_t)packetBuffer[i+4];
}
ledstrip.show(pixels);
This changes the protocol to be more like:
|II|R|G|B|
= |0-65535|0-255|0-255|0-255|
Have not tried this but it should work.
Do not really have a strip with that many LEDs...
Am also testing NeoPixedBus as an LED Controller...
Thoughts?
When using spectrum mode I notice the green LEDs don't turn on very often - consequently, the colors are mostly purple. If I check the GUI visualization, it shows the same:
However, this is not the output shown in the GIF embedded in the README - in that case, the green channel lights regularly.
RPi3, 300 LED 5m ws2812, 5V level shifted. CPU has 1 core at 90% most of the time. FPS reduced to 28.
Hi scottlawsonbc this is an excellent project love it. I have a Uno with the built in ESP8266 chip and would love to get this working with the board but im very new to arduino. Do you have any recommendations to get this ported onto this board or would it be easier to look at a serial solution?
Thanks
Hi! I'm noticing a consistent stutter with my strip, but not any other lag.
Video: https://www.youtube.com/watch?v=a1HR7BQzPOY
Note: this is on the official code and pyaudio, not the fork I've been working on
I wrote a pretty simple ESP8266 NodeMCU Lua script for handling UDP packets for this project, including a strip fade-out when no packets are delivered for 5s. Would you be interested in a pull request for that?
The experimental code is capable of doing some neat things. Can we step this up to automatically trigger certain effects? Personally, I'd be really interested in an implementation of a multi-speed scrolling pulse effect, similar to what is found at the beginning of this video.
(The code is available here)
When running the scroll function, I end up with the error:
TypeError: Cannot cast ufunc multiply output from dtype('float64') to dtype('int32') with casting rule 'same_kind'
Specifically it doesn't like line 132 in visualize.py:
p *= 0.98
As for visualize_energy
, I can't get that one to display anything, but it doesn't give any errors.
I'm running anaconda on windows 8, and I copied and pasted the pip installs/conda installs as recommended.
update after hours of trying....
tried to run the visualization.py file , it shows error
======= RESTART: C:\Users\xxx\Desktop\audio\python\visualization.py =======
Traceback (most recent call last):
File "C:\Users\xxx\Desktop\audio\python\visualization.py", line 7, in <module>
import microphone
File "C:\Users\xxx\Desktop\audio\python\microphone.py", line 3, in <module>
import pyaudio
ImportError: No module named pyaudio
>>>
This project is only for experts ?
How do you send to multiple nodeMCUs?
I edited the code a bit so now it supports serial communication too.
I can't really test how efficient it is as I only have a small 8 LED ring (this is my first time testing the ws2812b chips).
If anyone is interested, I can make a pull request with the Arduino sketch and code modifications.
I saw that this issue has been brought up before, but I don't think it reached a clear conclusion. When I run the visualization with scroll effect, it cycles through ~5 second intervals of smooth animation followed by noticeably choppy ones, however the visualization.py fps counter doesn't show a corresponding drop in frames. Is there an easy fix for this?
Thank you for your time and effort to make this project. I have been successful running this project on my Raspi 3, but when I try to do the same on Raspi 1, I have the following issues regardless of which GPIO I try to set it to. I believe on the Rpi 1 the only choice for PWM is GPIO18 so I am frankly baffled by the error. I appreciate your help resolving this:
Gpio 18 is illegal for LED channel 0
Traceback (most recent call last):
File "visualization.py", line 9, in
import led
File "/home/pi/LED/python/led.py", line 18, in
strip.begin()
File "build/bdist.linux-armv6l/egg/neopixel.py", line 115, in begin
RuntimeError: ws2811_init failed with code -11 (Selected GPIO not possible)
munmap error
: Invalid argument
I realize that the develop
branch is still under progress, but I thought I'd give it a shot. Unfortunately, it doesn't look like it's working with my Raspberry Pi setup:
import audioled
audio, fs = audioled.stream_audio(chunk_rate=60)
effect = audioled.effects.spectrum(pixels=144, fs=fs, chunk_rate=60)
device = audioled.devices.RaspberryPi(pixels=144, pin=18, invert_logic=False, freq=800000, dma=5)
for pixels in effect(audio):
device.show(pixels)
I get the following error:
Traceback (most recent call last):
File "test.py", line 8, in <module>
for pixels in effect(audio):
File "/home/pi/audio-reactive-led-strip/audioled/effects.py", line 62, in effect
audio, fs_ds = dsp.preprocess(audio, fs, fmax, n_overlaps)
File "/home/pi/audio-reactive-led-strip/audioled/dsp.py", line 196, in preprocess
audio = pad_zeros(audio)
File "/home/pi/audio-reactive-led-strip/audioled/dsp.py", line 121, in pad_zeros
peek = next(signal)
File "/home/pi/audio-reactive-led-strip/audioled/dsp.py", line 195, in <genexpr>
audio = (x for x in audio if np.sqrt(np.mean(np.square(x))) > 1e-5)
File "/home/pi/audio-reactive-led-strip/audioled/dsp.py", line 194, in <genexpr>
audio = (x * hanning_window for x in audio)
ValueError: operands could not be broadcast together with shapes (490,) (245,)
It looks like in dsp.py
, the rollwin
function is messing something up:
def rollwin(signal, n_overlaps):
frame = next(signal)
N = len(frame)
window = np.zeros(N * n_overlaps)
window[-N:] = frame
for data in signal:
window[:-N] = window[N:]
window[-N:] = data
yield window
The first time the signal
generator is called, frame is of size 245. The next time it's iterated over (in the for loop), the size increases to 490. As far as I can tell, it keeps switching between the two. Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.