Long delays while chasing

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
CML
 
Posts: 5
Joined: Sat May 11, 2013 12:58 am

Long delays while chasing

Post by CML »

I have bought 10 rolls of the addressable RGB LED strips and I want connect at least 5 rolls in a sequence and make the lights chase. I am using an Arduino Due to control the led strips. I have downloaded the Arduino library for the led strips and am using the chasing code from 'strandtest' to control my chase sequence. The problem I have is, that as the command 'strip.show()' which refreshes LED states, I think adds an additional delay depending on the number of LEDs there are in the circuit. This means I can't get my lights to chase at a given speed without having to skip LEDs which makes the chasing look very non-smooth. Is there some way to make the lights chase without the refresh command? I have tried to simply delete that line but the code doesn't work then. Here's the code for chasing that I'm using.

Code: Select all

void colorChase(uint32_t c, uint8_t wait) {
  int i;
  int incr = 3;  // how many LEDs to skip while chasing
int width = 10; //a segment of these many LEDs will move up and down the strip.
int j;
  // Start by turning all pixels off:
  for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);

  // Then display 'width' pixels at a time
  for(i=0; i<strip.numPixels(); i=i+incr) {
    for(j=i; j<i+width; j++) {
    strip.setPixelColor(j, c); // Set new pixels 'on'
    }
    strip.show();              // Refresh LED states
    for(j=i; j<i+width; j++) {
    strip.setPixelColor(j, 0); // Erase pixels, but don't refresh!
    }
    delay(wait); // this delay is not the only delay in the loop. I think the strip.shot() command also adds a substantial additional delay
  }
  for(i=strip.numPixels(); i>0; i=i-incr) { //chasing backwards
    for(j=i; j>i-width; j--) {
    strip.setPixelColor(j, c); // Set new pixels 'on'
    }
    strip.show();              // Refresh LED states
    for(j=i; j>i-width; j--) {
    strip.setPixelColor(j, 0); // Erase pixels, but don't refresh!
    }
    delay(wait);
  }
  

  strip.show(); // Refresh to turn off last pixel
}
Last edited by adafruit_support_bill on Wed Jun 26, 2013 6:07 am, edited 1 time in total.
Reason: Please use the 'code' button when submitting code

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Long delays while chasing

Post by adafruit_support_bill »

All the setPixelColor() functions are operating on a pixel array in memory. Nothing gets written out to the strip until you call strip.show(). The more pixels you have, the longer it takes to write it out.

CML
 
Posts: 5
Joined: Sat May 11, 2013 12:58 am

Re: Long delays while chasing

Post by CML »

So, is there a way to get around this problem? What if I have 640 LED hooked up in line? If i want the lights to move at say 3m/s with delays and everything set for 32 LEDs, it moves 10 times as slow (since there are 20 times more lights). But is there a way for the delay to not scale linearly, but sub-linearly, with number of lights added?

tldr
 
Posts: 466
Joined: Thu Aug 30, 2012 1:34 am

Re: Long delays while chasing

Post by tldr »

CML wrote: What if I have 640 LED hooked up in line?
i assume this means you're talking about 4 of the lpd8806 strips, (4 * 5 * 32 = 640, and 640 isn't divisible by 30 or 60 leds/m on the ws2811 strips).

i don't have a due, so i can't offer anything here with any degree of certainty, but i have had a certain amount of success with increasing the spi speed on mega328 based boards. i've been able to up the speed from the default of 2MHz to 8MHz which is as fast as the 328 can push out the data when run at 16MHz.

in the library the spi clock divider is set to 8, which would give a speed of 6MHz on the due, if the code is doing the right thing at all, since it's using a constant defined for the mega328.

what i would suggest is to try changing the spi speed after initializing the strip.

i would blindly try SPI.setClockDivider(3) in hopes of getting a 16MHz clock. when that fails i would have a look at the source code for SPI.setClockDivider and then hit the datasheet for the processor in the due.

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Long delays while chasing

Post by pburgess »

The problem most likely isn't in the strip.show() or the delay(), but that the processing time to fill the chase pattern varies with length.

Instead of using the delay() function, you could compare the value of millis() to a known time interval, something like this:

Code: Select all

long nextTime = 0;

void loop() {
  while(millis() < nextTime); // Wait for start of interval
  nextTime = millis() + 20; // Next interval in 20 ms (50 fps)
  strip.show(); // Display results of prior frame on interval mark
  // Process next frame of LED animation here -- time will vary
}

CML
 
Posts: 5
Joined: Sat May 11, 2013 12:58 am

Re: Long delays while chasing

Post by CML »

So, I switched from using digital pins to the hardware SPI pins and there doesn't seem to be any additional delay apart from what I specify using the delay() function. Thanks a ton, guys. Really appreciate your help.

CML
 
Posts: 5
Joined: Sat May 11, 2013 12:58 am

Re: Long delays while chasing

Post by CML »

I used the SPI port on the Due to get much faster writing speeds but if I use this with a long chain of lights, the signal gets corrupted so I have reverted to skipping lights to get my desired speed while using the digital pins. Does anyone know of ways around this? Either speeding up using digital pins or using the SPI pins but ensuring the signal doesn't get corrupted for long wire lengths.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”