WS2812B first project

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

WS2812B first project

Post by Dutch »

im trying to figure out how I can make something with the WS2812B work for my project. I'm at chapter one though with these and FC7...
have worked with inputs outputs and calculations decisions and so on inFC6 but this is my first with Macro's in FC7. :?
recent got my FC7 licenses with some extra components packs so started playing..

So from some examples i got a project build up with the WS2812B rgb-led. i 'think' im in the right direction.. so initialize, set all zero, and than for example a few different colors into led 1,2,3 and 4. not sure if this spot for the number of leds is oke though and also i cannot find where to change or set the data output pin. i also think that is why my simulation is not showing anything.

later i want to have some running up like an arrow.

anybody who can look at my simple prob full of errors code and give me a push in the right direction?:|
thanks, Angelo.
Attachments
ws2812b 1eproj.fcfx
(12.91 KiB) Downloaded 381 times

User avatar
STibor
Posts: 263
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 116 times
Been thanked: 113 times
Contact:

Re: WS2812B first project

Post by STibor »

Hi,

WS2811 INIT
WS2811 SET LED COLOR starting LED position 0
WS2811 SET LED COLOR 1
WS2811 SET LED COLOR 2
WS2811 SET LED COLOR 3
WS2811 REFRESH

I uploaded the program.
The microcontroller is not set!

The PIC16F88 is slow.
Use a faster controller for PIC 8bit> 48MHz.

