naztronaut / dancyPi-audio-reactive-led

Real-time WS2812b LED strip music visualization using Python and the ESP8266 or Raspberry Pi.
https://www.easyprogramming.net/raspberrypi/audio_reactive_holiday_leds.php
MIT License
245 stars 86 forks source link

Duplicating data to another GPIO than 18 #40

Closed JonDube24 closed 3 years ago

JonDube24 commented 3 years ago

Hi! I want to send the data to two identical strips, how would I duplicate the configuration?

DEVICE == 'pi': LED_PIN = 18

What would I add?

naztronaut commented 3 years ago

It might be better to use a splitter instead of trying to send two signals. Split your data cable coming out of pin 18 to the two LED strips.

If you still want to do it via software, then you need to pick two pins with PWM and everywhere that uses LED_PIN for data write, loop and write to both strips. That might end up causing some kind of delay though in the loop, may or may not be noticeable. I haven't tested this so I'm not sure. I usually just split the data line if I need to duplicate the signal.

JonDube24 commented 3 years ago

Hi Nazmus! Thank you! I read earlier that pin GPIO 18 is duplicated to GPIO 12, I'll try that.

On Sun, Mar 21, 2021 at 11:32 PM Nazmus Nasir @.***> wrote:

It might be better to use a splitter instead of trying to send two signals. Split your data cable coming out of pin 18 to the two LED strips.

If you still want to do it via software, then you need to pick two pins with PWM and everywhere that uses LED_PIN for data write, loop and write to both strips. That might end up causing some kind of delay though in the loop, may or may not be noticeable. I haven't tested this so I'm not sure. I usually just split the data line if I need to duplicate the signal.

— 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/40#issuecomment-803736833, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATJOR2XQ5T6FJ6LA2Q2GVHLTE2235ANCNFSM4ZSBKJMA .

naztronaut commented 3 years ago

GPIO 18 and 12 are on the same channel so I'm curious if it will work. Good luck!

JonDube24 commented 3 years ago

I tried "sumo python3 visualization.py scroll" to start it but it says "syntax error" with an arrow underneath the 3 pointing at it. I think I did all the steps right, do you have an idea what the problem might be?

Also, I'm wondering about the 2 power cables from the WS2812B LED strips? They have 5 cables, 3 attached together that go to the Pi, and 2 others separately for power, I have a wall wart for that with a screw-in adapter to attach the wires to, but is the 5v from the Pi enough? If I plug that too will it just increase the brightness or fry them?

On Mon, Mar 22, 2021 at 11:53 AM Nazmus Nasir @.***> wrote:

GPIO 18 and 12 are on the same channel so I'm curious if it will work. Good luck!

— 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/40#issuecomment-804178604, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATJOR2R25BWF3X6RL3FSH23TE5RXVANCNFSM4ZSBKJMA .

naztronaut commented 3 years ago

It should be sudo not sumo :)

The power in should be 5v if you're using a WS2812b strip. I think 95% of them are 5v and the other 5 are 12v. You should make sure you use the right voltage.

The amperage on the other hand, can vary and depending on the number of LEDs you're trying to power, you may need an external power supply. I normally connect directly to the pi using about 144 LEDs with a 5v power source providing 3A of power. If you have 200+ LEDs, I'd recommend an external power source. You should check your LED strip rating for the required/recommended current.

If you do use external power, make sure everything has common ground (connect ground to power and to the Pi).

JonDube24 commented 3 years ago

oh yes, sorry this is my first time doing any programming, but I did type sudo. I seem to have followed the instructions but it's still doing the same error, should I delete what I installed and start over?

naztronaut commented 3 years ago

Can you post t he whole error? A screenshot would be helpful.

JonDube24 commented 3 years ago

python3: can't open file 'visualization.py': [Errno 2] No such file or directory

Seems like a fundamental issue LOL

But now I just checked the Python version with python --version and turns out I have Python 2.7 installed! I thought I had updated it, that should be the issue

