Shop OBEX P1 Docs P2 Docs Learn Events
Ws2811/2812 Programming Help Needed — Parallax Forums

Ws2811/2812 Programming Help Needed

NWCCTVNWCCTV Posts: 3,629
edited 2015-02-01 11:07 in General Discussion
Attention ALL programmers, be it Spin or C for SimpleIDE. I am in need of a bit of help here. Our beloved Seahawks are in Phoenix for the Super Bowl and since I am throwing a rather large party I would like to program my WS2811 and WS 2812B's with our team colors, blue and green. I can make them blink blue and green at various speeds but they all blink at the same time. What I would like to do is to have the blue chase the green, the green chase the blue and any other really cool patterns that can be made. I have tried modifying Jonny Mac's awesome driver but I am having no luck. I can not get it to only do blue and green. Any and all help is greatly appreciated.
«13

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-26 17:21
    Hi Andy,

    Do you have some sort of input device you want to use to change the patterns, colors or brightness?

    When I made my "Mood Enhancing LEDs" for my niece, I used a five button input device to select what's being displayed. The project used WS2801 LEDs but I don't think it would be hard to change it to use WS2812 LEDs.

    If anyone else wants to help Andy, I hope they speak up. It won't hurt my feelings if someone else jumps in to help.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-26 17:42
    I was just planning on connecting them to my Prop Demo Boards and possibly a QS, depending on how many I end up with. I just want the patterns to run continuously, one after another so no button is needed. I currently have 2 of the WS2811 strips from the Shack. I have 110 of the WS2812's but not sure how many strings I will make. Thanks for the help Duane, and anyone else that chimes in!!!
  • xanaduxanadu Posts: 3,347
    edited 2015-01-26 17:52
    How many LEDs are on the Shack strips?

    With JM's code, doing "strip.set" commands with pauses should be fine for what you describe.

    Edit: Or you can do "strip.fill"(start_led, end_led, $00_00_00)
    repeat
     strip.fill(1, 15, $00_00_FF) 'fills LEDs 1 through 15 blue
     strip.fill(16, 30, $00_FF_00) 'fills LEDs 16 through 30 green
     pause 5000
     strip.fill(1, 30, $00_00_00) 'turn strip off
     pause 1000
    
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-26 18:14
    There are 30 LED's on the Shack strips. Where would I place the code you posted? What I am wanting though is blue chasing green and green chasing blue and some other cool patterns.
  • xanaduxanadu Posts: 3,347
    edited 2015-01-26 18:17
    In place of this block of code in PUB Main of jm_ws2812_demo.spin:
      repeat 10
        color_chase(@Chakras, 6, 100)
        
      repeat
        repeat pos from 0 to 255
          strip.set_all(wheelx(pos, 128))                           ' 1/2 brightness
          pause(20)
    
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-01-26 19:04
    I have tried modifying Jonny Mac's awesome driver but I am having no luck.

    There should be no need to modify the driver -- I'm pretty sure it supports any feature you're wanting to use for your animation.

    I knocked up a quick demo that may help get you where you want to go.

    I can not get it to only do blue and green.

    Do you have my latest driver? (it's included in the archive). It allows you to swap color channels -- I had to set that to true to work with the Adafruit strip I have connected to my PAB.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-26 19:31
    JonnyMac, I thank you kindly. This is perfect!!! Go Seahawks!!!!!!!!!!!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-26 22:40
    I added an effect to Jon's code.

    The effect is similar to my "HypnoRings" code shown in post #1 of this thread. I limited the colors to blue and green. I think it still looks cool with just the two colors.

    I added a "BRIGHTNESS" constant to the program to make it easier to adjust the maximum brightness of the LEDs. Jon had the brightness set to 32 ($20). I increased the brightness to 128 ($80). The brightness may be set as high as 255 ($FF). One problem with lower brightness levels is the color depth is reduced, this isn't a problem for the effects Jon added but the effect I added looks better at higher color depths.

    As I mentioned, the effect is limited to the blue and green colors. If you wanted to see my effect with the full range of colors, change the value of MIN_COLOR_INDEX and the value of MAX_COLOR_INDEX from (line #196):
    MIN_COLOR_INDEX = 85 ' green
      MAX_COLOR_INDEX = 169 ' blue
    

    to
    MIN_COLOR_INDEX = 0 ' red
      MAX_COLOR_INDEX = 255 ' back to red
    

    I have my effect last 20 seconds which is much longer than the duration of either of Jon's effects. I wanted to make sure you could see the colors transition a bit before looping back to the first effect. You'll probably want to either reduce the duration of my effect or increase the duration of Jon's effects.

    Here's the line indicating how long to run my effect.
    extra_from_duane(20_000) ' max allowed time is 26_500 longer intervals will cause rollover
    


    The duration is in units of milliseconds. As the comment warns, durations longer than half the rollover period of the Propeller will cause a problem with the way the method is timed. If you want durations longer than 26.5 seconds, let me know and I can modify the code to use a different time keeping technique.

    The effect I added probably will not look good on short strands of LEDs. I think you'd need at least 6 LEDs to get a good effect. I used a strand of 10 LEDs while testing the code.

    I hope you try out the this modified version of Jon's demo.

    IMO, manipulating memory to produce patterns with LEDs is a great programming exercise. It's a lot of fun to see LEDs do what you tell them to do. It's even more fun when what you think you told them to do turns out to be what you really did tell them to do. Even when the code surprises you with what is displayed on the LEDs it's still fun.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-27 13:12
    Well. This works GREAT on the WS2812's. However, my Radio Shack WS2811 Strips do not work and are only flashing white.

    Edit: I know there is a thread about the RS strips but am having trouble locating it. They are the ones that were on clearance last year. May not be WS2811.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-01-27 13:29
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-27 13:33
    Yea, I got them working a while back ago. they are a bit different than the ones you linked to as they were clearance: http://forums.parallax.com/showthread.php/153352-Driver-for-Radio-Shack-tricolor-LED-Strip?highlight=radio+shack+rgb+led

    I know I had them working with one of the WS2811/2812 code blocks but I just need to figure out which one it was!!!
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-27 13:46
    OK, So for the RS Strips it is the file at http://forums.parallax.com/showthread.php/153352-Driver-for-Radio-Shack-tricolor-LED-Strip/page2?highlight=radio+shack+rgb+led#27

    That needs to somehow be modified for the same thing. Any takers????
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-27 14:25
    NWCCTV wrote: »
    Any takers????

    It compiles but I haven't tested it.

    I just remembered, I forgot to update the comments at the top of the file. It still has the comment stating I was modifying Jon's code. It's still a modified version of Jon's code so I suppose the comment is still true.

    Make sure and change the value of "STRIP_LEN" to match number of LEDs in your strip.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-27 17:36
    Well, It works somewhat but is Red and Green, not Green and Blue. I believe there was some issues with the Red and Blue being somehow swapped with this strip.

    In this thread: http://forums.parallax.com/showthread.php/153352-Driver-for-Radio-Shack-tricolor-LED-Strip/page2?highlight=radio+shack+rgb+led#37

    JonnyMac has added this:
    JonnyMac wrote: »
    This is brute force and brutally easy -- I use this in my WS2801 driver.
    ' swap red and blue channels
                            ' -- swaps only if xrb <> 0
    
    swaprb                  tjz     xrb, #shiftout                  ' skip if swap flag is 0    
    
                            mov     t2, t1                          ' copy original
                            and     t1, HX_00_FF_00                 ' isolate green     
                            and     t2, HX_FF_00_FF                 ' isolate red and blue
                            rol     t2, #16                         ' swap red and blue
                            or      t1, t2                          ' re-mix
    

    However, I have no clue as to where in the code it is suppose to be placed. Duane, your code works perfectly and I really like the various patterns but the Blue is Red,
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-27 20:11
    NWCCTV wrote: »
    Well, It works somewhat but is Red and Green, not Green and Blue. I believe there was some issues with the Red and Blue being somehow swapped with this strip.

    See if this version works.

    I didn't change the PASM section, I just changed how blue was defined. This is a very superficial hack.

    I hope my section of the code still works. I haven't tested this code on any LEDs. I'm not sure how the changed MIN and MAX color index will affect my color algorithm.

    Edit: I had attached the wrong file. See post # 9 for the correct file.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-27 22:01
    This one does nothing.

    Edit: Did you modify the correct one? The one that is used on the RS strips is the TM1803.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-27 22:46
    NWCCTV wrote: »
    This one does nothing.

    Edit: Did you modify the correct one? The one that is used on the RS strips is the TM1803.

    I modified the correct one but I uploaded the wrong one. I'll upload the correct one presently.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-28 09:42
    Perfect. I thank you very much. Hopefully I can get everything made up in time now!!!!
  • PublisonPublison Posts: 12,366
    edited 2015-01-28 10:44
    Duane Degn wrote: »
    I think this is the correct file.

    Nicely done Duane.

    Works great on my new PPDB.

    Now I know P15 works. I just need to check 32 more pins. :)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-28 12:01
    Publison wrote: »
    Nicely done Duane.

    Works great on my new PPDB.

    I'm glad you liked it. I'm very pleased with how well the color merging and blending look. I hope you try out the changes mentioned in post #9 to get the full rainbow effect. If you can arrange your LEDs in a loop of some sort it should look even better since the pixels should be symmetrical around the loop.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-28 18:34
    @Duane Degn and @JonnyMac. I just wanted to take a moment to tell you both thank you for the help (er, for doing) on this project. I was torn between using some of my WS2812B's to make a sign that says Seahawks or just doing a "12" for the 12th man. I have decided to go with the 12 due to time constraints. I have some real work to do Thursday and Friday and writing out Seahawks would take too much time. I will do up a quick video when complete if I remember. Thanks again.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-30 22:29
    I am currently working on my # 12 display. The LED's are lighting up great. Just one thought, is there a way to make the colors "chase"? I will end up with roughly 40 or so of the WS2812's and it would be kind of neat to have them chase from the first one to the last one in line. If it is too much then no problem, I can live with what I have. Thanks in advance.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-30 22:35
    NWCCTV wrote: »
    is there a way to make the colors "chase"? I will end up with roughly 40 or so of the WS2812's and it would be kind of neat to have them chase from the first one to the last one in line.

    Can you describe what you mean by 'chase" a bit more. Is only one LED on at a time?
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-30 22:41
    When LED 1 is green then goes blue it then goes to LED 2 green and so on. Does that make sense?
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-30 22:44
    Have to leave but will be back in about 45 minutes.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-01-30 23:07
    Something like this perhaps
    repeat pixel from 0 to last
      strip.set(pixel, $00_00_40)
      strip.set(pixel-1, $00_40_00)
      pause(100)
    

    This will run a single pixel from the start to some end point. If you repeat this with a descending end point you can fill the string with a chase action.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-01-30 23:17
    I haven't tested this, but give it a try.
    pub chaseSingle(color1, color2, ms1, ms2, count) | ch, maxIndex
    
      maxIndex := strip.num_pixels - 1
      repeat count
        repeat ch from 0 to maxIndex                  
          strip.set(ch, color1)
          pause(ms1)
          strip.set(ch, color2)
          pause(ms2)
          strip.set(ch, 0)
    

    Add this to the loop in the "main" method.
        chaseSingle(blue, green, 167, 167, 2)
        strip.set_all(0)
        pause(100)
    
    

    Make sure you try different values when calling the new method (and old).

    These LEDs are a fun way to experiment with Spin. Make sure you try to modify the code to make your own patterns.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-30 23:44
    It works!!!! Now to get back to soldering!! Thanks a bunch. If I get time I will play around with the settings. This is very cool and I want to figure out how to do it myself. One thing I want to try is while the LED's are chasing have the previous one lit up in the opposite color. However, this is great for now.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2015-01-31 00:48
    Can I use a 9 or 12 volt wall wart to power the LED's? After 10 it seems that a couple of the sequences where the colors are mixing together the do not work. I do not want to throw a larger wall wart on without verifying. I am currently using a 5V 650 ma wall wart and it can handle the first 10. I can probably dig up a higher amp 5V supply if need be.
Sign In or Register to comment.