# WS281x, SK6812 driver for the Omega2? [Solved]

• Re: [WS281x](SK6812 driver for the Omega2? [Solved])

Hi.
In the last days I played a bit with Python to get the WS281x working wirth Luz' module.
As I want to use HLS color schema (it allows to change the luminosity of the color by only one number), I programmed a function HLS to RGB color string:

``````def hls2rgb(h,l,s):
r, g, b = colorsys.hls_to_rgb(h,l,s)
shr = str(hex(int(r * 255.0)))
shg = str(hex(int(g * 255.0)))
shb = str(hex(int(b * 255.0)))
# print ([int(255.0*r), int(255.0*g), int(255.0*b)])
if len(shr) == 3:
shr = shr[0:2] + str(0) + shr[2]
if len(shg) == 3:
shg = shg[0:2] + str(0) + shg[2]
if len(shb) == 3:
shb = shb[0:2] + str(0) + shb[2]
col_led_string = shr[2:4].decode('hex') +shg[2:4].decode('hex') + shb[2:4].decode('hex')
``````

By using the following additional function, it allows using a 2 dimensional color matrix which is converted in the corresponding hex color string needed for the module. (It might be useful and easier to use a matrix to handle LED chains instead of a string of hexadigitals)

``````def hls2rgb_hexstring(hls_matrix):
dim1 = len(hls_matrix)
try:
dim2t = len(hls_matrix[0])
except:
dim2t = 0
if dim2t == 0:
dim2 = dim1
dim1 = 1
else:
dim2 = dim2t

if dim1 == 1:
h = hls_matrix[0]/360.0
l = hls_matrix[1]/100.0
s = hls_matrix[2]/100.0
col_led_string = hls2rgb(h,l,s)
return col_led_string
else:
col_led_string=""
for i in range(0,dim1):
h = hls_matrix[i][0]/360.0
l = hls_matrix[i][1]/100.0
s = hls_matrix[i][2]/100.0
col_led_string = col_led_string + hls2rgb(h,l,s)
return col_led_string
``````

To display a color gradient among several LED's (here 40) one has to run this code, which is using both function above:

``````color_start = 0
color_end = 359
nr_led = 40
lum = 2
sat = 100
colorMatrix = []
for i in range(color_start,color_end, abs(color_end-color_start)/nr_led):
colorMatrix.append([i,lum,sat])
#print [i,lum, sat]
print colorMatrix
with open('/dev/ledchain0','w') as export:
export.write(hls2rgb_hexstring(colorMatrix))
``````

• @luz does it work for the omega 2+ version with kernel 4.4.6?

• @Jakofff-Parker sorry for the 2 month delay, must have missed a notification here!

The p44-ledchain module does not depend on many kernel internals, the only subsystem it actually uses is hrtimer (high resolution timers), so it should run on any not really ancient kernel version.
On the other hand, it strictly limited to the MT7688 SoC, as it directly uses the PWM hardware without any abstraction. So it's good for Omega2/2S, LinkItSmart and possibly HLK7688.

• Hi, just a note regarding WS2811 I had a go with @luz's driver and I found out that even my led strip is branded as WS2811 (BTF-LIGHTING WS2811) it didn't work properly if I set the ledchain to type 0 (ledchain0=0,200,0), but it did work well using type 2 with both 3.3V and 5V signals.

BTW, many thanks @luz for the driver!

• @Marti-MG Thanks for this information!

I made a separate mode for the WS2811 because the timing specs from the datasheet I had were definitely not compatible with those I knew working with the WS2812/13. But I had no WS2811 to test back then.

I'm not too surprised that apparently the datasheet is not correct. I saw the same for WS2813 which had the `T0L` time specified 300nS, which is definitely not working with real WS2813 as I found out.

The modes are actually just timing numbers in a table in the driver, see line 157 in p44-ledchain.c. So it would be simple to nudge the WS2811 entry towards the WS2813 timing until it works.

For the time being, I just added a note to the p44-ledchain README.md to also try WS2813 mode in case WS2811 does not work.

• @LaurentN
export.write(hls2rgb_hexstring(colorMatrix))
TypeError: expected a string or other character buffer object

• Mr @luz! Can you write full tutorial? It's very difficult for beginners like me.
I want to control RGB LED strip WS2813.

• @luz does it work for the omega 2+ version with kernel 4.4.6?

When I did the opkg install, I got the error:

`````` * satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-p44-ledchain:
* 	kernel (= 4.14.81-1-5c1ea8a282d7395b1a2c86bf6b1669fc) *
``````

then, after:

`````` echo-en '\ xFF \ x00 \ x00 \ xFF \ x00 \ x00'> / dev / ledchain0
``````

Omega immediately hung, omega wifi dropping, yellow led turns off, and I did her a power reset.

Is this problem happening because the module is for another kernel?
I have Omega 2+ with 4.4.74 kernel

