logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2  52 10653 Cool? (+11)
📢 Listen (AI):
Test setup with LEDs in red, green, and blue on a workbench.
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
Packaging of LSC Smart Digital LED Strip
Printed circuit board module connected to several colored wires on a cork background.
Close-up of LED strip with integrated circuits and LEDs.
- Feit Electric "Smart Color Chasing Strip Light" w/BK7231N and SM16703
Feit Electric smart LED strip packaging. Feit Electric LED strip packaging with features.
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:
LED strip with multicolored LEDs connected to a breadboard on a wooden table.
Close-up of a breadboard with multicolored wires and electronic components connected. Close-up of an electronic module soldered to wires.


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:
OpenBeken user interface with file editor and LED control scripts.
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:
Test setup with LEDs in red, green, and blue on a workbench.


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:
Individually addressable LED strip glowing red on a table.



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:
LED strip with multiple colorful lights on a wooden surface.


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):
OpenBekenX screen displaying packets and system settings
Effects while playing around with dimmer:
LED strip with green-lit LEDs connected to a device. LED strip glowing green with connected wires. Green LED strip connected to a device on a wooden table. Illuminated LED strip on a wooden table with connected wires.

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:
Screenshot of OpenBekenX settings with Flag 4 option highlighted regarding RGBCW controller.
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:
Interface for managing LED lighting settings on the OpenBekenX platform.
Everything except CW controls will work, even the dimmer and color picker:
RGB color palette with selected green color.

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:
Screenshot of the xLights interface with RGB light settings.
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!

About Author
p.kaczmarek2
p.kaczmarek2 wrote 14416 posts with rating 12370 , helped 650 times. Been with us since 2014 year.

Comments

jkwim 18 Feb 2024 09:43

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]

p.kaczmarek2 18 Feb 2024 09:56

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]

jkwim 18 Feb 2024 10:05

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]

p.kaczmarek2 18 Feb 2024 10:19

Hm okay, so please try doing that modification and we will try to add WS2812B LEDs to your wall switch. [Read more]

jkwim 18 Feb 2024 10:51

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]

p.kaczmarek2 18 Feb 2024 11:31

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]

bjoerns 18 Feb 2024 15:48

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]

p.kaczmarek2 18 Feb 2024 16:01

@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]

bjoerns 18 Feb 2024 16:17

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]

jkwim 18 Feb 2024 16:33

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]

p.kaczmarek2 18 Feb 2024 18:41

@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]

jkwim 18 Feb 2024 18:47

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]

p.kaczmarek2 18 Feb 2024 19:10

Can you make a video of my script running on your strip? Do you have PowerSave on? [Read more]

jkwim 18 Feb 2024 19:41

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]

p.kaczmarek2 19 Feb 2024 01:33

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]

jkwim 19 Feb 2024 07:56

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]

p.kaczmarek2 19 Feb 2024 08:11

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]

jkwim 19 Feb 2024 08:44

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]

p.kaczmarek2 19 Feb 2024 08:53

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]

FAQ

