0

CRICKIT and Neopixels
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CRICKIT and Neopixels

by geekguy on Tue Aug 20, 2019 7:13 am

Hi,

As my first foray into using CRICKIT (Raspberry Pi HAT), I am working with RGBW Neopixels. I am getting weird colors on my Neopixel RGBW rings. Does CRICKIT work correctly with RGBW Neopixels?

Is the CRICKIT onboard Neopixel RGB or RGBW? I believe it is just RGB.

I get the results I would expect (correct colors) on the onboard Neopixel, but not on the 12 pixel RGBW ring I have connected, or on my 16 pixel RGBW ring.

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: CRICKIT and Neopixels

by XRAD on Tue Aug 20, 2019 9:10 am

check your code. Slight difference for RGB and RGBW neopixels......

XRAD
 
Posts: 504
Joined: Sat Nov 19, 2016 3:28 pm

Re: CRICKIT and Neopixels

by geekguy on Tue Aug 20, 2019 10:07 am

XRAD wrote:check your code. Slight difference for RGB and RGBW neopixels......

I already figured that out. This is Circuitpython and CRICKIT I am using, and I need to know what the difference is.

Here is my current code:
Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/env python3
import time
import board
import busio
import neopixel

from adafruit_crickit import crickit
from adafruit_seesaw.neopixel import NeoPixel

#   Standard RGB colors
RED = (0x10, 0, 0)
YELLOW = (0x10, 0x10, 0)
GREEN = (0, 0x10, 0)
CYAN = (0, 0x10, 0x10)
BLUE = (0, 0, 0x10)
PURPLE = (0x10, 0, 0x10)
BLACK = (0, 0, 0)

#   Standard RGBW colors
RED4 = (127, 0, 0, 0)
YELLOW4 = (127, 127, 0, 0)
GREEN4 = (0, 127, 0, 0)
CYAN4 = (0, 127, 127, 0)
BLUE4 = (0, 0, 127, 0)
PURPLE4 = (127, 0, 127, 0)
BLACK4 = (0, 0, 0, 0)

ORDER = neopixel.RGBW

#   Initialize the onboard Neopixel
status = NeoPixel(crickit.seesaw, 27, 1, brightness = 0.1, auto_write = False)
status.fill(BLACK)
status.show()
time.sleep(1)

status.fill(BLUE)
status.show()
time.sleep(1)

#   Initialize the Neopixel ring
pixels = NeoPixel(crickit.seesaw, 20, 12, brightness = 0.1, auto_write = False, pixel_order = ORDER)
pixels.fill(BLACK)
pixels.show()
time.sleep(1)

pixels[0] = RED
pixels[1] = GREEN
pixels[2] = BLUE
pixels[len(pixels) - 1] = PURPLE
pixels.show()
time.sleep(1)

This is just a little test program I put together to isolate where the change is.

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: CRICKIT and Neopixels

by adafruit_support_carter on Tue Aug 20, 2019 5:44 pm

Try:
Code: Select all | TOGGLE FULL SIZE
ORDER = neopixel.GRBW

adafruit_support_carter
 
Posts: 12971
Joined: Tue Nov 29, 2016 2:45 pm

Re: CRICKIT and Neopixels

by geekguy on Tue Aug 20, 2019 7:05 pm

adafruit_support_carter wrote:Try:
Code: Select all | TOGGLE FULL SIZE
ORDER = neopixel.GRBW

I did. It does not give me anything different and I still get weird behavior on my RGBW Neopixels. Also, I am not able to use the (127, 0, 0, 0) form for colors.

When I do, I get this error:
Code: Select all | TOGGLE FULL SIZE
Traceback (most recent call last):
  File "./Onboard_Neopixel_Test.py", line 42, in <module>
    pixels.fill(BLACK4)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_seesaw/neopixel.py", line 134, in fill
    self[i] = color
  File "/usr/local/lib/python3.7/dist-packages/adafruit_seesaw/neopixel.py", line 96, in __setitem__
    r, g, b = color
ValueError: too many values to unpack (expected 3)

Script code is here:
Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/env python3
import time
import board
import neopixel

from adafruit_crickit import crickit
from adafruit_seesaw.neopixel import NeoPixel

#   Standard RGB colors
RED = (0x10, 0, 0)
YELLOW = (0x10, 0x10, 0)
GREEN = (0, 0x10, 0)
CYAN = (0, 0x10, 0x10)
BLUE = (0, 0, 0x10)
PURPLE = (0x10, 0, 0x10)
BLACK = (0, 0, 0)

#   Standard RGBW colors
RED4 = (127, 0, 0, 0)
YELLOW4 = (127, 127, 0, 0)
GREEN4 = (0, 127, 0, 0)
CYAN4 = (0, 127, 127, 0)
BLUE4 = (0, 0, 127, 0)
PURPLE4 = (127, 0, 127, 0)
BLACK4 = (0, 0, 0, 0)

ORDER = neopixel.GRBW

#   Initialize the onboard Neopixel
status = NeoPixel(crickit.seesaw, 27, 1, brightness = 0.1, auto_write = False)
status.fill(BLACK)
status.show()
time.sleep(1)

status.fill(BLUE)
status.show()
time.sleep(1)

#   Initialize the Neopixel ring
pixels = NeoPixel(crickit.seesaw, 20, 12, brightness = 0.1, auto_write = False, pixel_order = ORDER)
pixels.fill(BLACK)
pixels.show()
time.sleep(1)

