dancyPi-audio-reactive-led icon indicating copy to clipboard operation
dancyPi-audio-reactive-led copied to clipboard

WS2801

Open Stevelande opened this issue 4 years ago • 17 comments

Is it possible to use WS2801 type LED strips? How do I connect this? Does the program have to be changed?

Stevelande avatar Feb 23 '21 18:02 Stevelande

I had to investigate for a while and it looks like someone found a way to make this work with WS2801. Check out the thread here: https://github.com/scottlawsonbc/audio-reactive-led-strip/issues/123

I don't have WS2801 LEDs so I can't test it, but let me know if it works for you, I can add that to the list of supported hardware.

naztronaut avatar Feb 28 '21 19:02 naztronaut

Many Thanks. I will test it and then report it. I think I can do it in the course of the week.

Nazmus Nasir [email protected] schrieb am So., 28. Feb. 2021, 20:41:

I had to investigate for a while and it looks like someone found a way to make this work with WS2801. Check out the thread here: scottlawsonbc#123 https://github.com/scottlawsonbc/audio-reactive-led-strip/issues/123

I don't have WS2801 LEDs so I can't test it, but let me know if it works for you, I can add that to the list of supported hardware.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/naztronaut/dancyPi-audio-reactive-led/issues/38#issuecomment-787509904, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGMP34W5F2JUANCWUW5IDF3TBKL5ZANCNFSM4YC7RTNQ .

Stevelande avatar Mar 01 '21 12:03 Stevelande

I followed your linked instructions. I have a few problems though.Traceback (most recent call last): File "visualization.py", line 9, in <module> import led File "/home/pi/dancyPi/python/led.py", line 15, in <module> import RPi.GPIO as GPIO ModuleNotFoundError: No module named 'RPi'

solution sudo apt-get install python3-rpi.gpio

next problem Traceback (most recent call last): File "visualization.py", line 366, in <module> led.update() File "/home/pi/dancyPi/python/led.py", line 156, in update _update_pi() File "/home/pi/dancyPi/python/led.py", line 122, in _update_pi strip.show() File "/usr/local/lib/python3.7/dist-packages/Adafruit_WS2801/WS2801.py", line 73, in show self._spi.write(self._pixels) File "/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO/SPI.py", line 82, in write self._device.writebytes(data) TypeError: Non-Int/Long value in arguments: b4f87e50. I can't find a solution. But keep looking

Stevelande avatar Mar 01 '21 18:03 Stevelande

Did you make changes to led.py? Lines 156 and 122 for me are both comments so I'm wondering if your file is different.

naztronaut avatar Mar 02 '21 04:03 naztronaut

I changed the led.py like it did in the linked post.

Nazmus Nasir [email protected] schrieb am Di., 2. März 2021, 05:52:

Did you make changes to led.py? Lines 156 and 122 for me are both comments so I'm wondering if your file is different.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/naztronaut/dancyPi-audio-reactive-led/issues/38#issuecomment-788583133, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGMP34TQGT624R4XBTRGNY3TBRVHNANCNFSM4YC7RTNQ .

Stevelande avatar Mar 02 '21 06:03 Stevelande

Ah right. I didn't fully read through full file.

Try this. On line 120 change this:

strip.set_pixel(i, Adafruit_WS2801.RGB_to_color( r[i], g[i], b[i] ))

to this:

strip.set_pixel(i, Adafruit_WS2801.RGB_to_color( int(r[i]), int(g[i]), int(b[i]) ))

Just typecasting the colors to be integers. It may not work but I think that's where the issue is. The error says that you're passing a non-int value so hopefully forcing it will help you pass that error.

naztronaut avatar Mar 02 '21 06:03 naztronaut

Thank you. I will test it. I could also send you an LED strip 😁

Stevelande avatar Mar 02 '21 09:03 Stevelande

I have change line 120. The LEDs light up now. And the next error right away This is a Error with sudo python3 visualization.py scroll

