adafruit / Adafruit_CircuitPython_NeoPixel

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

Slow performance setting Neopixels #90

Closed whogben closed 4 years ago

whogben commented 4 years ago

I am following the neopixel tutorial on a raspberry pi 4 and getting unexpectedly slow performance.

Setting 60 neopixels takes approximately 0.2 seconds using the following code. Is there a trick to making it faster?

import board
import neopixel
import time
import random

pixels = neopixel.NeoPixel(board.D21, 60)

pixct = 60

while (True):
    t1 = time.time()
    for i in range(1,pixct):
        pixels[pixct - i] = pixels[(pixct - i)-1]
    t2 = time.time()-t1
    print(str(t2))
    pixels[0] = [random.randint(0,255),random.randint(0,255),random.randint(0,255)]

I am hoping to play cool sequences at 30fps or faster across the entire 60 neopixel strip - looking for a smooth effect - but right now, 5fps is the maximum. Many thanks in advance for your ideas / suggestions.

whogben commented 4 years ago

OK i found a workaround by turning off autowrite - if autowrite is on it's slow, with autowrite off it's quick.