neopixel speed (and IC question)

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
acanessa
 
Posts: 18
Joined: Fri Oct 24, 2014 2:45 pm

neopixel speed (and IC question)

Post by acanessa »

Hi! Im not sure if this is the correct forum for this, so sorry in advance!

I have a possible problem, and a question:

PROBLEM: I bought 3 meters of neopixel strip. now, the problem is that it seems to be slow, i mean, very slow, like a solid second / second and a half to turn on 180 pixels, one by one. Maybe my code is rubbish? I tried this code along to sort of benchmark it.
It's the only code running on the arduino.
strip.begin();
strip.show();
for (int px = 0;px<=180;px++){
strip.setPixelColor(px,strip.Color(255,0,0));
strip.show();
}

I suspect that the strip.show() is responsible for my problem, because if I run this code, all the leds turn on at the same time in an instant.

strip.begin();
strip.show();
for (int px = 0;px<=180;px++){
strip.setPixelColor(px,strip.Color(255,0,0));
}
strip.show();

I've read on the page regarding neopixels at your site that there is like a 50 uS requirement to turn on a neopixel? I have 180 of them, even if it's a bit more than 50uS, it takes too long.

is it my code? what am I doing wrong here?


Now the QUESTION:
I need an IC that:
- Has one input only. (analog ideally)
- Has three or more outputs.
- Operates like this: Give the input a signal (5v) to have the IC turn on the first output, then give again another signal to the input and have the first output off and the next one on. and so on.

Can you help me? Thank you!!!

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: neopixel speed (and IC question)

Post by adafruit_support_mike »

Calling strip.show() inside the loop is what's killing your speed.

The whole strip updates every time you call that command, so you're doing 180 updates of 180 pixels, which amounts to 32,400 pixels worth of data. That's around 780,000 bits, and the bit rate for the NeoPixel signal is around 800kHz.

WRT the device that cycles through inputs one at a time, that's usually done in hardware with a CD4017 counter: https://octopart.com/search?q=cd4017

Today, people usually reach for a microcontroller and program it to do the same thing. A small chip like the ATtiny85 used in the Trinket would be able to do it: https://www.adafruit.com/products/1501

User avatar
acanessa
 
Posts: 18
Joined: Fri Oct 24, 2014 2:45 pm

Re: neopixel speed (and IC question)

Post by acanessa »

Thank you for your reply!

I think I see what you mean; I set the pixels to a desired state (on / off...colour) and then srip.show() updated the entire 180 pixels. Is this correct?

But, let me ask you this:
Say I want to have a "red dot" travelling from the first pixel to the last one (180)....what I would do is have the 1st pixel on, then have the 2nd on and the 1st off. And so on. ( I have done this and it works. The result is a red dot travelling from the beginning till the end of the strip in about 1 to 1.5 seconds. )
Now, shouldn't I have to code something like this? (calling strip.show every time I make a change on the strip?)

for (int px = 0;px<=180;px++){
strip.setPixelColor(px,strip.Color(255,0,0));
strip.setPixelColor(px-1,strip.Color(0,0,0));
strip.show();
}


Thank you!!!

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: neopixel speed (and IC question)

Post by adafruit_support_mike »

You don't have to (and shouldn't) call strip.show() every time you change a single pixel. Set the values for all 180 pixels in the strip, then call strip.show() to make them all appear.

A moving-light loop would look like this:

Code: Select all

int pixelCount = strip.numPixels();

for ( int i=0 ; i < pixelCount ; i++ ) {
    for ( int j=0 ; j < pixelCount ; j++ ) {
        if ( j == i ) {
            strip.setPixelColor( j, strip.Color( 255, 0, 0 ));
        } else {
            strip.setPixelColor( j, strip.Color( 0, 0, 0 ));
        }
    }
    strip.show();
    delay( 100 );
}
The inner loop (where the counter 'j' iterates over the whole strip) sets the pixel values for a single frame of the animation. The outer loop (where the counter 'i' iterates over the whole strip) displays each frame after all the pixel colors have been set.

User avatar
acanessa
 
Posts: 18
Joined: Fri Oct 24, 2014 2:45 pm

Re: neopixel speed (and IC question)

Post by acanessa »

1_Thank you for your reply.
I tried your code and It still takes about 1 to 1.5 seconds for the dot to travel the 180 pixels. :/ And this is with no delay() instruction. I even tried a sketch only with the lines of code you've provided.
Is this the fastest the strip can do 180 strip.show()'s?

Is there a way to tweak the library to make strip.show() faster?

2_There is also an issue I'd like to report that is very weird;

If I upload neopixel strip code like the lines you provided in the Setup() part of the code (to be executed once), the upload process hangs. This does not happen if the code is in the loop() part.

When I comment the neopixel related code in the setup(), it works perfect. I've been using arduino every day for more than a year, using mostly (90%) adafruit's hardware (awesome btw!) and never came across this issue. I've reinstalled arduino software just in case, but still, same issue. The moment I remove the neopixel code from my sketch's setup(), no problem any more...



It's super weird.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: neopixel speed (and IC question)

Post by adafruit_support_mike »

Hmm.. you may be losing speed to the system clock.

Could you post the whole sketch you're using please?

User avatar
acanessa
 
Posts: 18
Joined: Fri Oct 24, 2014 2:45 pm

Re: neopixel speed (and IC question)

Post by acanessa »

I have attached a video. https://www.youtube.com/watch?v=baLPDcD0FB0

#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

#define PIN 9
#define NUMPIXELS 180
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin(); // This initializes the NeoPixel library.
}



void loop() {
for ( int i=0 ; i < NUMPIXELS ; i++ ) {
for ( int j=0 ; j < NUMPIXELS ; j++ ) {
if ( j == i ) {
strip.setPixelColor( j, strip.Color( 255, 0, 0 ));
} else {
strip.setPixelColor( j, strip.Color( 0, 0, 0 ));
}
}
strip.show();

}
}

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: neopixel speed (and IC question)

Post by adafruit_support_mike »

Thanks. What microcontroller are you using?

User avatar
acanessa
 
Posts: 18
Joined: Fri Oct 24, 2014 2:45 pm

Re: neopixel speed (and IC question)

Post by acanessa »

Arduino Mega 2560

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: neopixel speed (and IC question)

Post by adafruit_support_mike »

Okay, no trouble with a lower-voltage CPU running at less than 16MHz.

You're probably seeing the limits of having a 180-pixel strip. Each update sends 180*24==4320 bits of data along the strip, and at 800kHz that will take about 5.5ms.

User avatar
acanessa
 
Posts: 18
Joined: Fri Oct 24, 2014 2:45 pm

Re: neopixel speed (and IC question)

Post by acanessa »

I think so too...but wait, by "each update" are you referring to each call to strip.show() ? if that is what you are saying then each call to strip.show() takes 5.5ms so 5.5ms by 180 is 990ms and that's about the 1 second that I was talking about...right?

This would be the explanation of my problem, correct? I thought the pixels would be faster :/

Thank you! :)

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: neopixel speed (and IC question)

Post by adafruit_support_mike »

An update is a call to strip.show(), yes. It takes about 990ms to send data to a strip of 180 NeoPixels.

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

Return to “General Project help”