Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors running visualization.py #76

Open
WarrenLead opened this issue Jun 20, 2023 · 18 comments
Open

Errors running visualization.py #76

WarrenLead opened this issue Jun 20, 2023 · 18 comments

Comments

@WarrenLead
Copy link

WarrenLead commented Jun 20, 2023

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?

@WarrenLead WarrenLead changed the title Errors running vizualization.py Errors running visualization.py Jun 20, 2023
@pixmusix
Copy link

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
Copy link
Author

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
Copy link

strip._led_data[i] = int(rgb[i])

Strip, the instance of the Adafruit_NeoPixel 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 Adafruit_NeoPixel. I'd love to verifty when the _.led_data variable is defined.

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

@WarrenLead
Copy link
Author

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
Copy link
Owner

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
Copy link

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
Copy link
Author

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
Copy link

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

@WarrenLead
Copy link
Author

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
Copy link

@WarrenLead
Copy link
Author

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
Copy link

@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
Copy link
Author

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

@WarrenLead
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants