Page 1 of 1

Neopixel Frameloss

Posted: Thu Aug 18, 2022 9:39 pm
by Draculen
I'm noticing having a lot of PixelSubsets(Pixelmaps) going off at once and the adafruit animation library animation "frames per second" start to get extremely low, is this because:

1.my code organization is not optimal

2. copper defeciency is affecting how fast the leds can receive instructions because its an array of 103 pixels on 2 separate pins

3. The feather m4 express im using only has 120mhz to work with and too much code firing at once is going to cause "frame" loss from complexity of the code.

I wasnt sure if just making the code sleep for a milisecond would fix this issue or if I need to find a different way to do the same effect

code below

Code: Select all

import board
import neopixel
import time
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.color import PURPLE, AMBER, JADE, CYAN, TEAL
from adafruit_led_animation.group import AnimationGroup
from adafruit_led_animation import color
from adafruit_led_animation.animation.sparkle import Sparkle
from adafruit_led_animation import helper
from adafruit_led_animation.helper import PixelMap
from adafruit_led_animation.helper import PixelSubset

# Update to match the pin connected to your NeoPixels
pixel_pin = board.A4
pixel_pinL = board.A2
# Update to match the number of NeoPixels you have connected
pixel_num = 103
pixels = neopixel.NeoPixel(
    pixel_pin, pixel_num, brightness=0.5, auto_write=False, pixel_order=(1, 0, 2, 3)
)
pixil = neopixel.NeoPixel(
    pixel_pinL, pixel_num, brightness=0.5, auto_write=False, pixel_order=(1, 0, 2, 3)
)

leds_range0 = PixelMap(pixels, range(0, 16), individual_pixels=True)  # 0 to J-shape
leds_range1 = PixelMap(pixil, range(0, 17), individual_pixels=True)
crestR = PixelSubset(pixil, 17,29)
stem_R = PixelSubset(pixil, 29,52)
crestL = PixelSubset(pixels, 16,29)
stem_L = PixelSubset(pixels, 29,50)
rem_R = PixelSubset(pixil, 52,103)
rem_L = PixelSubset(pixels, 50, 103)

crestR2 = PixelSubset(pixil, 17,29)
stem_R2 = PixelSubset(pixil, 29,52)
crestL2 = PixelSubset(pixels, 16,29)
stem_L2 = PixelSubset(pixels, 29,50)
rem_R2 = PixelSubset(pixil, 52,103)
rem_L2 = PixelSubset(pixels, 50, 103)

sped = 0.04

#stem_grid_L = PixelMap(pixels, [
                           # 3(26, 27, 28, 29, 30, 31, 32) ,
                            #(33, 34, 35, 36, 37, 38, 39, 40 ,41),
                            #(42, 43, 44, 45, 46, 47, 48),
                            #(49, 50, 51, 52),
                            #(53, 54, 55, 56 ,57) ], individual_pixels=True)
                            #doesnt work, lights up entire strips at a time





animations = AnimationSequence(
    AnimationGroup(
       
        Comet(leds_range0, sped, tail_length=8, color=TEAL),
        Comet(leds_range1, sped, tail_length=8, color=TEAL),
        Comet(crestR, sped, tail_length=5, color=TEAL),
        Comet(stem_R, sped, tail_length=5, color=TEAL),
        Comet(crestL, sped, tail_length=5, color=TEAL),
       
        Comet(rem_R, sped, tail_length=15, color=TEAL),
        Comet(rem_L, sped, tail_length=15, color=TEAL),

    ),
    AnimationGroup(
        Comet(pixels, speed=0.08, color=CYAN),
        Comet(pixil, speed=0.08, color=CYAN),
        # sync=True,
        Sparkle(pixels, speed=0.08, color=TEAL, num_sparkles=10),
        Sparkle(pixil, speed=0.08, color=CYAN, num_sparkles=10),
    ),
    advance_interval=8.0,
    auto_clear=True,
    auto_reset=True,
)
while True:

    animations.animate()

Re: Neopixel Frameloss

Posted: Sat Aug 20, 2022 3:42 pm
by mikeysklar
The M4 is a beefy processor @ 120MHz and 103 pixels does not sound too crazy to drive.

If you run the code with half the number of pixels what changes?

What are you power the circuit with?

Can you post a video? A link from Youtube or Google drive (for example) of uploaded video would be fine.

Re: Neopixel Frameloss

Posted: Sun Aug 21, 2022 5:11 pm
by Draculen
Here is the animation video. At the 5 second mark is when all the pixelsubsets start animating
. https://drive.google.com/file/d/12wJUpT ... p=drivesdk

For context this is where the neopixels will be glued to
https://drive.google.com/file/d/12wtV_a ... p=drivesdk

So in total for both sides of the object it would be 400 neopixels. Reading the overview of the feather I believe it says it can animate up to 300 pixels if there is fading control (the comet animation may be included in that due to the tail fading out) or it can power 1000 neopixels if no brightness math is going on.

Any advice is sincerely appreciated

Re: Neopixel Frameloss

Posted: Tue Aug 23, 2022 9:20 am
by mikeysklar
I’m curious where the slow down is occurring.

If you add some print() statements to your code maybe we can narrow the line of code that is running at the 5 second point where you start seeing frameloss

Another trick would be to try and run with half the amount of LEDs. Not changing the wiring just the number of LEDs being initialized (eg. 103 —> 51) to see if it is a scaling issue.