Neopixel Ring coding speed.

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
alexb240303
 
Posts: 2
Joined: Thu Jun 13, 2019 1:59 am

Neopixel Ring coding speed.

Post by alexb240303 »

Alright, so I am currently working on Adafruit's Neopixel Gas Mask project, and this is the first time I've used anything python related. I have all the physical stuff set up and working, but the speed at which the pixels shift is far to slow for what i want, and i don't know how to fix it. I have tried lowering the delay (line 36) but it doesn't affect it at all. Does anyone know how I could fix this?
Heres my (Adafruit's) code->

Code: Select all

import time
 
import board
import neopixel
 
try:
    import urandom as random  # for v1.0 API support
except ImportError:
    import random
 
numpix = 24  # Number of NeoPixels
pixpin = board.D0  # Pin where NeoPixels are connected
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3)
 
mode = 0  # Current animation effect
offset = 0  # Position of spinner animation
color = [0, 0, 50]  # RGB color - blue
prevtime = time.monotonic()  # Time of last animation mode switch
 
while True:  # Loop forever...
 
    
    if mode == 0:  # Spinny wheels
        # A little trick here: pixels are processed in groups of 8
        # (with 2 of 8 on at a time), NeoPixel rings are 24 pixels
        # (8*3) and 16 pixels (8*2), so we can issue the same data
        # to both rings and it appears correct and contiguous
        # (also, the pixel order is different between the two ring
        # types, so we get the reversed motion on #2 for free).
        for i in range(numpix):  # For each LED...
            if ((offset + i) & 7) < 2:  # 2 pixels out of 8...
                strip[i] = color  # are set to current color
            else:
                strip[i] = [0, 0, 0]  # other pixels are off
        strip.write()  # Refresh LED states
        time.sleep(0.000)  # 1 millisecond delay
        offset += 1  # Shift animation by 1 pixel on next frame
        if offset >= 8:
            offset = 0
    elif mode == 1:  # Spinny wheels
        # A little trick here: pixels are processed in groups of 8
        # (with 2 of 8 on at a time), NeoPixel rings are 24 pixels
        # (8*3) and 16 pixels (8*2), so we can issue the same data
        # to both rings and it appears correct and contiguous
        # (also, the pixel order is different between the two ring
        # types, so we get the reversed motion on #2 for free).
        for i in range(numpix):  # For each LED...
            if ((offset + i) & 7) < 2:  # 2 pixels out of 8...
                strip[i] = color  # are set to current color
            else:
                strip[i] = [0, 0, 0]  # other pixels are off
        strip.write()  # Refresh LED states
        time.sleep(0.04)  # 40 millisecond delay
        offset += 1  # Shift animation by 1 pixel on next frame
        if offset >= 8:
            offset = 0
    # Additional animation modes could be added here!
 
    t = time.monotonic()  # Current time in seconds
    if (t - prevtime) >= 80000:  # Every 8 seconds...
        mode += 1  # Advance to next mode
        if mode > 1:  # End of modes?
            mode = 0  # Start over from beginning
        strip.fill([0, 0, 0])  # Turn off all pixels
        prevtime = t  # Record time of last mode change 

User avatar
siddacious
 
Posts: 407
Joined: Fri Apr 21, 2017 3:09 pm

Re: Neopixel Ring coding speed.

Post by siddacious »

How fast are the pixels shifting? What do you like it to do?

CircuitPython has many benefits like being easily accessible and making it easy and fast to develop the code, but the speed that the code runs at is not it's core strength.

The CircuitPython 4.1.0 beta has some notable speed improvements that might help.

It is available here if you're using a gemma m0 : https://circuitpython.org/board/gemma_m0/ or on the download page for you board here:https://circuitpython.org/downloads

Instructions for updating your version of CircuitPython are here: https://learn.adafruit.com/welcome-to-c ... cuitpython

Please be aware that this is BETA software and may still have some bugs. If 4.1.0 still isn't fast enough, you may wish to use the Arduino instructions from the guide: https://learn.adafruit.com/3d-printed-e ... duino-code.

I hope this helps!

User avatar
alexb240303
 
Posts: 2
Joined: Thu Jun 13, 2019 1:59 am

Re: Neopixel Ring coding speed.

Post by alexb240303 »

It does a lot! thanks!

User avatar
DJERO77
 
Posts: 2
Joined: Fri Jun 21, 2019 5:38 pm

Re: Neopixel Ring coding speed.

Post by DJERO77 »

Hello,

What was the solution for you?
I upgrade the GEMMA M0 card with the latest version of CircuitPython: CircuitPython 4.1.0-beta.0 but the animation (Mode 1) is still very slow and does not correspond at all to what we can see on the site.

Have you been with Arduino?

Thank you for your feedback.

User avatar
danhalbert
 
Posts: 4651
Joined: Tue Aug 08, 2017 12:37 pm

Re: Neopixel Ring coding speed.

Post by danhalbert »

@DJER077 try

Code: Select all

strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3, auto_write=False)
and see if it speeds things up for you.

User avatar
DJERO77
 
Posts: 2
Joined: Fri Jun 21, 2019 5:38 pm

Re: Neopixel Ring coding speed.

Post by DJERO77 »

Hello,

wooo, what a quick response :)
It works perfectly, thank you very much!

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

Return to “Adafruit CircuitPython”