``````root@Omega-1D19:~# ls -l
-rw-r--r--    1 root     root           940 Jan 14  2019 greeting.py
-rw-rw-r--    1 1000     1000          6936 May 16  2019 kmod-p44-ledchain_4.14.81+2.0-7_mipsel_24kc.ipk
root@Omega-1D19:~# opkg install --force-depends kmod-p44-ledchain*
Installing kmod-p44-ledchain (4.14.81+2.0-7) to root...
Configuring kmod-p44-ledchain.
Collected errors:
* satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-p44-ledchain:
* 	kernel (= 4.14.81-1-5c1ea8a282d7395b1a2c86bf6b1669fc) *
root@Omega-1D19:~#
root@Omega-1D19:~# insmod /lib/modules/4.14.81/p44-ledchain.ko ledchain0=0,5,1
root@Omega-1D19:~# echo -en '\xFF\x00\x00\xFF\x00\x00' >/dev/ledchain0
packet_write_wait: Connection to 192.168.3.1 port 22: Broken pipe

``````

• @Nikolay-Vetrov Yes, it is!

• @Nikolay-Vetrov Yes, upgrade to the very latest available firmware: `oupgrade -l -f` and the ledchain kernel module will work right away.

That's actually what controls the notification LED on the Omega2 Pro

• ./scripts/feeds update -a

``````Create index file './feeds/telephony.index'
Updating feed 'plan44' from 'ssh://plan44@plan44.ch/home/plan44/sharedgit/plan44-public-feed.git;master' ...
Cloning into './feeds/plan44'...
The authenticity of host 'plan44.ch (5.148.180.31)' can't be established.
ECDSA key fingerprint is SHA256:2MTxsEAWz1HLbiYcN9wufc0e0pLraCZHbizwVXat0RE.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'plan44.ch,5.148.180.31' (ECDSA) to the list of known hosts.
Connection closed by 5.148.180.31 port 22
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
failed.
``````

• You seem to have the wrong repo URL for some reason. Where did it come from? Probably a mistake on my part publishing that URL somewhere (it's the url to my private staging repo for preparing stuff before I push to github - and obviously not publicly accessible). If you can point me to where you got that url from into your feeds.conf, I'll correct it, of course

Anyway, just use github URL: https://github.com/plan44/plan44-feed.git , in your feeds.conf (or feeds.conf.default in case you modified that one) then it will work.

src-git plan44 ssh://plan44@plan44.ch/home/plan44/sharedgit/plan44-public-feed.git;master

Here.
And what we can to write in feeds.conf.default?
This: `src-git plan44 https://github.com/plan44/plan44-feed.git`?

• If you install a new build system and run make, ledchain is included correctly in the Omega2Pro firmware. No other configuration is required.

• @crispyoz As @Lazar-Demin wrote above practically every recent firmware already has the ledchain kernel module.
Probably for most of us this is simpler to use (and change its configuration only) than build some custom firmware.

• @Alexandr-Didenko thanks for pointing me to that old post! Apparently that was a cut&paste error of mine back in 2017
I just edited it to have it point to the github repo now.

And what we can to write in feeds.conf.default?
This: `src-git plan44 https://github.com/plan44/plan44-feed.git`?

Yes, I think that would work (master branch should be the default) but to make sure I usually specify the branch explicitly:

`src-git plan44 https://github.com/plan44/plan44-feed.git;master`

Note that if `feeds.conf` does not exist already, first copy `feeds.conf.default` to `feeds.conf` and then append the new line.

(Side note: It's a widespread error to directly edit `feeds.conf.default`, altough one should not! `feeds.conf` is the mechanism intended to customize your build , like `.config` or the contents of `files/`. All of these are NOT in the openwrt git repo, and belong to you. `feeds.conf.default` however belongs to openwrt)

• @GyÃ¶rgy-Farkas Yes of course, but it seems @Alexandr-Didenko is building firmware otherwise why would he be using feeds.conf

• @luz Sorry to dragging you back in the past to remind you about this beautiful creation of yours!
I am using p44-ledchain on the Omage 2+ on the pwm0(Pin 18) with 5 ws2812 LEDs with my Custom PCB board.
I used the below command line to insert the driver(as mentioned in the readme);

``````insmod p44-ledchain ledchain0=0,5,1,10,5100
``````

Here the issue I am facing is that when i give command to update all 5 LEDs, it does not control all five LEDs. Sometimes it glows 3 and sometime 2.
Eg. To glow all 5 LEDs in Bright Blue color; I applied below command but it turned on only first 3 LEDs in Green, 1 bright blue, 1 dim blue.

``````echo -e "\x00\x00\xFF\x00\x00\xFF\x00\x00\xFF\x00\x00\xFF\x00\x00\xFF" > /dev/ledchain0
``````

I am pretty sure that the driver if okay in terms of controlling the LEDs.
Can you help me to make this work by pointing to the points I might have missed.

TAI

• @dixit What configuration parameters have you set for the ledchain module? I expect this is a timing issue, WS2812x seem to vary a bit depending on the manufacturer,

• @crispyoz What do you mean by `What configuration parameters have you set for the ledchain module?`
I am using p44-ledchain driver as it is and providing the above mentioned parameter while inserting the module.
Which means;
use ledchain0(pwm0) in non-inverted mode, for 5 leds in chain, ws2812 ledtype, 10 retries, 5100ns Maxretries value(default suggested for ws2812 on readme Github)
Let me know what other information would be helpful?

Looks like your connection to Community was lost, please wait while we try to reconnect.