RGBW NeoPixel LED support

I have been experimenting with controlling some RGBW NeoPixels (Adafruit Jewel) that i have on-hand within lua scripts running under the current released version of Copter. (4.2.3) I have had some success in getting them to function and wanted to share my observations.

Disclaimer, I have not dug into the implementation of serialLED:set_RGB as of yet so what I am doing may be fraught with problems that I am not aware of.

Initially to get all seven of the RGBW LEDs on the jewel to light at all within the lua script I had to pass a value of 9 or greater to set_num_neopixel for each channel. Which got me thinking, perhaps each RGBW LED was occupying more than a single block within whatever data structure/memory mapping is being used under the hood (again I haven’t dug into the guts of set_RGB yet so this is pure speculation…). After some more experimentation, passing a value of 10 to set_num_neopixel allowed me to properly control the RGBW values of each pixel of the jewel individually.

It turns out that using two calls to serialLED:set_RGB with adjacent indices will let you set the RGBW values of a single LED on the jewel.

However there is some overlap between the indicies:

led_index 0 and 1 control RGBW led 0
led_index 1 and 2 control RGBW led 1
led_index 2 and 3 control RGBW led 2
led_index 4 and 5 control RGBW led 3

etc.

Going further, the individual r,g,b values passed to serialLED:set_RGB can be for two different LEDs:

for example, to set the RGBW values of LED 0 of the jewel:

serialLED:set_RGB( channel, 0, r, g, b)
serialLED:set_RGB( channel, 1, 0, w, 0)

whereas to set the RGBW values of LED 1 of the jewel:

seriaLED:set_RGB( channel, 1, g, 0, r )
serialLED:set_RGB( channel, 2, w, b, 0 )

values passed as 0 above are not applicable to the individual RGBW led, but are used by either the previous or next RGBW LED in the sequence…

Fortunately there does not appear to be any conflicts between the adjacent indices, ie. the values not needed to set LED 0 are used to set LED 1 when the indices overlap. This has proven true for all seven of the LEDs on the neopixel jewels that I have been using for testing.

Working out what the correct overlap between the LEDs proved to be a royal PITA (this is where i should have started to dig into the implementation of serialLED:set_RGB if I wasn’t so obsessed with trying to work out the pattern without looking under the hood), but fortunately the pattern repeats every 4th LED:

--RGBW 0:
serialLED:set_RGB( channel, 0, r, g, b )
serialLED:set_RGB( channel, 1, 0, w, 0 )

--RGBW 1:
serialLED:set_RGB( channel, 1, g, 0, r )
serialLED:set_RGB( channel, 2, w, b, 0 )

--RGBW 2:
serialLED:set_RGB( channel, 2, 0, 0, g )
serialLED:set_RGB( channel, 3, b, r, w )

--RGBW 3:
serialLED:set_RGB( channel, 4, r, g, b )
serialLED:set_RGB( channel, 5, 0, w, 0 )

--RGBW 4:
serialLED:set_RGB( channel, 5, g, 0, r )
serialLED:set_RGB( channel, 6, w, b, 0 )

--RGBW 5:
serialLED:set_RGB( channel, 6, 0, 0, g )
serialLED:set_RGB( channel, 7, b, r, w )

RGBW 6:
serialLED:set_RGB( channel, 8, r, g, b )
serialLED:set_RGB( channel, 9, 0, w, 0 )

Care should be taken when setting the RGBW values of adjacent LEDs, to ensure values are not being overwritten. For example to properly set LED 0 of the jewel to 128,128,128,128 and LED 1 of the jewel to 255,255,255,255 at the same time:

serialLED:set_RGB( channel, 0, 128, 128, 128)
serialLED:set_RGB( channel, 1, 255, 128, 255)
serialLED:set_RGB( channel, 2, 255, 255, 0 )

Or to set all seven of only the white LEDs of the jewel to full brightness:

serialLED:set_RGB( channel, 0, 0, 0, 0 )
serialLED:set_RGB( channel, 1, 0, 255, 0 )
serialLED:set_RGB( channel, 2, 255, 0, 0  )
serialLED:set_RGB( channel, 3, 0, 0, 255)
serialLED:set_RGB( channel, 4, 0, 0, 0 )
serialLED:set_RGB( channel, 5, 0, 255, 0 )
serialLED:set_RGB( channel, 6, 255, 0, 0 )
serialLED:set_RGB( channel, 7, 0, 0, 255)
serialLED:set_RGB( channel, 8, 0, 0, 0 )
serialLED:set_RGB( channel, 9, 0, 255, 0 )

This is as far as I have gotten with my experiments to-date, making simple RGBW LED animations on four NeoPixel Jewels, and controlling them via unpolished Lua scripts under Ardupilot Copter 4.2.3 running on my Matek H743-Wing v3…

Hopefully someone will find the above useful if they wanted to use some RGBW LEDs with Ardupilot and Lua scripts…

cheers,
g.

2 Likes