Updated WS2812 Driver
JonnyMac
Posts: 9,104
I've made a serious change to my WS2812 driver that I'm hoping my friends here will play with before I unleash in ObEx.
Changes:
-- driver no longer uses internal array; this allows the app to set the size of the pixel buffer without waste
-- pixel buffer, buffer size, and transmit pin can be changed on-the-fly
By removing the internal array the application can save memory. Using external arrays also facilitates some animation techniques without artifacts (the current array is transmitted before switching to the new one). And by allowing pin changing, the same array(s) can be sent to multiple strings of pixels (this should eliminate my one-shot driver which I was never very happy with).
Your comments and suggestions are appreciated.
09 OCT 2016 : Per a request, I created an integrated driver for WS2812 (RGB) and SK6812 (RGBW) pixels. In order to keep things as clean as possible RGB values when use WS2812 pixels must now be left justified (in the standard WS2812 driver they are right justified). The driver will support both pixel types in the same project; the use() method requires the bit count for the type of pixels in use for the specified buffer/pin.
Note: As of 09 OCT 16 I have only tested the integrated driver with WS2812b pixels.
Updated jm_rgbx_pixel.spin driver 13 OCT 2016 @ 2:55 PM (Pacific Time)
Redundant drivers removed.
Changes:
-- driver no longer uses internal array; this allows the app to set the size of the pixel buffer without waste
-- pixel buffer, buffer size, and transmit pin can be changed on-the-fly
By removing the internal array the application can save memory. Using external arrays also facilitates some animation techniques without artifacts (the current array is transmitted before switching to the new one). And by allowing pin changing, the same array(s) can be sent to multiple strings of pixels (this should eliminate my one-shot driver which I was never very happy with).
Your comments and suggestions are appreciated.
09 OCT 2016 : Per a request, I created an integrated driver for WS2812 (RGB) and SK6812 (RGBW) pixels. In order to keep things as clean as possible RGB values when use WS2812 pixels must now be left justified (in the standard WS2812 driver they are right justified). The driver will support both pixel types in the same project; the use() method requires the bit count for the type of pixels in use for the specified buffer/pin.
Note: As of 09 OCT 16 I have only tested the integrated driver with WS2812b pixels.
Updated jm_rgbx_pixel.spin driver 13 OCT 2016 @ 2:55 PM (Pacific Time)
Redundant drivers removed.
Comments
Like these.
https://www.adafruit.com/products/2842
They are very similar to the 2812b but with a few differences. I was able to modify one of your old drivers to make them work. I didn't know if your revamped "official" version would include support for them.
So far no luck with the SK6812RGBW driver. Not sure if it is the way I have it set up in the demo object. Still testing. I will let you know when I find something.
Updates move to original post (top of thread)
Results in :
Green Wipe
Red Wipe
Blue Wipe
White Wipe
Still testing!!!
and further down
Thanks for testing the driver.
I just ordered a reel from Amazon -- I'll have some SK6812s to work with on Monday.
Would it be worth considering keeping the "pub start" and "pub start_b" routine from your original ws2812 driver to set up timing and variables to run ws2812 strips and adding a "pub start_c" routine to setup sk6812RGBW strip timing and variables?
There would also need to be an additional variable to tell the driver to shift 24 bits for 2812's and 32bits for 6812RGBW's.
I think this would allow the driver to be used for any neopixel product.
Also, my code is written to be functional and to allow others to learn. Have you ever looked at an Arduino library written by Limore Fried? Holy Cow, Batman, following that stuff can be a nightmare at times. I have a different attitude: I want people to do more than use my libraries, I want them to learn from them and build other things.
Great advice/reminder on developing simple useful drivers and letting others learn and build on them for there own needs.
Good bits:
-- will support 24-bit and 32-bit pixels
-- can even support both types of SK6812 pixels in same project!
Caveats:
-- pixel values for 24-bit types (WS2812) must now be left-aligned
It's not working at the moment (with WS2812b pixels) and I have to build some PCBs this morning, so I will finish later. My SK6812s will be here tomorrow so I can do a full test. I had a free bit in my connection value so the way it's designed the driver will support 24-bit and 32-bit pixels and even allow you to switch between them in the same project. I don't know if I would do this, but someone might have a special circumstance that requires it.
I'm working on an under cabinet lighting project. For budget purposes I was only going to implement RGBW strips where good quality white task lighting was necessary and the less expensive RGB strips everywhere else but was not sure if I would be able to mix and match them at the time. I ended installing all RGBW just in case. It's great that this driver will offer that flexibility going forward.
The sk6812RGBW is the 32bit RGBW strips while the sk6812 is functionally the same as the ws2812B
Some companies are shipping the ws2812B and sk6812 interchangeably.
Okay. I made a very small update to the driver, changing the interface for SK6812 pixels (same change in sk6812x driver).
The timing is the same for the SK6812 RGB and RGBW strips, so adding the bit count into this method should take care of everything. The WS2812 and WS2812b pixels have slightly different timing, hence the separate methods in the drivers that support them.
Update at top.
I'm using a Quickstart board and a strip of 8 Neopixels with an external 5V power supply.
When the code loops back to the top and flips through the three colors, blue is missing - I see red, green and then black/off.
The last buffer assigned to the LEDs is pixels3 which held blue up at the top for the buffer switching demo. At the bottom of your demo loop the .clear() method is operating on pixels3 which means the blue array is being erased. If you move the buffer filling into the loop the problem will go away.
I will try and test your driver today.
Jim
There are really two drivers: an update to the WS2812 driver, and a consolidated driver that will support WS2812 and SK6812 types. The latter has 24- and 32-bit variants, so the storage is changed for all pixels; the new format is $RR_GG_BB_WW where WW (byte0) is the white channel for 32-bit pixels, and not used for 24-bit pixels.
At the top of the main loop the PASM code looks for a command which changes its connection settings; this is a packed long that contains the address of the buffer (low word), the # of pixels in the buffer minus one (10 bits of high word), the output pin (five bits), and the 24- or 32-bit type (bit31).
https://www.adafruit.com/products/2862
They use the WS2812, so I would say yes.