pixels[0] = RED
pixels[1] = GREEN
pixels[2] = BLUE
pixels[len(pixels) - 1] = PURPLE
pixels.show()
time.sleep(1)

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: CRICKIT and Neopixels

by adafruit_support_carter on Tue Aug 20, 2019 9:31 pm

I think I see the issue. It's tangentially related to this:
https://github.com/adafruit/Adafruit_Ci ... /issues/32

I think there's a work around though. First, switch to initializing the NeoPixels attached to the Crickit using init_neopixel():
https://github.com/adafruit/Adafruit_Ci ... est.py#L13
And for RGBW NeoPixels, you'll need to also set bpp.

Here's a quick example you can try with your 12 pixel ring.
Code: Select all | TOGGLE FULL SIZE
import time
from adafruit_crickit import crickit
crickit.init_neopixel(12, bpp=4, pixel_order=(1, 0, 2, 3))
crickit.neopixel.fill(0xFF0000)
time.sleep(1)
crickit.neopixel.fill(0x00FF00)
time.sleep(1)
crickit.neopixel.fill(0x0000FF)

You should get red, green, then blue.

adafruit_support_carter
 
Posts: 12971
Joined: Tue Nov 29, 2016 2:45 pm

Re: CRICKIT and Neopixels

by geekguy on Wed Aug 21, 2019 12:09 pm

adafruit_support_carter wrote:Here's a quick example you can try with your 12 pixel ring.
Code: Select all | TOGGLE FULL SIZE
import time
from adafruit_crickit import crickit
crickit.init_neopixel(12, bpp=4, pixel_order=(1, 0, 2, 3))
crickit.neopixel.fill(0xFF0000)
time.sleep(1)
crickit.neopixel.fill(0x00FF00)
time.sleep(1)
crickit.neopixel.fill(0x0000FF)

You should get red, green, then blue.

It works! Thank you!

On question though: Why does "np.fill(RED) "immediately take effect without doing something like an "np.show()"? This is going to make some code not work right, because I depend on being able to set pixel color before actually displaying it. The WHITE channel is being ignored and is never set.

My updated demo:
Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/env python3
import time
import neopixel
from adafruit_crickit import crickit

ORDER = neopixel.GRBW

RED = (127, 0, 0, 0)
GREEN = (0, 127, 0, 0)
BLUE = (0, 0, 127, 0)
PURPLE = (127, 0, 127, 0)
YELLOW = (127, 127, 0, 0)

WHITE = (0, 0, 0, 127)
BLACK = (0, 0, 0, 0)

crickit.init_neopixel(12, bpp = 4, pixel_order = ORDER)

np = crickit.neopixel

np.fill(0)
time.sleep(1)
np.fill(RED)
time.sleep(1)
np.fill(GREEN)
time.sleep(1)
np.fill(BLUE)
time.sleep(1)
np.fill(WHITE)
time.sleep(1)

np.fill(BLACK)
time.sleep(1)

np[0], np[1], np[2] = RED, GREEN, BLUE

np[3], np[4], np[5] = RED, GREEN, BLUE

np[6], np[7], np[8] = RED, GREEN, BLUE

np[9], np[10], np[11] = RED, GREEN, BLUE
time.sleep(2)

np.fill(BLACK)
time.sleep(1)

length = len(np)
print("length(np) = {0}".format(length))

np[0] = BLUE
np[length - 1] = PURPLE
np[length - 2] = YELLOW
time.sleep(2)

np.fill(BLACK)
time.sleep(1)

np[0] = PURPLE
np[length - 1] = WHITE
np[length - 2] = WHITE
time.sleep(2)

np.fill(BLACK)
time.sleep(1)

np[0], np[1], np[2], np[11] = RED, GREEN, BLUE, WHITE
time.sleep(2)

np.fill(BLACK)
time.sleep(1)

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Re: CRICKIT and Neopixels

by adafruit_support_carter on Wed Aug 21, 2019 2:07 pm

There's an "auto_write" parameter that defaults to True:
https://github.com/adafruit/Adafruit_Ci ... it.py#L347
That calls show() for you anytime you change the pixel buffer data.
https://github.com/adafruit/Adafruit_Ci ... el.py#L174

You can disable it by adding that parameter when calling init_neopixel().

Or, you can turn it on/off anytime with:
Code: Select all | TOGGLE FULL SIZE
crickit.neopixel.auto_write = False  # or True to enable


If it's False, then you'd have to call show().

adafruit_support_carter
 
Posts: 12971
Joined: Tue Nov 29, 2016 2:45 pm

Re: CRICKIT and Neopixels

by geekguy on Wed Aug 21, 2019 3:43 pm

adafruit_support_carter wrote:There's an "auto_write" parameter that defaults to True:

You can disable it by adding that parameter when calling init_neopixel().

Or, you can turn it on/off anytime with:
Code: Select all | TOGGLE FULL SIZE
crickit.neopixel.auto_write = False  # or True to enable


If it's False, then you'd have to call show().

I had forgotten about that and how it works. Thanks!

8-Dale

geekguy
 
Posts: 241
Joined: Tue Sep 10, 2013 2:43 pm
Location: Beaverton, OR

Please be positive and constructive with your questions and comments.