
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!
Cool? Ranking DIY Helpful post? Buy me a coffee.