adafruit / Adafruit_CircuitPython_NeoPixel

CircuitPython drivers for neopixels.
MIT License
302 stars 98 forks source link

Number of led in the strip really affect the speed. #132

Open gumush opened 2 years ago

gumush commented 2 years ago

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 ?

tremby commented 1 year ago

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!

pathnirvana commented 1 year ago

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

dhalbert commented 1 year ago

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()