Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Arduino Vixen Multiple 2812b LED strips

  1. #1
    Join Date
    Dec 2017
    Posts
    6
    Post Thanks / Like

    Default Arduino Vixen Multiple 2812b LED strips

    I am having a hard time controlling two strips of ws2812b LED's with my Arduino Mega. I cannot seem to figure out the correct coding for the Arduino to control multiple LED strips. I have been able to successfully control one strip, but cannot figure out how to manipulate the code to allow two strips.

    Could you help me add a second strip to this code below? The first strip is a 300 pixel strip, the 2nd is 240 pixels. Both ws218b rgb strips.

    I certainly am not married to this below sketch, if a different one is better please suggest it.

    Here is the code I am using which I found online:

    Code:
    /*
    
    Vixen Lights 3.x - Arduino Generic Serial for Addressable Pixels
    
    Using this code is pretty straight forward, simply hookup your one wire (WS2811 or WS2812) data line to pin 6 of your Arduino
    and upload this code.  Make sure you have properly installed the FastLED library from http://fastled.io Once you are done, simply
    power your Pixel strips from an external power supply.  Next configure a Generic Serial Controller inside of Vixen Lights 3.x and 
    add 3 x pixels for the number of channels.  Configure the Generic Serial Controller to use 115200, 8, none, and 1.  Then create
    your element and add "Multiple Items (1 x number of pixels).  Finally select your pixel elements and set them as RGB pixels before
    patching them to the controler outputs.  You should now be ready to begin testing.
    
    For a complete tutorial check out blog.huntgang.com
    
    Created   November 8th, 2014
    By        Richard Sloan - www.themindfactory.com
    And       David Hunt - blog.huntgang.com
    Version   1.4
    
    */
    
    
    // You must download and install the library from http://fastled.io/ 
    #include <FastLED.h>
    
    // Sets the maximum number of LEDs that this code will handle to avoid running out of memory
    #define NUM_LEDS 300
    
    // Sets the pin which is used to connect to the LED pixel strip
    #define DATA_PIN 8
    
    CRGB leds[NUM_LEDS];
    
    
    void setup() {
      // Define the speed of the serial port
      Serial.begin(115200);
    }
    
    void loop() {
      // Set some counter / temporary storage variables
      int cnt;
      unsigned int num_leds;
      unsigned int d1, d2, d3;
    
      // Begin an endless loop to receive and process serial data
      for(;;) {
        // Set a counter to 0.  This couter keeps track of the pixel colors received.
        cnt = 0;
        //Begin waiting for the header to be received on the serial bus
        //1st character
        while(!Serial.available());
          if(Serial.read() != '>') {
            continue;
            }
        //second character
        while(!Serial.available());
          if(Serial.read() != '>') {
            continue;
            }
        //get the first digit from the serial bus for the number of pixels to be used
        while(!Serial.available());
          d1 = Serial.read();
        //get the second digit from the serial bus for the number of pixels to be used
        while(!Serial.available());
          d2 = Serial.read();
        //get the third digit from the serial bus for the number of pixels to be used
        while(!Serial.available());
          d3 = Serial.read();
        //get the end of the header
        while(!Serial.available());
          if(Serial.read() != '<') {
            continue;
            }
        while(!Serial.available());
          if(Serial.read() != '<') {
            continue;
            }
        // calculate the number of pixels based on the characters provided in the header digits
        num_leds = (d1-'0')*100+(d2-'0')*10+(d3-'0');
        // ensure the number of pixels does not exceed the number allowed
        if(num_leds > NUM_LEDS) {
          continue;
          }
        // Let the FastLED library know how many pixels we will be addressing
        FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, num_leds);
        // Loop through each of the pixels and read the values for each color
        do {
          while(!Serial.available());
            leds[cnt].r = Serial.read();
          while(!Serial.available());
            leds[cnt].g = Serial.read();
          while(!Serial.available());
            leds[cnt++].b = Serial.read();
          } 
        while(--num_leds);
        // Tell the FastLED Library it is time to update the strip of pixels
        FastLED.show();
        // WOO HOO... We are all done and are ready to start over again!
        }
    }

  2. #2
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,471
    Post Thanks / Like

    Default Re: Arduino Vixen Multiple 2812b LED strips

    I haven't done this so I can't "walk" you through it, but here is the basics... https://github.com/FastLED/FastLED/w...oller-Examples
    You may still need to determine if a MEGA board can handle the workload so you could start with say two separate strings on two different ports then keep expanding each port until it becomes unreliable.

  3. #3
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,296
    Post Thanks / Like

    Default Re: Arduino Vixen Multiple 2812b LED strips

    It is a bad idea to do this in your processing loop. You should set up the fast led library in your setup section. Next, you have the max num LEDs set to 300. You will never get more than that until you change the constant. Based on this sketch you are going to put all 540 pixels on a single output (you only configured one instance of fastled).

    FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, num_leds);

    2017 adding 2 more candy canes, 7 Mid trees and a Halloween show. Removing most 2812 strips and replacing them with bullet pixel mounting strips. Replacing many buck converter waterproof bags with printed boxes.

  4. #4
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,471
    Post Thanks / Like

    Default Re: Arduino Vixen Multiple 2812b LED strips

    I think I have read that a MEGA board would be limited to 500 pixels. However, it doesn't prevent you from starting with a smaller number then scale it up slowly. If your Vixen sequence sends all 540 pixel in a serial run then you need to know which group goes to which strips.

    To answer your initial question, yes you can hook up multiple strips to multiple MEGA ports. If you start with a total of less than 500 pixel but split them into 3 output pins then use the following example. It is found in the fastLED library under Examples-> Multiple -> MultipleStripsInOneArray. You have to adjust the variables for the strips as the sketch uses 3 separate output pins and one array. So your Vixen data will need to be entered into this array. The sketch doesn't have the Vixen serial input portion of the code which would be your homework assignment if you want to use this sketch.

  5. #5
    Join Date
    Dec 2017
    Posts
    6
    Post Thanks / Like

    Default Re: Arduino Vixen Multiple 2812b LED strips

    Quote Originally Posted by LightUp View Post
    I think I have read that a MEGA board would be limited to 500 pixels. However, it doesn't prevent you from starting with a smaller number then scale it up slowly. If your Vixen sequence sends all 540 pixel in a serial run then you need to know which group goes to which strips.

    To answer your initial question, yes you can hook up multiple strips to multiple MEGA ports. If you start with a total of less than 500 pixel but split them into 3 output pins then use the following example. It is found in the fastLED library under Examples-> Multiple -> MultipleStripsInOneArray. You have to adjust the variables for the strips as the sketch uses 3 separate output pins and one array. So your Vixen data will need to be entered into this array. The sketch doesn't have the Vixen serial input portion of the code which would be your homework assignment if you want to use this sketch.
    Ok so I did some merging of my code and I think I have a good sketch. I also scaled my setup so I have 77 pixels on each strip, 6 strips with a total of 462 pixels. I cannot check it for a bit, though I am concerned I will not know what to trouble shoot if it does not work. Thus I was wondering if you could review this code and see if it makes sense?

    Also, MartinMueller2003, I am not sure which part of the code I should move to the Setup section and if I do move it how/if the rest of the code needs to be adjusted.

    Code:
    /*
    
    Vixen Lights 3.x - Arduino Generic Serial for Addressable Pixels
    
    Using this code is pretty straight forward, simply hookup your one wire (WS2811 or WS2812) data line to pin 6 of your Arduino
    and upload this code.  Make sure you have properly installed the FastLED library from http://fastled.io Once you are done, simply
    power your Pixel strips from an external power supply.  Next configure a Generic Serial Controller inside of Vixen Lights 3.x and 
    add 3 x pixels for the number of channels.  Configure the Generic Serial Controller to use 115200, 8, none, and 1.  Then create
    your element and add "Multiple Items (1 x number of pixels).  Finally select your pixel elements and set them as RGB pixels before
    patching them to the controler outputs.  You should now be ready to begin testing.
    
    For a complete tutorial check out blog.huntgang.com
    
    Created   November 8th, 2014
    By        Richard Sloan - www.themindfactory.com
    And       David Hunt - blog.huntgang.com
    Version   1.4
    
    */
    
    
    // You must download and install the library from http://fastled.io/ 
    #include <FastLED.h>
    
    // Sets the maximum number of LEDs that this code will handle to avoid running out of memory
    #define NUM_LEDS 462
    
    // Sets the pin which is used to connect to the LED pixel strip
    
    #define NUM_LEDS_PER_STRIP 77
    CRGB Strip1[NUM_LEDS_PER_STRIP];
    CRGB Strip2[NUM_LEDS_PER_STRIP];
    CRGB Strip3[NUM_LEDS_PER_STRIP];
    CRGB Strip4[NUM_LEDS_PER_STRIP];
    CRGB Strip5[NUM_LEDS_PER_STRIP];
    CRGB Strip6[NUM_LEDS_PER_STRIP];
    
    
    
    
    void setup() {
      // Define the speed of the serial port
      Serial.begin(115200);
      
    }
    
    void loop() {
      // Set some counter / temporary storage variables
      int cnt;
      unsigned int num_leds;
      unsigned int d1, d2, d3;
    
      // Begin an endless loop to receive and process serial data
      for(;;) {
        // Set a counter to 0.  This couter keeps track of the pixel colors received.
        cnt = 0;
        //Begin waiting for the header to be received on the serial bus
        //1st character
        while(!Serial.available());
          if(Serial.read() != '>') {
            continue;
            }
        //second character
        while(!Serial.available());
          if(Serial.read() != '>') {
            continue;
            }
        //get the first digit from the serial bus for the number of pixels to be used
        while(!Serial.available());
          d1 = Serial.read();
        //get the second digit from the serial bus for the number of pixels to be used
        while(!Serial.available());
          d2 = Serial.read();
        //get the third digit from the serial bus for the number of pixels to be used
        while(!Serial.available());
          d3 = Serial.read();
        //get the end of the header
        while(!Serial.available());
          if(Serial.read() != '<') {
            continue;
            }
        while(!Serial.available());
          if(Serial.read() != '<') {
            continue;
            }
        // calculate the number of pixels based on the characters provided in the header digits
        num_leds = (d1-'0')*100+(d2-'0')*10+(d3-'0');
        // ensure the number of pixels does not exceed the number allowed
        if(num_leds > NUM_LEDS) {
          continue;
          }
        // Let the FastLED library know how many pixels we will be addressing
          FastLED.addLeds<WS2812B, 7>(Strip1, NUM_LEDS_PER_STRIP);
          FastLED.addLeds<WS2812B, 8>(Strip2, NUM_LEDS_PER_STRIP);
          FastLED.addLeds<WS2812B, 9>(Strip3, NUM_LEDS_PER_STRIP);
          // tell FastLED there's 77 WS2812B leds on pin 10
          FastLED.addLeds<WS2812B, 10>(Strip4, NUM_LEDS_PER_STRIP);
          // tell FastLED there's 77 WS2812B leds on pin 11
          FastLED.addLeds<WS2812B, 11>(Strip5, NUM_LEDS_PER_STRIP);
          // tell FastLED there's 77 WS2812B leds on pin 12
          FastLED.addLeds<WS2812B, 12>(Strip6, NUM_LEDS_PER_STRIP);
        // Loop through each of the pixels and read the values for each color
        do {
          while(!Serial.available());
            Strip1[cnt].r = Serial.read();
            Strip2[cnt].r = Serial.read();
            Strip3[cnt].r = Serial.read();
            Strip4[cnt].r = Serial.read();
            Strip5[cnt].r = Serial.read();
            Strip6[cnt].r = Serial.read();
          while(!Serial.available());
            Strip1[cnt].g = Serial.read();
            Strip2[cnt].g = Serial.read();
            Strip3[cnt].g = Serial.read();
            Strip4[cnt].g = Serial.read();
            Strip5[cnt].g = Serial.read();
            Strip6[cnt].g = Serial.read();
          while(!Serial.available());
            Strip1[cnt++].b = Serial.read();
            Strip2[cnt++].b = Serial.read();
            Strip3[cnt++].b = Serial.read();
            Strip4[cnt++].b = Serial.read();
            Strip5[cnt++].b = Serial.read();
            Strip6[cnt++].b = Serial.read();
          } 
        while(--num_leds);
        // Tell the FastLED Library it is time to update the strip of pixels
        FastLED.show();
        // WOO HOO... We are all done and are ready to start over again!
        }
    }
    So my project is a 2D megatree. I have a wooden framed tree which I am wiring up with these strips. I am now realizing I have a few other things I am unsure of. As I said earlier, it is hard to trouble shoot to determine what I am doing wrong. I have a few more quesitons if you are willing to help:

    • In vixen, do I stick with one generic controller? I am under the assumption the controller is the Mega, which is still just one. Though this makes me wonder how does Vixen know there are 6 strips on separate mega outputs?
    • I have one 5V 15amp psu I intend to use for the strips. When I wire them up am I wiring them in series with each other or parallel? Parallel would be easiest as it would place the "top" of each wire at the top and allow me to use less wire to connect them all. My understanding of electricity indicates this should be fine, though my technological misunderstanding of LED strips may not agree with this.


    Thanks for the help, I really appreciate this. I am very excited to try to get this project finished, it is my first Vixen project and I am already quite addicted.

  6. #6
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,471
    Post Thanks / Like

    Default Re: Arduino Vixen Multiple 2812b LED strips

    I'm impressed that you are actually taking this challenge. I haven't done these things and am not a programmer. I have some knowledge of coding but don't do enough to be proficient. But, hey, I may learn something here. This project can also help others answering the question what can the MEGA board actually do reliably?

    So far I can't see a particular flaw, except I don't know what Vixen is sending. Your sketch appears to me to assume that all the red LEDs are stored first into an array, then the green LEDs and finally the blue LEDs. Not being a Vixen user, can you vouch that Vixen will send the data in the same order as your read them in your sketch?

    You stick with one Generic Serial if you have one Arduino controller. You can use more than one Arduino and then add another Generic Serial with its own COM port.

    With regards to wiring the strips, all strips must see 5V, thus this means that all 5V strips are in parallel, power wise. (If you were to wire two strips in series then a 10V supply would power the two strips, not what you are doing). EDIT: Not so. Forgot that the 5V is like a buss so a "series" connection is still 5V as Martin later indicated

    I haven't figured out how the Vixen MEGA tree maps to the physical pixels of your seven strings. It's something I want to know someday as I'm thing of making a MEGA tree 2018 season - if the LEDs are affordable. I dislike putting a $1000 into a tree - yeah, money tree
    Last edited by LightUp; 12-08-2017 at 10:03 AM.

  7. #7
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,471
    Post Thanks / Like

    Default Re: Arduino Vixen Multiple 2812b LED strips

    One other thing I got an error in compiling your sketch.

    C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\S tream.cpp:319:1: fatal error: opening dependency file core\Stream.cpp.d: Invalid argument

    }

    ^

    compilation terminated.

    exit status 1
    Error compiling for board Arduino/Genuino Mega or Mega 2560.
    Archiving built core (caching) in: C:\Users\user1\AppData\Local\Temp\arduino_cache_74 9335\core\core_arduino_avr_mega_cpu_atmega2560_563 8c217b04eda8279099c4937887265.a
    Sketch uses 11576 bytes (4%) of program storage space. Maximum is 253952 bytes.
    Global variables use 1841 bytes (22%) of dynamic memory, leaving 6351 bytes for local variables. Maximum is 8192 bytes.

  8. #8
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,471
    Post Thanks / Like

    Default Re: Arduino Vixen Multiple 2812b LED strips

    I compiled it again and the error is gone. So I don't what happened the first time.
    I don't have 7 pixels strings to test this sketch. I could scrounge 5 pixel strings and modify my sketch to suit.
    Last edited by LightUp; 12-07-2017 at 08:33 PM.

  9. #9
    Join Date
    Dec 2012
    Location
    Hudson MA
    Posts
    2,296
    Post Thanks / Like

    Default Re: Arduino Vixen Multiple 2812b LED strips

    If you put two 5V strips in series (which I do all the time) they are still 5V. Pixel strips run V+ and V= as a bus from end to end. You can inject the voltage from either end. As for the pixels, if you put two strips end to end, they look like one long strip. The controller does not see the strips, it see N pixels on an output. N is whatever you want it to be.

    Do you need to have multiple outputs on the MEGA? No. You can do this with a single output. Yes the MEGA will peak out at about 500 pixels due to the time it takes to generate the pixel data.

    2017 adding 2 more candy canes, 7 Mid trees and a Halloween show. Removing most 2812 strips and replacing them with bullet pixel mounting strips. Replacing many buck converter waterproof bags with printed boxes.

  10. #10
    Join Date
    Nov 2009
    Location
    Morrisburg, On, Canada
    Posts
    2,471
    Post Thanks / Like

    Default Re: Arduino Vixen Multiple 2812b LED strips

    Quote Originally Posted by MartinMueller2003 View Post
    If you put two 5V strips in series (which I do all the time) they are still 5V. Pixel strips run V+ and V= as a bus from end to end. You can inject the voltage from either end. As for the pixels, if you put two strips end to end, they look like one long strip. The controller does not see the strips, it see N pixels on an output. N is whatever you want it to be.

    Do you need to have multiple outputs on the MEGA? No. You can do this with a single output. Yes the MEGA will peak out at about 500 pixels due to the time it takes to generate the pixel data.
    Yes, you are right about two strings in "series" as end to end. I was thinking of it in "series" in a different sense when I responded, "stacking" two strings, I guess. I did 5 strings in series to make long string and injected power on the ends of each string.

    Regarding multiple outputs on the MEGA, I don't know what the advantage is either, but thought it might be less lag. So, unless one tries it or has the math to prove either case, he might as well try it and let us know how it works.

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •