Adafruit_CircuitPython_NeoPixel icon indicating copy to clipboard operation
Adafruit_CircuitPython_NeoPixel copied to clipboard

Number of led in the strip really affect the speed.

Open gumush opened this issue 3 years ago • 3 comments

I use simple led move but it's very very slow in 1800leds ( just 30m 60led/meter )

def run(position ,color , speed , size  ):
    turnoff()
    for i in range(position):
        wait = 1/(speed*60)
        clean = int(60*size)
        print(f'Clean:{clean} Wait:{wait} I:{i}')
        pixels[i]=[255,0,0]
        if i-clean>0:
            pixels[i-clean]=[0,0,0]
        else:
            pixels[0]=[0,0,0]
        # time.sleep(0.001)
    turnoff()

Is there any way to speed this thing up ?

I guess in microcontrollers this would be better ?

gumush avatar Aug 04 '22 15:08 gumush

I came here hoping to find out about performance and any limits. Your post is concerning. The project I'm planning would have around 830 LEDs, and I was hoping to control it with a Pi Nano. If anyone could chime in with whether this is realistic or not it would be appreciated!

tremby avatar Jan 03 '23 12:01 tremby

since python is an interpreted language it is slow when updating large number of leds with a high refresh rate. It is best to stick with C++ libraries in arduino

pathnirvana avatar Feb 07 '23 06:02 pathnirvana

You can control when a write to the strip happens. Set auto_write to false in the constructor, and call show() when you want to send the state to the strip. I didn't do that below because I don't know how you want it to look.

Also, in the loop above, factor out the constant values. Create them once outside the loop. For instance:

RED = (255, 0, 0)
OFF = (0, 0, 0)
def run(position ,color , speed , size  ):
    turnoff()
    wait = 1/(speed*60)  # only needs to be computed once
    clean = int(60*size)  # only needs to be computed once
    for i in range(position):
        #print(f'Clean:{clean} Wait:{wait} I:{i}') # Don't print if you don't need to.
        pixels[i]=RED
        if i-clean>0:
            pixels[i-clean]=OFF
        else:
            pixels[0]=OFF
        # time.sleep(0.001)
    turnoff()

dhalbert avatar Feb 07 '23 14:02 dhalbert