ALSA lib pcm_direct.c:1271:(snd1_pcm_direct_initialize_slave) unable to install hw params ALSA lib pcm_dsnoop.c:649:(snd_pcm_dsnoop_open) unable to initialize slave ALSA lib pcm_direct.c:1271:(snd1_pcm_direct_initialize_slave) unable to install hw params ALSA lib pcm_dmix.c:1120:(snd_pcm_dmix_open) unable to initialize slave ALSA lib pcm_direct.c:1271:(snd1_pcm_direct_initialize_slave) unable to install hw params ALSA lib pcm_dmix.c:1120:(snd_pcm_dmix_open) unable to initialize 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 JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock Expression 'r' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2097 Expression 'PaAlsaStreamComponent_FinishConfigure( &self->capture, hwParamsCapture, inParams, self->primeBuffers, realSr, inputLatency )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2731 Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2843 Traceback (most recent call last): File "visualization.py", line 368, in <module> microphone.start_stream(microphone_update) File "/home/pi/dancyPi/python/microphone.py", line 14, in start_stream frames_per_buffer=frames_per_buffer) File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 750, in open stream = Stream(self, *args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 441, in __init__ self._stream = pa.open(**arguments) OSError: [Errno -9999] Unanticipated host error

This Error with sudo python3 visualization.py spectrum

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 JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock Traceback (most recent call last): File "visualization.py", line 368, in <module> microphone.start_stream(microphone_update) File "/home/pi/dancyPi/python/microphone.py", line 22, in start_stream callback(y) File "visualization.py", line 229, in microphone_update led.update() File "/home/pi/dancyPi/python/led.py", line 156, in update _update_pi() File "/home/pi/dancyPi/python/led.py", line 118, in _update_pi if np.array_equal(p[:, i], _prev_pixels[:, i]): IndexError: index 30 is out of bounds for axis 1 with size 30

This Error with sudo python3 visualization.py energy

ALSA lib pcm_direct.c:1271:(snd1_pcm_direct_initialize_slave) unable to install hw params ALSA lib pcm_dmix.c:1120:(snd_pcm_dmix_open) unable to initialize slave ALSA lib pcm_direct.c:1271:(snd1_pcm_direct_initialize_slave) unable to install hw params ALSA lib pcm_dmix.c:1120:(snd_pcm_dmix_open) unable to initialize 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 JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock Expression 'r' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2097 Expression 'PaAlsaStreamComponent_FinishConfigure( &self->capture, hwParamsCapture, inParams, self->primeBuffers, realSr, inputLatency )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2731 Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2843 Traceback (most recent call last): File "visualization.py", line 368, in <module> microphone.start_stream(microphone_update) File "/home/pi/dancyPi/python/microphone.py", line 14, in start_stream frames_per_buffer=frames_per_buffer) File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 750, in open stream = Stream(self, *args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 441, in __init__ self._stream = pa.open(**arguments) OSError: [Errno -9999] Unanticipated host error

Stevelande avatar Mar 02 '21 18:03 Stevelande

Do the lights work even with those errors? Or do the lights stop working when the errors pop up?

Those could be PyAudio errors. Can you post the outputs of t hese commands:

cat /etc/asound.conf

And

cat /proc/asound/cards

naztronaut avatar Mar 02 '21 20:03 naztronaut

The LEDs light up and stay on. Only permanent light does not blink or scroll.

cat /etc/asound.conf pcm.!default { type hw card 1 } ctl.!default { type hw card 1 }

cat /proc/asound/cards 0 [Headphones ]: bcm2835_headphonbcm2835 Headphones - bcm2835 Headphones bcm2835 Headphones 1 [Headset ]: USB-Audio - Logitech USB Headset Logitech Logitech USB Headset at usb-20980000.usb-1.2, full speed

Stevelande avatar Mar 03 '21 17:03 Stevelande

new Test. I Have 31 Leds. If I change the config.py to 30 LEDs the whole thing works. At 31 I get the error. I can look for a mistake for a long time.

