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
237 stars 87 forks source link

Errors running visualization.py #76

Open WarrenLead opened 1 year ago

WarrenLead commented 1 year ago

When I issue the command "sudo python3 visualization.py scroll" I get an error

Traceback (most recent call last): File "/home/pi/dancyPi-audio-reactive-led/python/visualization.py", line 418, in led.update() File "/home/pi/dancyPi-audio-reactive-led/python/led.py", line 144, in update _update_pi() File "/home/pi/dancyPi-audio-reactive-led/python/led.py", line 108, in _update_pi strip._led_data[i] = int(rgb[i]) AttributeError: 'Adafruit_NeoPixel' object has no attribute '_led_data'

Any ideas?

pixmusix commented 1 year ago

Hello. From the led.py file in the repo I found this code.

elif config.DEVICE == 'pi':
    from rpi_ws281x import *
    strip = Adafruit_NeoPixel(config.N_PIXELS, config.LED_PIN,
                                       config.LED_FREQ_HZ, config.LED_DMA,
                                       config.LED_INVERT, config.BRIGHTNESS)
    strip.begin()

This object, strip, is a instance of the class Adafruit_NeoPixel and this is throwing the AttributeError.

I notice the constructor of Adafruit_NeoPixel takes constants from the config.py file. Can you confirm you followed step seven from the README file under "Setup and Configuration"

  1. In config.py:
    • Set N_PIXELS to the number of LEDs in your LED strip (must match NUM_LEDS in ws2812_controller.ino)
    • Set UDP_IP to the IP address of your ESP8266 (must match ip in ws2812_controller.ino)
    • If needed, set MIC_RATE to your microphone sampling rate in Hz. Most of the time you will not need to change this.
WarrenLead commented 1 year ago

Hi

Yes I have set the number of pixels etc in the config.py file.

It doesn't seem to like the code "strip._led_data[i] = int(rgb[i])" it thinks _led_data is an attribute of Adafruit_NeoPixel

If I comment that line out the code runs but obviously the LEDs don't work.

Regards Warren

pixmusix commented 1 year ago
strip._led_data[i] = int(rgb[i])

Strip, the instance of the AdafruitNeoPixel object, must have a .led_data param in it's __new__(): or __init__(): funcs. The underscore, although not enforcing, usually denotes an internal item. Internal as in something only the class is meant to know about; something you're not meant to reach into the instance of and modify. I cannot for the life of me find where @naztronaut has defined AdafruitNeoPixel. I'd love to verifty when the .led_data variable is defined.

@naztronaut can you point me in the right direction please? 😃

WarrenLead commented 1 year ago

I can see it in [rpi_ws281x] (https://github.com/richardghirst/rpi_ws281x/tree/master)/[python](https://github.com/richardghirst/rpi_ws281x/tree/master/python) /neopixel.py

Maybe I have the wrong one?

naztronaut commented 1 year ago

Hi, It's been a few years since I worked on the project, will do my best to help. Did you install the rpi_ws281x library? The Adafruit_neopixel() function is defined there as @WarrenLead pointed out.

pixmusix commented 1 year ago

Good find @WarrenLead.

Here is our definition on line 83 in neopixel.py

## Grab the led data array.
self._led_data = _LED_Data(self._channel, num)

Perhaps the interpreter can't find rpi_ws281x as @naztronaut suggested.

Alternatively I remember reading somewhere that python slots sometimes hides variables by pre-pending a second underscore to their variables. However if that's the case the issue would need to be moved to rpi_ws281x.

WarrenLead commented 1 year ago

My rpi_ws281x was already installed by sudo pip3 install rpi_ws281x for another project and it is working.

I also have

sudo pip3 install adafruit-circuitpython-neopixel sudo python3 -m pip install --force-reinstall adafruit-blinka

installed

pixmusix commented 1 year ago

@naztronaut does you're library require a specific version? 😄

WarrenLead commented 1 year ago

Yes it would appear the version I have is different as it doesnt have the _led.data

_## Grab the led data array. self._led_data = _LED_Data(self.channel, num)

How do I install the correct one?

pixmusix commented 1 year ago

Since you installed with pip you can use the --upgrade or the -U flag

WarrenLead commented 1 year ago

Looks like rpi_ws281x was updated to v5.0.0 approx 2 months ago and _led_data was removed. Previous version has it, I.e 4.3.4 see https://pypi.org/project/rpi-ws281x/4.3.4/ I will try to install this.

pixmusix commented 1 year ago

@WarrenLead let me know if this works? It will depend on your version of Python.

sudo pip3 install rpi_ws281x==4.3.4

@naztronaut would you like some assistance modernizing the code to be compatible with the modification to rpi_ws281x?

WarrenLead commented 1 year ago

Installing 4.3.4 fixed the _led_data issue but I obviously have other compatibility issues as it is still not working.

WarrenLead commented 1 year ago

Hi @naztronaut

Any chance you (or anyone else) can give this a go using a Pi 4 and current libraries to expose issues?

I followed the install procedure described and had numerous issues. I worked through installing and reinstalling step by step and found I needed rpi_ws281x v4.3.4 as current version 5 is not compatible. I also had problems with the audio libraries.

I just cant get it to function any lights. I know I am close I just cant get over the last hurdle. I would love to get this working.

Regards Warren

WarrenWillis commented 1 year ago

I am a linux newbie and am having similar problems to WarrenLead. Fixed the rpi_ws281x version problem and visualization now runs to the point where it turns LEDs on, but getting server socket errors and invalid input device error - Alsa not recognising USB mic. After several hours of trying to get this working, would really love to have a solution before Christmas. Regards WarrenW

WarrenLead commented 1 year ago

I am a linux newbie and am having similar problems to WarrenLead.

Hi Warren

I couldnt get the audio part working and I spent hours and hours getting nowhere so I gave up. I ended up buying a couple of nice Wifi LED controllers on ebay for about $20 bucks each, which work great, but it is a shame because I really was enjoying playing with the lights on the Ras Pi.

I'm all primed and ready for Christmas now :-)

tiagonmas commented 9 months ago

I was able to put it to work after running some of the suggestions here. Leds are going on ... but not producing the effect in the video. But it's a start.

OnlyOneByte commented 3 months ago

Howdy everyone! Just wanted to add in that if anyone is having this problem, rather than downgrade the Adafruit library, you can change it to:

strip.setPixelColor(i, int(rgb[i]))

and it should also work.