Snippet - WS2811 Led Strip SPI driver

@ Nicolas3 - I know this thread is a little long in the tooth, but I was playing with your WS2811 code on a Panda II tonight, and ran into an odd problem.

I’m using the WS2811/2812 string that came with my Espruino kit:

Once I adjusted the code for the length of the LED string, I was able to get the string to light up, but it seems like the colors are off. Where the code says that it’s setting yellow, it comes out white (initially, at least).

If I step through the code that is supposed to rotate the Yellow LED around the strip, sometimes more than one LED is lit (for example one red and one blue), and sometimes just one, but the color seems to change each time.

Suggestions on troubleshooting? Something in the initialization, perhaps, or is it because this string is so much smaller than what your code is written for (25 LEDs vs. 240)?

UPDATE: A bit more on the symptom. Seems like sometimes the color (during the rotate sweep portion of program.cs) is yellow, but only when a single LED is lit. If more than one LED is lit, then it seems to always be the first LED, which is red, and another LED, which appears to have all three elements lit.

The Strip is in a Corner like my Controller.
Didn’t had the time to complete and i didn’t got it work.
I never got control of the LED’s… sry…

Hello all !
WS2811 http://www.adafruit.com/datasheets/WS2811.pdf and WS2812 http://www.adafruit.com/datasheets/WS2812.pdf does not have exactly the same data pattern to light them up ; plus, I think both strips have 2 different speed modes. You might have to adjust SPI speed for each strip. My code was just an example for the precise kind of strip I had at the time. I thing it was WS2812 high speed mode (800Khz) but you might have the 400Khz model (read the comments in the source, if you have this model, you might need to divide SPI speed accordingly by 2).

You might even have a little different protocol : try to find the datasheet of your strip and adapt the code accordingly…

Good luck !

@ Nicolas3 - Thanks, Nicolas!

I think you may be right with respect to the speed…I noticed that without some additional Thread.Sleep statements, the code seemed to execute way faster than I expected.

I’ll see if Grant Williams (the creator of Espruino) has posted a link to the datasheet for the string of LEDs he supplied with the kit, but I don’t recall seeing one. But I think that’s probably exactly what’s going on…subtle differences in the implementation.

I’ll follow up here if I’m able to get things working properly.

WS2811 Led Strip SPI driver text with mcu.who is geted?

WS2811 Led Strip SPI driver text with mcu:
In here I think anyone(www.ghielectronics.com’Members or web visitors) have see the WS2812 and WS2811.(if not please review(Rgb addressable led strip : LED COB module,Epistar high-power integrated LED,LED controllers, dimmers & amp, DMX! ) )
I am trying to get the timer to generate a (The diagram"WS2812 Protocol") squarewave using the output with 8bit MCU.but I’ve found nothing for WS2812b
However,I get a great kick out of a sequence manually like this…

#asm
MOV P1, #1
nop

nop
nop
nop
nop
nop
nop
nop
nop
nop
nop

nop
nop
nop
nop
nop
nop
nop
nop
nop
nop

nop
nop
nop
nop
nop
nop
nop
nop
nop
nop

nop
nop
nop
nop
nop
nop
nop
nop

MOV P1, #0

nop
nop
nop
nop
nop
nop
nop
nop
nop
nop

nop
nop
nop
nop
nop
nop
nop
nop
nop
nop

nop
nop
nop
nop
nop
nop
nop
nop
nop

ENDASM
it’s run on main_loop.any thing is ok!
may it is not good idea in single-threaded’program code.I shall be glad to get guy suggestions?

Guessing that after a year, @ Redtailed may not be checking this thread, but for the sake of others who may be looking to control WS281* strips from Netduino Plus 2, I found this post over at Adafruit that may be helpful:

I’m curious why there seems to be a difference in the ability to control these with GHI NETMF devices like Cerb-family boards and the Netduino. Is it just a matter of how the firmware implements SPI?

@ Bill Gates - It also worked for me for a WS2812B 30 leds strip on a Fez Cerbuino Bee. Just replaced the Number of Leds. Also take care that it’s hard coded in some place in the code, instead of using NumberOfLeds. I have used SPI1 with the signal generated on PIN11.

I’d love to see a blog post / write up on the logic behind the BuildTable function… and the rest of the code as well.

1 Like