/EDIT Now the LEDs also react to music. If I finish the whole thing and restart it, an error occurs 4-5 times. Then I have to restart the RPi and it works again. sudo python3 visualization.py scroll ALSA lib pcm_direct.c:1271:(snd1_pcm_direct_initialize_slave) unable to install hw params ALSA lib pcm_dsnoop.c:649:(snd_pcm_dsnoop_open) unable to initialize slave ALSA lib pcm_direct.c:1271:(snd1_pcm_direct_initialize_slave) unable to install hw params ALSA lib pcm_dmix.c:1120:(snd_pcm_dmix_open) unable to initialize slave ALSA lib pcm_direct.c:1271:(snd1_pcm_direct_initialize_slave) unable to install hw params ALSA lib pcm_dmix.c:1120:(snd_pcm_dmix_open) unable to initialize 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 JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock Expression 'r' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2097 Expression 'PaAlsaStreamComponent_FinishConfigure( &self->capture, hwParamsCapture, inParams, self->primeBuffers, realSr, inputLatency )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2731 Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2843 Traceback (most recent call last): File "visualization.py", line 368, in <module> microphone.start_stream(microphone_update) File "/home/pi/dancyPi/python/microphone.py", line 14, in start_stream frames_per_buffer=frames_per_buffer) File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 750, in open stream = Stream(self, *args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 441, in __init__ self._stream = pa.open(**arguments) OSError: [Errno -9999] Unanticipated host error

Stevelande avatar Mar 03 '21 17:03 Stevelande

Your outputs to those commands look fine.

As for LED counts, you need to use an even number. Odd numbers will give you an error. Many places in the code divide that by 2 and is expecting an integer and not a float.

It's cool that you were able to get it to work! Even if it's a short running. It's a good sign that things are working.

Do you have to restart the Pi because it becomes unresponsive? Or is it just because the lights freeze? Which version of the Pi are you using? 3b?

naztronaut avatar Mar 03 '21 21:03 naztronaut

First of all, thank you very much for your help. As an experimental setup I use an RPi 1. It should then run on a Pi2 or RPi zero. Rpi 3 is in the bedroom. To test the effect I stopped the program, at some point during the start the error occurred. The RPi has not crashed and the LEDs have not frozen.

Now a bit of fine-tuning would be needed. Sometimes it is so that when I start the program the LEDs light up continuously, the effect only starts when music is playing. It would be nice if the LEDs light up briefly or go through and then go out and then the effect runs when music is recognized.

Can I turn any screws for the sensitivity of the microphone to make the effect stronger or weaker?

What is the best way to set up an autostart when the RPi starts up?

Stevelande avatar Mar 04 '21 06:03 Stevelande

By changing the FPS and microphone sample rate in config.py I get a better result. The only thing missing is the auto start. A function would still be desirable. Switching the effect with a button on the GPIO of the RPi.

Stevelande avatar Mar 04 '21 19:03 Stevelande

Awesome! Glad you got it to work.

You may have trouble making it work on a RPi Zero. I've tried and usually starts well and then the processing becomes too intensive for the tiny processor and it fails/stalls.

As for auto start, you can try crontab. I'm pasting my comment I wrote to someone else here:

You can run the script on startup with crontab. Here's some documentation on crontab: https://www.raspberrypi.org/documentation/linux/usage/cron.md

At the very bottom, there's an example of how to use the @reboot command. This will start something whenever the pi is started.

So in your case, it would be something like:

sudo crontab -e

That will run crontab as root, then add this line:

@reboot python3 /home/pi/dancyPi-script-location/python/visualization.py scroll &

Substitute "scroll" for whichever visual you want as default.

I use crontab for my more permanent setups and it works pretty well. Good luck!

naztronaut avatar Mar 08 '21 04:03 naztronaut

I now have it running with the RPi 2 with 110 leds, it runs for hours without any problems.

I realized autostart with systemd.

I also have a script for a button on the GPIO, just not yet tested.

I have now ordered a WS2812b LED strip because I would like it to be in a different location.

The brightness settings in config.py don't work with my LEDs.

Stevelande avatar Mar 08 '21 06:03 Stevelande

Ah nice! Glad you are able to see consistent results. And Systemd is a good idea for autostart as well, good thinking.

As for the brightness, I found it to also not be very noticeable. I never looked too much into it though.

naztronaut avatar Mar 08 '21 06:03 naztronaut