adafruit / Adafruit_CircuitPython_NeoPixel_SPI

SPI driven CircuitPython driver for neopixels.
MIT License
21 stars 11 forks source link

Example broken under Blinka in Python 3.6.4 on Windows 10 #8

Closed XFactHD closed 4 years ago

XFactHD commented 4 years ago

When trying to run the NeoPixel_SPI example in Python 3.6.4 on Windows 10 I get the following error:

Traceback (most recent call last):
  File "neo_test.py", line 15, in <module>
    auto_write=False)
  File "c:\users\dc\appdata\local\programs\python\python36\lib\site-packages\neopixel_spi.py", line 117, in __init__
    self.buf = bytearray(self.n * self.bpp)
AttributeError: can't set attribute

The code (slightly modified):

import time
import board
import neopixel_spi as neopixel

NUM_PIXELS = 1
PIXEL_ORDER = neopixel.GRBW
COLORS = (0xFF0000, 0x00FF00, 0x0000FF)
DELAY = 0.1

spi = board.SPI()

pixels = neopixel.NeoPixel_SPI(spi,
                               NUM_PIXELS,
                               pixel_order=PIXEL_ORDER,
                               auto_write=False)

while True:
    for color in COLORS:
        for i in range(NUM_PIXELS):
            pixels[i] = color
            pixels.show()
            time.sleep(DELAY)
            pixels.fill(0)

The versions of the libraries I am using:

Adafruit-Blinka                     3.4.1
adafruit-circuitpython-busdevice    4.1.1
adafruit-circuitpython-neopixel     4.1.0
adafruit-circuitpython-neopixel-spi 0.3.1
adafruit-circuitpython-pypixelbuf   1.0.1
Adafruit-PlatformDetect             1.4.4
Adafruit-PureIO                     1.0.4
pyftdi                              0.42.2
pyusb                               1.0.2

I currently cannot test any further on another PC or CircuitPython powered MCU.

caternuson commented 4 years ago

What hardware are you using to provide a SPI port on the Windows machine?

XFactHD commented 4 years ago

I am using an Adafruit FT232H Breakout board.

caternuson commented 4 years ago

Thanks. That should be fine.

I think this might be related to changes in the NeoPixel library related to pixelbuf. I just tested on a Pi and recreated the issue:

(neopixel_spi) pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> import neopixel_spi as neopixel
>>> pixels = neopixel.NeoPixel_SPI(board.SPI(), 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/neopixel_spi/lib/python3.7/site-packages/neopixel_spi.py", line 117, in __init__
    self.buf = bytearray(self.n * self.bpp)
AttributeError: can't set attribute
>>> 

Thanks for pointing this out. Investigating...

caternuson commented 4 years ago

Please try the 0.3.2 release: https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel_SPI/releases/tag/0.3.2

XFactHD commented 4 years ago

I will test it later and come back to you with the results.

XFactHD commented 4 years ago

I have now tested the fix, works as intended now. Thanks for the quick fix.

One thing I discovered while testing is that RGBW pixels can not be controlled with the library, attempting to pass a 4 Byte value as a color throws a ValueError. Should I create another issue for that or do you want to handle that here? I will update this issue or a new one with the error message as soon as I am back at my PC.

caternuson commented 4 years ago

Cool. Glad that fixed it. Let's close this one.

For the ValueError issue, try using a tuple instead of a 32bit value. See here: https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/issues/50

XFactHD commented 4 years ago

Okay, thanks for the hint, I will try that.