TL;DR: OpenBeken can drive 60 LEDs on BK7231 using P16, and one tester confirmed support was "good to go now" after updating from build 451 to 469. This FAQ helps OpenBeken users script, debug, and integrate WS2812B, SM16703P, WS2811, DDP, and PixelAnim control on BK7231 devices. [#20968181]

Why it matters: This thread turns scattered LED-driver notes into a practical setup guide for getting addressable strips working reliably on OpenBeken hardware.

Option Control method Best use Key limitation
Manual script SM16703P_* commands in autoexec.bat Static colors, loops, dimmer logic You must write and maintain the script
DDP startDriver DDP Fast external effects from xLights or WLED Packet/buffer size limits long single-device runs
PixelAnim startDriver PixelAnim Built-in GUI animations Was still work-in-progress in May 2024
Classic LED UI hack Script maps $led_* variables to pixels Reuse OBK color picker and dimmer Single-color style control only

Key insight: OpenBeken’s WS2812B support depends more on the right pin, firmware build, and pixel protocol than on the LED brand name. Most reported “driver bugs” were actually old firmware, GRB/RGB order mismatches, or strips that group 3 LEDs per controller.

Quick Facts

  • OpenBeken’s addressable LED driver uses P16 only, because it relies on the BK7231 SPI DMA path for timing-accurate signaling rather than ordinary GPIO bit-banging. [#20966201]
  • A working basic setup shown in the thread initializes 3 LEDs and then writes pixel 0, 1, and 2 before calling SM16703P_Start. [#20966201]
  • For DDP, startDriver DDP 1024 sets a 1024-byte packet buffer, which the thread estimates at about 341 LEDs when using 3 bytes per LED. [#20968257]
  • One real-world test used a 16-LED OpenBeken DDP endpoint chained to a 180-LED WLED installation, creating a logical total of 196 LEDs with acceptable speed. [#20968181]
  • WS2811-style hardware may drive LEDs in groups of 3, so seeing three LEDs change together can be expected behavior, not a firmware fault. [#20970128]

How do I control a WS2812B or SM16703P LED strip in OpenBeken with a basic autoexec.bat script?

Use a short autoexec.bat that starts the driver, initializes the LED count, sets pixels, and then pushes the frame. 1. Add startDriver SM16703P. 2. Run SM16703P_Init 3 or your strip length. 3. Use SM16703P_SetPixel lines and finish with SM16703P_Start. The thread’s first example lights LED 0 green, LED 1 blue, and LED 2 red. The same command set works for WS2812B and SM16703P in OpenBeken. [#20966201]

What is the correct BK7231 pin for OpenBeken WS2812B control, and why does the driver only use P16 (MOSI)?

The correct pin is P16, which is the BK7231 MOSI pin. OpenBeken uses only that pin because the driver depends on SPI DMA to generate precise timings for WS2812B-like protocols. Ordinary GPIO timing was described as unreliable due to instruction-cache delays. That is why the thread repeatedly says addressable LEDs can only be connected on P16 for this driver path. [#20966201]

How can I break out or reroute P16 on CB2S or CB3S modules to use OpenBeken with addressable LEDs?

You can reroute P16 by exposing the hidden SPI pin on the module and wiring it out manually. For CB2S, the thread points to a dedicated P16 breakout method. For CB3S, a user reports that P14 can be modified for the purpose after opening the RF shield and soldering a wire. In both cases, you still need common ground, and external 5 V power can feed the LEDs while the module supplies data. [#20966561]

What is DDP in OpenBeken LED control, and how does it work with xLights or WLED?

DDP is the thread’s network-control method for sending pixel data from external software into OpenBeken. "DDP is a protocol that transports pixel data over UDP, letting another controller stream effects to the strip." In practice, you start both drivers, for example startDriver SM16703P, startDriver DDP, and SM16703P_Init 60. The thread shows it working with xLights and with WLED, including a 16-LED OBK target appended to a 180-LED WLED setup. [#20968181]

What does the SM16703P_SetRaw command do in OpenBeken, and what does the bUpdateAfterSet parameter mean?

SM16703P_SetRaw sends a raw byte stream to the LED buffer without converting values into color fields first. Its syntax is SM16703P_SetRaw bUpdateAfterSet firstByte hexData. The bUpdateAfterSet flag decides whether OpenBeken immediately transmits the prepared data to the LEDs. In plain terms, 1 makes it auto-run the equivalent of SM16703P_Start, while 0 lets you queue data first and start later. [#20968399]

Why do OpenBeken raw logs show translated SPI bytes like 0x88 and 0xEE instead of the original RGB values such as 0x00 and 0xFF?

The logs show SPI-translated transport bytes, not your original RGB payload. OpenBeken splits each source byte into 4 groups of 2 bits, then maps them through a lookup table: 0x88, 0x8E, 0xE8, 0xEE. That is why values like 0x00 and 0xFF appear in logs as repeated translated bytes instead of unchanged color bytes. The thread explains this as part of the SPI DMA timing method. [#20967350]

How do I set all pixels to one color or create an RGB repeating pattern on a full WS2812B strip in OpenBeken?

Use either a loop or the special all index. For one color, the simplest form is SM16703P_SetPixel all 0 255 0, which the thread uses for a full-strip green fill. For a repeating RGB pattern, initialize the strip length, step an index by 3, and write red, green, and blue to $CH6, $CH6+1, and $CH6+2 before SM16703P_Start. The example shown was written for 60 LEDs. [#20966201]

Why were LEDs lighting in the wrong sequence on a WS2812B strip until the firmware was updated from OpenBeken build 451 to 469?

The wrong sequence came from using an older firmware build, not from the LED protocol itself. A tester first saw LEDs 3 and 4 light together and color inconsistencies on build 451, then reported that upgrading to build 469 fixed both the sequence and color issues. The same user also confirmed the strip was GRB, which explained remaining color-order differences after the firmware update. [#20968181]

How do I handle GRB versus RGB color order when WS2812B colors look wrong in OpenBeken?

Swap the channel order in your SM16703P_SetPixel values to match the strip’s actual protocol. One tester found that a strip advertised as WS2812B was really GRB, so correct red required entering 0 0 255 in the RGB argument positions shown in the script comments. If white looks purple or colors seem shifted, treat color order as the first thing to check before blaming the driver. [#20968181]

What’s the difference between WS2812B, SM16703P, and WS2811 strips in OpenBeken, especially when one controller drives groups of 3 LEDs instead of individual pixels?

WS2812B and SM16703P can work with the same OpenBeken command set here, but WS2811 hardware may control LEDs in fixed groups instead of per-pixel. "WS2811 is a LED-driver category that controls external RGB sections, often with one controller chip driving 3 LEDs as one logical pixel." That is why one user saw 3 reds, 3 greens, and 3 blues in a test; the hardware grouped them by design, and the thread says this was expected. [#20970128]

How can I use the classic OpenBeken single-color LED web UI and dimmer to control an addressable strip through a script?

Enable the legacy LED-control flag, then map $led_* variables to every pixel in a loop. The thread’s example initializes 60 LEDs, repeatedly writes all pixels from $led_enableAll, $led_red, $led_green, $led_blue, and $led_dimmer, then calls SM16703P_Start every 1 second. This lets the normal OBK color picker and dimmer work, although the author notes the CW controls do not apply in that script path. [#20966201]

What is PixelAnim in OpenBeken, and how is it different from manual scripting or DDP-based LED effects?

PixelAnim is OpenBeken’s built-in pixel animation driver, intended to reduce or replace custom scripts for common effects. Manual scripting gives direct control through autoexec.bat, while DDP streams frames from external tools like xLights or WLED. PixelAnim sits between those approaches: local animations with a GUI, but less external dependency than DDP. A public test showed it working with startDriver SM16703P, SM16703P_Init 120, and startDriver PixelAnim, though some LEDs at the end still behaved oddly in that early build. [#21099114]

How do I integrate an OpenBeken RGBIC plus tunable white strip with Home Assistant so I can switch between RGB mode and cold/warm white mode?

Use the newer OpenBeken version rather than relying only on custom scripts. The thread shows a user first scripting separate RGB and white behavior for a strip with 2 PWM pins for white and one SM16703P data path, then later reporting that Home Assistant works great with the latest version. That means HA integration succeeded there, while the Web GUI mode toggle was still confusing. For this hardware, OpenBeken’s updated driver path was the practical answer. [#21083738]

What is the maximum practical LED count for OpenBeken DDP control, and how does the DDP buffer size like startDriver DDP 1024 affect strip length?

A 1024-byte DDP buffer supports about 341 LEDs when each pixel uses 3 bytes. The thread explicitly does the math as 1024/3=341 and treats that as plenty because WLED or other controllers can cascade effects across multiple OBK devices. That makes the practical ceiling depend on your packet size and topology, not only on one strip. Long decorative layouts can therefore be split across devices instead of forcing one huge DDP endpoint. [#20968297]

How does WS2812B support work on BK7231T compared with BK7231N in OpenBeken?

The thread does not describe a separate scripting model for BK7231T versus BK7231N, and the same OpenBeken LED work is presented as a shared driver feature. The opening post links both BK7231T and BK7231N under the same OBK project and explains WS2812B support through the common SM16703P-based driver flow. A later user explicitly asked whether this was available on BK7231T as well, which indicates the feature was being treated as part of the same platform family rather than a different API. [#20966201]
Generated by the language model.
%}