JonDube24 commented 3 years ago

It says the version is python 2.7.16 but if I update it it says the latest version is already installed...

naztronaut commented 3 years ago

Are you in the python directory? If you do ls can you see the visualization.py file? Make sure you are in the proper location.

Also you can do python3 --version for that version. The Pi comes with both Python2 and Python3.

JonDube24 commented 3 years ago

When I type ls I get:

On Tue, Mar 23, 2021, 10:41 AM Nazmus Nasir @.***> wrote:

Are you in the python directory? If you do ls can you see the visualization.py file? Make sure you are in the proper location.

Also you can do python3 --version for that version. The Pi comes with both Python2 and Python3.

— 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/40#issuecomment-804958733, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATJOR2XDUEM6HEB4OCPXSHTTFCSBTANCNFSM4ZSBKJMA .

JonDube24 commented 3 years ago

Hi again, I wiped the SD card and started over from scratch. Same issue, the error is:

can't open file 'visualization.py': [Errno 2] No such file or directory

I know zero about programming or python. I just follow the few steps on your tutorial, and when you say "Make sure you are in the proper location" I don't know what that means, I open a black window to write commands, so what are the steps to get to the right location prior to typing "sudo python3 visualization.py scroll"?

JonDube24 commented 3 years ago

If I type ls, I see in blue:

Bookshelf Desktop Downloads Pictures Templates dancyPi-audio-reactive-led Documents Music Public Videos

JonDube24 commented 3 years ago

If I go into the dancyPi-audio-reactive-led folder, then open the python folder, and open the file visualization.py, then click RUN in the Thonny window, I get this error:

Python 3.7.3 (/usr/bin/python3)

%cd /home/pi/dancyPi-audio-reactive-led/python %Run visualization.py Can't open /dev/mem: Permission denied Traceback (most recent call last): File "/home/pi/dancyPi-audio-reactive-led/python/visualization.py", line 9, in import led File "/home/pi/dancyPi-audio-reactive-led/python/led.py", line 18, in strip.begin() File "/usr/local/lib/python3.7/dist-packages/rpi_ws281x/rpi_ws281x.py", line 131, in begin raise RuntimeError('ws2811_init failed with code {0} ({1})'.format(resp, str_resp)) RuntimeError: ws2811_init failed with code -5 (mmap() failed)

naztronaut commented 3 years ago

You're not in the right directory. Do:

cd dancyPi-audio-reactive-led/python
sudo python3 visualization.py scroll

You're in the home directory, that's why when you type ls you see all of the folders there.

The second error says that you don't have permission and you need to run it with sudo. I don't know if you have a sudo option if you right click. It's easier to see in the command prompt.

If you haven't watched the walkthrough yet, check it out here: https://www.youtube.com/watch?v=7YLF-N0596I

The "installing the software" section may be the most helpful to you.

Good luck! you're almost there!

JonDube24 commented 3 years ago

Thanks I appreciate all your help you rock. I got it to start listing FPS which is a good sign. But the lights weren't lighting and I was powering it through the Pi 5v pins but I want it to not get too hot so I'm wiring the power to the 5v wall warts I have for it. Hope it works next.

JonDube24 commented 3 years ago

It starts listing FPS (i.e. 24/50, etc.) but at the beginning it says:

pi@raspberrypi:~ $ cd dancyPi-audio-reactive-led/python pi@raspberrypi:~/dancyPi-audio-reactive-led/python $ sudo python3 visualization.py scroll 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 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 ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM iec958:{AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2 CARD 1} ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card 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

naztronaut commented 3 years ago

Those are just warnings and can be ignored. As long as you see the FPS and it doesn't stop, the app is running fine.

If the lights aren't working still, it might be a wiring problem. If you post a pic of your set up, I can take a look.

I'm going away for the weekend so I may not be able to respond until next Wednesday. Best of luck with the project this weekend!

JonDube24 commented 3 years ago

