OpenBeken WS2812B driver (compatible with SM16703P, etc) - short scripting presentation

Here I will show you the basics of individually addressable LEDs control in OpenBeken. Currently OpenBeken supports WS2812B LEDs and many LEDs with similiar protocols, like, for example SM16703P. In this topic I will focus on the basics of the manual LED control, I will not cover advanced animations here. The advanced animations system will be added, hopefully, soon, and it will be covered by a separate tutorial.
For generic information about OBK, please see:
https://github.com/openshwprojects/OpenBK7231T_App
Which devices have individually addressable LEDs?
There are many devices like that on the market, here are some examples:
- LSC Smart Digital LED Strip (2x5m RGBCW): BK7231N, SM16703P



- Feit Electric "Smart Color Chasing Strip Light" w/BK7231N and SM16703


And much more.
How to connect LEDs?
LEDs can be only connected on P16, which is MOSI pin. This is because we're using SPI DMA driver to get precise timings.
See our datasheet topic to locate P16:
BK7231 datasheet, pinout, programming, specification, wiki (BK7231T, BK7231N)
If your module has no P16 routed out, like a CB2S, you can always route it out yourself:
How to access hardware SPI port on CB2S? P16 (MOSI) GPIO breakout method
How to create a script in OpenBeken?
Please refer to this tutorial:
My testing environment
I don't have any IoT device with individually adressable LEDs, so I just used a CB2S with routed out P16 pin (as in the guide which I mentioned earlier) with the WS2812B strip connected:



Sample - RGB test
Ok, so let's create a sample script. For now, we will just lit two LEDs, just to check if the strip is working. Here's how it looks like on my side:

Here's full script:
startDriver SM16703P
SM16703P_Init 3
SM16703P_SetPixel 0 0 255 0
SM16703P_SetPixel 1 0 0 255
SM16703P_SetPixel 2 255 0 0
SM16703P_Start
The script is using SM16703P commands, but the same works for WS2812B. It's just that we have first developed SM16703P driver and then discovered that timings are also matching classic WS diodes.
Result:

Sample - Full strip Single Color
For this example, we can set all the pixels to a single color. There are two ways to do it. First one is to use a loop:
startDriver SM16703P
// number of LEDs
setChannel 5 60
// init
SM16703P_Init $CH5
// iteration variable
setChannel 6 0
// loop for each LEd
again:
SM16703P_SetPixel $CH6 0 255 0
addChannel 6 1
if $CH6<$CH5 then goto again
// done
SM16703P_Start
Second way is much simpler - if you provide 'all' as pixel index, it will set all pixels:
SM16703P_SetPixel all 0 255 0
Result:

Sample - Full strip RGB
A simple loop can be also used to set RGB colors. First red, then green, then blue, but the order of colors can be different if your strip is, for example, GBR standard.
startDriver SM16703P
// number of LEDs
setChannel 5 60
// init
SM16703P_Init $CH5
// iteration variable
setChannel 6 0
// loop for each LEd
again:
SM16703P_SetPixel $CH6 255 0 0
SM16703P_SetPixel $CH6+1 0 255 0
SM16703P_SetPixel $CH6+2 0 0 255
addChannel 6 3
if $CH6<$CH5 then goto again
// done
SM16703P_Start
Result:

Sample - Basic Dimmer
startDriver SM16703P
setChannelType 1 Dimmer256
// number of LEDs
setChannel 5 60
// init
SM16703P_Init $CH5
// on channel 1 dimmer change, refresh
addEventHandler OnChannelChange 1 startScript autoexec.bat refresh
// refresh function
refresh:
// iteration variable
setChannel 6 0
// loop for each LEd
again:
SM16703P_SetPixel $CH6 $CH1 0 0
addChannel 6 1
if $CH6<$CH5 then goto again
// done
SM16703P_Start
OBK web panel (ignore the DDP for now):

Effects while playing around with dimmer:




Class LED controller (single color only)
Another interesting possibility is 'hacking' the OBK script to control LEDs with old OBK single-color LED interface. For that, you need to enable the following flag:

Then, add the following script:
startDriver SM16703P
SM16703P_Init 60
again:
SM16703P_SetPixel all $led_enableAll*$led_red*$led_dimmer/255 $led_enableAll*$led_green*$led_dimmer/255 $led_enableAll*$led_blue*$led_dimmer/255
SM16703P_Start
delay_s 1
goto again
This will make OBK panel able to control the LEDs:

Everything except CW controls will work, even the dimmer and color picker:

Raw access
It is also possible to send raw bytes stream via command. The bytes are sent directly, without converting to colors. This can be done via SM16703P_SetRaw command with the following syntax:
SM16703P_SetRaw bUpdateAfterSet firstByte hexData
Here is example usage:
SM16703P_SetRaw 1 0 FF000000FF000000FF
This will set first 3 LEDs to green, red and blue on WS2812B.
Control via Home Assistant/HTTP
Just like in Tasmota, all our commands can be executed via cmnd interface, so you can set colors directly from outside.
Xlights control
It is also possible to control LEDs via DDP protocol. Many applications like XLights can be used for that purpose:

Required setup on OBK side is minimal:
startDriver SM16703P
startDriver DDP
SM16703P_Init 60
Here are some sample effects made by DDP:
Summary
This is just the beginning of WS2812B LEDs adventure. For now, you can just script simple effects yourself or use DDP (with xLights, for example) for more advanced effects. The OBK-only animation system is not ready yet, but I am planning to add one soon.
Stay tuned and let me know how I can improve the system!
My current plan is to make also an automatic, user-friendly animations system with some animations that are built-in.
The new system will work without any scripts, but I will publish more information once it's ready!
Comments
This is a great news indeed! I have requirement to be able to add a couple of WS2812B LEDs in to a Smart Wall Switch to be used as a Status Indicator Panel. Here is what I have done with a ESP8285... [Read more]
It should be possible right now with the current scripting system. The only question would be does your light switches have P16 available ? Otherwise you'll have to do the P16 hack I described here: ... [Read more]
For CB3S P14 can be modified for the purpose as explained by https://www.elektroda.com/rtvforum/viewtopic.php?p=20790939#20790939 https://obrazki.elektroda.pl/2805148600_1708247142_thumb.jpg ... [Read more]
Hm okay, so please try doing that modification and we will try to add WS2812B LEDs to your wall switch. [Read more]
The CBU based LQ-Y06 can be used as a LED Controller as well: https://obrazki.elektroda.pl/9985756200_1708249120_thumb.jpg https://obrazki.elektroda.pl/3839918100_1708249154_thumb.jpg ... [Read more]
Sure, just route out the P16 and the ground. Then you can use external 5V power supply to power the LEDs. Connect all grounds together (don't forget, common ground is required), then P16 to the DIN of... [Read more]
Just tried it with the Battletron Lamp and it works. Colors are sometimes not really what you think (white is like a light purple) but it works stables, so thats a good start. [Read more]
@bjoerns how that Battletron Lamp is organized, how many LEDs? I would like to help you with creating a final config for that. I am also still planning to add advanced animations system to OpenBeken.... [Read more]
The Battletron lamp uses two WS2811c Controller. One is controlling the nine LED's around the base, the second one powers the six LED's on the top. You can only control these two groups indiviual not... [Read more]
I tried to repeat my test from last year with WS2812B strip and came up with this slightly modified script: startDriver SM16703P // Channel for number of LEDs setChannel 5 16 // init SM16703P_Init... [Read more]
@jkwim , I suspect that you are incorrect. The raw data is not the hex data you provided. Raw data is the data for the SPI, where we split each byte into 4 bytes for the SPI DMA transfer: static uint8_t... [Read more]
Ok. Now I understand. I tried a normal WS2812B strip and also a WS2812B Ring. Same observation of LED 0,1,2 (2 lighting up very briefly) and then 3 & 4 getting lit at the same time and then 5 ... ... [Read more]
Can you make a video of my script running on your strip? Do you have PowerSave on? [Read more]
Tried your script on both versions of LEDs. Same issue is there. Changed power supply also (I did the latest test plugging in to laptop USB port) just to eliminate one more variable. If there was... [Read more]
This is just a debug text, I will remove it in the next build. I think we need more tests. Or maybe you're running something in the background, like IR interrupt? [Read more]
I am really sorry for dragging this on. The issue was with having the wrong version of FW. I was expecting to download the latest version and picked the topmost item which was actually 451 on that... [Read more]
So everything is working and you just had older version of firmware? That's a very good news! By the way, if you want to drive a really long LED strip, you can change the size of DDP buffer in the following... [Read more]
1024/3=341 LEDs right. That would be plenty as in reality if DDP is used from another device like WLED, the cascading can be done on WLED on to another OBK device. Physically the LEDs can be scattered... [Read more]
The LEDs can certainly span among different devices so I guess we won't run into the buffer size problems anytime soon. Regarding the wall switch modification, do you have hot air? It will be needed... [Read more]