Skip to content

NeoPixels can't be disabled #75

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
dhalbert opened this issue Dec 10, 2021 · 3 comments · Fixed by #76
Closed

NeoPixels can't be disabled #75

dhalbert opened this issue Dec 10, 2021 · 3 comments · Fixed by #76

Comments

@dhalbert
Copy link
Contributor

@FoamyGuy and https://forums.adafruit.com/viewtopic.php?f=60&t=186080 report NeoPixel disabling no (no longer/) works.

Example:

magtag.peripherals.neopixel_disable = False
magtag.peripherals.neopixels.fill((100, 0, 0))
time.sleep(2)
print("disabling neopixels")
magtag.peripherals.neopixel_disable = True
magtag.peripherals.neopixels.fill((0, 0, 100))

Pixels still turn blue.

@FoamyGuy
Copy link
Contributor

A bit more troubleshooting reveals that when the library attempts to initialize the DigitalInOut for the NEOPIXEL_POWER pin the system believes that NEOPIXEL_POWER_INVERTED is already in use. The code from here:

try:
self._neopixel_disable = DigitalInOut(board.NEOPIXEL_POWER)
self._neopixel_disable.direction = Direction.OUTPUT
self._neopixel_disable.value = False
except ValueError:
self._neopixel_disable = None

Is raising and catching the error. I added raise e into that except block to verify and I can see the traceback:

Traceback (most recent call last):
  File "code.py", line 109, in <module>
  File "/lib/adafruit_magtag/magtag.py", line 102, in __init__
  File "/lib/adafruit_magtag/peripherals.py", line 54, in __init__
  File "/lib/adafruit_magtag/peripherals.py", line 49, in __init__
ValueError: NEOPIXEL_POWER_INVERTED in use

@FoamyGuy
Copy link
Contributor

I have also found that bypassing the library and directly handling the NEOPIXEL and NEOPIXEL_POWER pins does work as expected. With the following code we see the red light and the neopixels are turned off so we never see the blue light:

import time
import board
import neopixel
from digitalio import DigitalInOut, Direction

neopixel_disable = DigitalInOut(board.NEOPIXEL_POWER)
neopixel_disable.direction = Direction.OUTPUT
neopixel_disable.value = False

pixel_pin = board.NEOPIXEL

num_pixels = 4

ORDER = neopixel.GRB

pixels = neopixel.NeoPixel(
    pixel_pin, num_pixels, brightness=0.1, auto_write=False, pixel_order=ORDER
)

pixels.fill((255, 0, 0))
pixels.show()
time.sleep(1)
neopixel_disable.value = True


pixels.fill((0, 0, 255))
pixels.show()
time.sleep(1)

@FoamyGuy
Copy link
Contributor

I think I understand the root of this issue. the neopixel library is initializing NEOPIXEL_POWER itself now here:

https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/9ca3bf00c6a2dd1de2d315a3b952a381d720aa7d/neopixel.py#L129-L143

This means it's already in use by the time the MagTag library tries to initialize it.

With my other direct pin example above I initialized the power pin first so it was in use when neopixel tried to initialize it and it silently catches that error and moves on.

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

Successfully merging a pull request may close this issue.

2 participants