Thanks enjoy your weekend, I'll try to make it work and let you know Wednesday if I wasn't able to! I play electric guitar with effects pedals and want to make the sound activate light that will be awesome :D

JonDube24 commented 3 years ago

Looks like my led strip has 60 leds, so I change the number from 144? If I change the text in config.py it doesn't seem to work

naztronaut commented 3 years ago

Yeah you can change the N_PIXELS to 60 in config.py: https://github.com/naztronaut/dancyPi-audio-reactive-led/blob/master/python/config.py#L52

What happens when you change it? Do you get any errors or do the lights not work?

JonDube24 commented 3 years ago

Hi! I tried to change the N_PIXELS to 60 but if I open the config.py file in dancyPi and replace 144 with 60 there, an error message says: "It looks like this file or folder is not writable"

naztronaut commented 3 years ago

Ah put sudo in front. You won't have access as the base pi user. E.g.:

sudo nano config.py

Then saving should work.

JonDube24 commented 3 years ago

Hi again! I finally bought 144 LED WS2812B strips but it doesn't work :( I can run the program and see the list of FPS count run down so it should be working. Could it be that the USB audio input is not in the right port? And is the mic 3.5 jack the green or the pink one?

naztronaut commented 3 years ago

You can test the lights to make sure they work. The rpi_ws281s library has a test script you can run. Try these commands:

Download the test file to your Pi:

wget https://raw.githubusercontent.com/jgarff/rpi_ws281x/master/python/examples/strandtest.py

Edit the strandtest.py file to make sure the configuration is correct (e.g. LED Count, LED pin, etc.).

Then run:

sudo python3 strandtest.py

If the lights work then it could be the set up with the dancypi project (not as likely since you can see the FPS which means that the application is getting and processing the audio).

If the lights don't work with the test, then it's probably the connection to the lights (or the lights themselves). Check your connections, make sure they are good. And make sure you are powering the lights correctly.

Good luck!

JonDube24 commented 3 years ago

Still not working :( The test didn't light the new LEDs. I have the 5V (red), data (green = pin 18) and ground (white) wires correctly connected to the Pi with the 3 wires that are attached together but what about the two separate red and white power wires? If I power the LEDs through the Pi, these two power cables don't need to be connected to anything?

naztronaut commented 3 years ago

The two separate wires are there if you want to use external power. So you're correct that if you're powering through the Pi, you don't need to connect those.

Would you be able to post a picture of your connections? I can take a look and see if I can spot anything.

JonDube24 commented 3 years ago

Hi again! I finally got back to it, and now I'm able to make it work! The issue was that I had connected the pins to the opposite side of the LED strip! So another thing now is that I've read the GPIO 18 pin can be duplicated to the GPIO 12 that is supposed to mirror GPIO 18, how would I add 12 to the program to send the data to it too so I can activate both sides at once? Thanks so much for all your help!

naztronaut commented 3 years ago

Glad you were able to get the lights to work!

If you're just duplicating the data, why not use a splitter from one GPIO pin? It would be much simpler and require no change to the actual set up, just one splitter.

GPIO 12 and 18 are on the same channel, I'm not sure how duplicating works in this case to be honest.

JonDube24 commented 3 years ago

Oh right I can just attach the two data wires together lol

On Sun, May 2, 2021 at 3:52 PM Nazmus Nasir @.***> wrote:

Glad you were able to get the lights to work!

If you're just duplicating the data, why not use a splitter from one GPIO pin? It would be much simpler and require no change to the actual set up, just one splitter.

GPIO 12 and 18 are on the same channel, I'm not sure how duplicating works in this case to be honest.

— 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/40#issuecomment-830862410, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATJOR2XFBDPO4KFPIUOEHJ3TLWURRANCNFSM4ZSBKJMA .

naztronaut commented 3 years ago

Good luck with your project!

I'll mark this issue as closed for now but feel free to reopen or open another one if you need more help.