Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Cannot re initialize NeoPixel library
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Cannot re initialize NeoPixel library

by AndrewMohawk on Wed Oct 14, 2020 1:14 am

Hey Everyone,

I am working on a project where libraries of "effects" are dynamically loaded into my project. They use the NeoPixel library but I am having a problem re-initialising the library, for example:

Code: Select all | TOGGLE FULL SIZE
>>> import board, neopixel
>>> x = neopixel.NeoPixel(board.D18,300,auto_write=False); x.fill((255,0,0)); x.show();
>>> #Strip showing red, everything is good
>>> x.deinit()
>>> #Strip is off, looks okay
>>> x = neopixel.NeoPixel(board.D18,300,auto_write=False); x.fill((0,255,0)); x.show();
>>> #No errors but strip is not responsive

I am using a Pi4 with the following libraries:
Code: Select all | TOGGLE FULL SIZE
Adafruit-Blinka                   5.5.2     
adafruit-circuitpython-neopixel   6.0.0     
adafruit-circuitpython-pypixelbuf 2.2.0


I've tried many different things from calling de-init on the pin object, to trying to instantiate a neopixel on a different pin to just del(x) on the object.

I suspect the issue sits somewhere in the NeoPixel library, since if I deinit and then delete the object, if I try make a NeoPixel object on another pin I get the following:
Code: Select all | TOGGLE FULL SIZE
>>> x = neopixel.NeoPixel(board.D18,300,auto_write=False); x.fill((255,0,0)); x.show();
>>> x.deinit()
>>> del(x)
>>> y = neopixel.NeoPixel(board.D19,300,auto_write=False); y.fill((255,0,0)); y.show();
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/adafruit_pypixelbuf.py", line 206, in show
    return self._transmit(self._post_brightness_buffer)
  File "/usr/local/lib/python3.7/dist-packages/neopixel.py", line 167, in _transmit
    neopixel_write(self.pin, buffer)
  File "/usr/local/lib/python3.7/dist-packages/neopixel_write.py", line 24, in neopixel_write
    return _neopixel.neopixel_write(gpio, buf)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/bcm283x/neopixel.py", line 80, in neopixel_write
    raise RuntimeError("Raspberry Pi neopixel support is for one strip only!")
RuntimeError: Raspberry Pi neopixel support is for one strip only!


If someone can point me in the right direction that would be awesome, I dont mind modifying the libraries and making PRs, I just cant find where this is going wrong, I've also put it as an issue on the circuitpython page here: https://github.com/adafruit/Adafruit_Ci ... /issues/94

Thank you :)
-AM

AndrewMohawk
 
Posts: 1
Joined: Wed Oct 14, 2020 1:05 am

Re: Cannot re initialize NeoPixel library

by dastels on Wed Oct 14, 2020 10:24 am

Maybe set x to None and force a garbage collection before creating a new NeoPixel object?

Dave

dastels
 
Posts: 3767
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.