Skip to content

Can't set brightness in NeoPixel() #85

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

Closed
LukeMoll opened this issue May 28, 2020 · 9 comments · Fixed by adafruit/Adafruit_CircuitPython_Pypixelbuf#21
Closed

Can't set brightness in NeoPixel() #85

LukeMoll opened this issue May 28, 2020 · 9 comments · Fixed by adafruit/Adafruit_CircuitPython_Pypixelbuf#21
Labels

Comments

@LukeMoll
Copy link

import board
import neopixel

# Causes error
pixels = neopixel.NeoPixel(board.A15, 8, brightness=0.5) 

# works fine
pixels = neopixel.NeoPixel(board.A15, 8, brightness=1.0) 
pixels.brightness = 0.5 

Setting brightness to than 1.0 in NeoPixel() causes the following error:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
  File "neopixel.py", line 131, in __init__
  File "adafruit_pypixelbuf.py", line 103, in __init__
  File "adafruit_pypixelbuf.py", line 187, in brightness
  File "adafruit_pypixelbuf.py", line 206, in show
  File "neopixel.py", line 167, in _transmit
AttributeError: 'NeoPixel' object has no attribute 'pin'

I believe this is attributed to self._transmit being called (referencing self.pin) by pypixelbuf as part of super().init, before self.pin is initialised on line 135.

Tested with Adafruit CircuitPython 5.3.0 on 2020-04-29; stm32f411ce-blackpill with STM32F411CE, CircuitPython bundle 5.x 20200526.

@tannewt
Copy link
Member

tannewt commented May 29, 2020

@LukeMoll Would you mind creating a fix PR for this? I think you can either init the pin earlier or disable auto_write until everything is set.

@LukeMoll
Copy link
Author

Sure, I can have a go at that sometime next week :)

@tannewt
Copy link
Member

tannewt commented Jun 1, 2020

@LukeMoll Awesome! Thanks! Join our discord if you need any help (or just want to :-) ): https://adafru.it/discord

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Jun 3, 2020

This code is working properly for me on a Neo Trellis M4 with 5.4.0.beta and Neo pixel library out of today's library bundle:

import board
import neopixel

pixels = neopixel.NeoPixel(board.NEOPIXEL, 32, brightness=0.05)
pixels[0] = (0,0,100)

while True:
    pass

I am not experiencing any crash or other issues from this code.

What device and version of Circuit Python are you using when you see this error?

@LukeMoll
Copy link
Author

LukeMoll commented Jun 3, 2020

@FoamyGuy I mentioned at the bottom of my issue:

Tested with Adafruit CircuitPython 5.3.0 on 2020-04-29; stm32f411ce-blackpill with STM32F411CE, CircuitPython bundle 5.x 20200526.

I've got an ItsyBitsy M4 and Trinket M0 that I can try reproducing on later.

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Jun 3, 2020

Ah, whoops. I missed that on the first read. Thank you. The STM32 port is somewhat newer. I wonder if this is actually a symptom of an issue with that port rather than the neopixel library.

I will test on a nrf52840 based device as well so we will cover all of the current main processor types between us.

@Al105
Copy link

Al105 commented Jun 16, 2020

Hi, I found same error when auto_write=True - could you verify this as well?

@evaherrada
Copy link
Collaborator

evaherrada commented Jun 30, 2020

I actually ran into this testing someone's code from the forum today, the brightness wouldn't change when auto_write was enabled

@kevinjwalters
Copy link

kevinjwalters commented Jul 5, 2020

I get this on 5.3.0 using 20200703 libs too.

Another issue from the forum which is likely to be this too: Adafruit Forums: Help needed! REALLY basic!).

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