It is possible to control a ws2812 LED strip (got mine from http://www.ledlightinghut.com/ws2812b-chip-built-in-digital-intelligent-led-strips.html ) via GPIO on a raspberry Pi using: https://learn.adafruit.com/neopixels-on-raspberry-pi/software

Would it be possible to control this same strip with the C1?

What is the C1?

@ Dave McLaughlin - Probably ODROID board

http://ameridroid.com/products/odroid-c1

hate to break the bad news to you - you will never run a strip of 60 LEDs from the power setup you have there.

You will need to supply a separate power supply of much higher current capability than the red power board will be able to provide over the 5v line on the extender module.

I use a 12v source capable of many amps directly connected to the LED strips, with GND of that source tied to the GND of the Gadgeteer board (you do have to be careful with managing earth isolated and non-earth isolated power supplies). The signal wire is then connected to the LED strip

If you want to prove your code is working, you could use a strip of say 3 or 4 LEDs only and that may not exceed your setup’s capability.

@ Brett - I’m not sure that’s @ NewBie_RPi’s problem.

While I agree with you that ideally, a separate power supply should be used, in my experience if there isn’t sufficient current, you would still get the LEDs closest to the breakout module lighting up normally, and the further you get down the line, the dimmer they get. Where you get in trouble is if you’re trying to run all 3 elements of every LED at high intensity.

When I was first starting with the WS2811 strips, I had a strip that was probably at least 60 LEDs wired up the same way, and it worked fine. But I probably powered it via the barrel jack, so I could use a power supply with a little more oomph than USB.

@ NewBie_RPi:

Hard to tell from the picture you posted, but first thing to check is that your connections (particularly on the breakout and on the LED strip) are solid, and not shorting. If you have a multimeter, check that the strip is getting 5v on the 5v line, and check and make sure you have good continuity between the ground and 5v pins and the matching terminals on the strip.

Looking at the schematic for the FEZ Spider (http://www.ghielectronics.com/downloads/schematic/FEZ_Spider_Mainboard_SCH.PDF), it looks like you may be trying to connect to the wrong SPI channel in your code. Socket 6 is SPI2 (second SPI channel), so you may want to try changing this:



to this:


```cs]WS2811Led MyWS2811Strip = new WS2811Led(NumberOfLeds, SPI.SPI_module.SPI2[/code


Also, if I recall correctly, there is at least one place in the driver code (the WS2811Led class) where the number of LEDs is hard-coded, and if you are using fewer than the hard-coded number, the code throws an out of range exception. Just something to keep an eye on, though it might have been fixed in a later version of the code.

Hope that helps!

@ NewBie_RPi - Adding an extra power supply to the red power board can help somewhat, but not enough to provide proper power to a full strip of RGB LEDs. But I’m still not convinced that’s your issue. To power the LEDs from your other power supply, you would need to wire that power supply to the LED strip, not to the Gadgeteer power module. Be VERY careful, however, if your strip is a 5v WS2811 strip…attempting to power this directly from a 12V source will likely destroy the strip, as these are quite sensitive to overvoltage.

I would recommend that you read through this article over at Adafruit:

paying particular attention to the “Best Practices” and “Powering NeoPixels” sections. (What they call “neopixels” are just WS2812 LEDs, which is the same thing as the WS2811, but with an integrated IC right on the LED package.) The programming section obviously isn’t relevant to NETMF and Gadgeteer, but that’s OK, as you need to get the hardware stuff connected right first before the software part will work.

Two more hardware things I’d check.
[ol]Make sure you’re wired to the correct end of the strip. Should be GND, DI (or DIn), and 5V (or whatever the source voltage of the strip is). If you’re seeing DO or DOut at the end you’re soldered to, you need to connect to the other end.
If you have verified that you’re connected to the correct end, you may want to skip down the strip a few LEDs and try re-connecting there, in case you have damaged one or more of the LEDs at the beginning of the strip. This can happen if a voltage spike occurs when you turn power on to the board/strip.[/ol]

Beyond the suggestions above, you’d need a protocol analyzer to verify that the SPI channel is generating a proper signal. I don’t have one, so I’ve mostly had to do trial and error with blinkies, but have usually been able to get them working by double and triple checking my electrical connections, and being sure that I was using the correct SPI channel. Those are the two things that have consistently tripped me up.

Good luck.

@ devhammer - hey it worked now!! Problem was in the soldering…

Thanks a lot ;D

My pleasure. Glad I could help. Congrats!

Anyone alive here? :slight_smile:

Wondering of driving WS2813 LED Strip with Fez Panda 2. Any comments? Is it fast enough to fulfill the task?

Fez Rhino, which this code was developed on, is USBizi144 based. Panda2 is USBizi100 based. Both have essentially the same firmware, just more pins on the USBizi144.
So yes it will do it

Hi guys! I was finally able to get back to my project and here’re some updates:

I was able to run WS2813 LED strip with this code with no issues and no RLP involved:

https://www.ghielectronics.com/community/codeshare/entry/977

The interesting part though is that I am using a power supply from my old CD Player which is 4.5V 0.5A: I am able to run all the 60 LEDs white color, which I suppose I shouldn’t be able, because each LED needs 18mA according to this datasheet (http://www.normandled.com/upload/201605/WS2813%20LED%20Datasheet.pdf)

Moreover, I’ve read somewhere that you better to reserve 60mA for each LED. The brightness of the LEDs are the same whatever count I run: 1 or all the 60.
Maybe there’s a brightness parameter anywhere else in the code which I abandoned and that one will let me solve the mystery. Any thoughts are appreciated.

However, I wanted to share a good news with you since there’re a lot of gossips in the internet which state that Fez Panda 2 and .Net Micro framework is not capable of driving Neo Pixels.

1 Like