I tested with WS2811 and WS2812B LED hardware, up to 144 devices.
I tested 18F26K22 @ 64MHz working.
I tested with AVR controller Arduino NANO, UNO and Mega @ 16MHz, it works.
I tested STM32F051Discovery, it does not work, error message: undefined reference to `nop '
Follow the program bug fixes topic. http://www.matrixtsl.com/mmforums/viewt ... 760#p81283
Attachments
ws2812b 1eproj2.fcfx
(11.98 KiB) Downloaded 403 times

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: WS2812B first project

Post by Jay Dee »

Hi,
Before Ben and the guys wrote the component for these, I played around with NeoPixels which use these LEDs.
viewtopic.php?f=54&t=16757&p=78652&hili ... xel#p78652
You will need a pretty quick PIC as the timing required for the LED relys on very short pulses.

To be honest, I only got it working fast enough by using a few lines of basic assembly;
fastest way to turn output ON, single NOP command for the shortest possible delay and then turn output back OFF again.
If you have the capability, you may want to try turning an output on/off as fast as you can and measure the output period with scope.
I was using a ECIO40P which is a PIC18F4455 so the clock freq is running at about 48MHz which is pretty fast for a small PIC.
J.

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: WS2812B first project

Post by Dutch »

Thanks so much for that STibor! I immediately started reconfiguring begin the evening and and see the outcome in the system panel! just now took a break to thank you!
did not realize the 'refresh' was a kind of send command at the end but it clearify's a lot.

i just started with a 16F88 because i have that. maybe i need to get a faster one. a few leds should maybe work already to see some results. i have read about the tight timings and so also have gotten a arduino Nano 328P 16Mhz but never worked with those. i do have the avr license just to play with these too in stead of pics.

Jay Dee, i have a fluke scope to see the signal so indeed curious to see how it turns out with the macro's. i tried something with delays in FC to make the signal but the smallest timings are not enough to create the signal.
i have read some more about what signals to the WS leds are critical and what not so there are gains to made for sure.

first gat a simple set of leds working and then expand!

Angelo.

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: WS2812B first project

Post by Jay Dee »

Hi Angelo,
Yeah, for sure a std Flowcode on/off routine will not be fast enough but the some assembler code inserted into a FC program, worked great.
As for chip choice, I'm a big fan of the the little ECIO building blocks, the ECIO40P about £25 and the ECIO28P for around £12, great little 8 bit 18F chip, with USB bootloader so very simple to program straight from the flowcode and host PC. So simple to use, I drop them into lots of projects.

Also, if your just looking for a simple way to drive individual RGB LEDs on a long strip, look at the APA102C. They dont care about timing at all! Much easier than the WS2812B timing.
Previous post covers them as well.
viewtopic.php?f=54&t=16757&p=78652&hili ... xel#p78652
Have fun. J.

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: WS2812B first project

Post by Dutch »

well im programming a lot now and playing and teaching myself techniques along the way. I have a question though I cant solve

lets say I have a strip of 20 leds and I want just the center 10 to lite up a certain color. the all led is not an option in these. I can make 10 macro's for each individual led but how can I put that in just one macro?
I have seen I can make a variable for the led number. but what calculation results in 5, 6, 7....to 15 to put as variable in one macro? I created a loop where I add value of 1 a number of loop times but that aint a very nice solution.. any creative idea's?

Angelo.

EDIT: the obvious is sometimes too easy to think of. just tried 5&6&7.... 8)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: WS2812B first project

Post by Benj »

Hello,

I suggest you make a macro named SetXLEDs or something similar.

The macro parameters could have the colour (R, G, B) channels as well as the start offset (Offset) and number of LEDs to set (numLEDs).

Inside the macro we simply have a loop that runs for the number of leds times.

e.g.

While (numLEDs > 0)
{
CompMacro: SetColour (Offset, R, G, B)
Calculation: Offset = Offset + 1
Calculation: numLEDs = numLEDs - 1
}

At the end of the macro you could add a call to refresh, or you could add an extra parameter to the macro which would then allow you to choose to refresh automatically or not.

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: WS2812B first project

Post by Dutch »

That would be great and would certainly clean my flowchart up! I have rows of 30 leds in single macro's now.

The 5&6&7... etc didn't work although no syntax error.

Thanks ! Angelo.

Dutch
Posts: 102
Joined: Mon Aug 19, 2013 8:38 am
Location: Netherlands
Has thanked: 24 times
Been thanked: 5 times
Contact:

Re: WS2812B first project

Post by Dutch »

Benj, no push or so but do you have any idea when you might be able to make such an macro.?
im now 'playing' with effects in strips of over 100 leds and having pieces in one color somewhere inbetween after one change instead of an interupt is making a lot :shock: of macro's.
Hope you find time soon. thanks.

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: WS2812B first project

Post by Docara »

Hi Dutch,

Not wanting to put words in Ben's mouth but I think he was suggesting a way for you to try and not an offer to write a macro. I interpreted his last post as something for you to convert into a flowchart.

Whilst I have no experience of the specific kit you mention and don't fully 'get' what you are trying to do on a project level - I presume you are getting values from somewhere that need to be 'converted' into your desired LED output. MY initial thought would be

1) in the main routine set up 4 Global Variables which would hold offset and R,G,B values, then initialise whatever modules are needed if any, set up a While Wend continuous loop that reads the external data that sets the relevant Global Variable and repeats.
6
2) In a second Macro (NOT Component Macro) display the values from the Global Variables -(Offset, R,G,B) on the LEDs

3) set up a timer interrupt that fires the Macro in '2' above.


Please don't take this as THE way to do it I'm also still learning FC. Rereading this I noticed I didn't include a 'length' or similar variable to say the number of LEDs to be lit after the Offset, I would also deal with this I the 2nd Macro (subroutine using old money terms) :(


I find half the battle is to work out the proper 'logic' of the problem THEN use FC

Hope this is useful to you and I apologise if I'm completely wrong

Regards
Matt

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: WS2812B first project

Post by Benj »

Hi Dutch,

Yes the instructions were for you to allow you to create your own Flowcode macro. If I just do it for you then it's not helping you become a better programmer.

The instructions should be fairly straight forward, have a go and let us know how you're getting on.

I don't beleive this macro is something that should be built into the component, however I could be wrong.
The 5&6&7... etc didn't work although no syntax error.
5&6&7 won't cause a syntax error as the syntax is valid, however this is performing binary ANDs which will end up giving you the value as shown below.

5 = 0b00000101
6 = 0b00000110
7 = 0b00000111

Anding these values together gives you the value 4 as this is the only bit that is set for all ANDed values.

4 = 0b00000100

Post Reply