0

DotStar Library Circuitpython Speed
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DotStar Library Circuitpython Speed

by vl_martin on Tue Apr 10, 2018 4:23 pm

hello,

I have a 3 m dotstar LED strip @60 pixels per meter, thus 180 pixels. I set it up using an trinket M0 and the DotStar circuit-python library with the following example:

Code: Select all | TOGGLE FULL SIZE
import time
import random
import board
import adafruit_dotstar as dotstar

# print('Hello world! I can count to 10:')
# for i in range(1,11):
#     print(i)

# With a Dotstar Digital LEB Strip with 30 lights
dots = dotstar.DotStar(board.SCK, board.MOSI, 180, brightness=1, auto_write=False)

######################### HELPERS ##############################

# a random color 0 -> 224
def random_color():
    return random.randrange(0, 7) * 32

# print ("hello")

######################### MAIN LOOP ##############################
n_dots = len(dots)
while True:
    #fill each dot with a random color
    # r = random_color()
    for dot in range(n_dots):
        dots[dot] = (random_color(), random_color(), random_color())
        # dots[dot] = (r, r, r)
        # dots[dot] = (0xff, 0xff, 0xff)

    # show all dots in strip
    dots.show()
    # time.sleep(.01)
    # print (".")


However, the demo runs extremely slow - meaning more than 100 ms per refresh of the whole strip (reducing the number of pixels helps)

I've tried re-building the dotstar library with a faster I2C speed but it doesn't seem to help. Seeing that in the videos the strips are running smoothly I am now doubting that this is possible with circuitpython? In theory it shouldn't make a difference whether or not I'm using python since the application logic isn't really slowing it down - it's the I2C - right ?

thanks :)

vl_martin
 
Posts: 7
Joined: Tue Apr 03, 2018 3:18 am

Re: DotStar Library Circuitpython Speed

by danhalbert on Fri Apr 13, 2018 12:00 am

The DotStar and NeoPixel libraries could be faster, and it's something we should look at.

You may be spending a lot of time in the `random()` function. Trying changing your random color function so it does something simpler than calling random() and see if it runs faster. I looked at randrange() and it can call the internal random number generator several times due to how its coded.

danhalbert
 
Posts: 642
Joined: Tue Aug 08, 2017 12:37 pm

Re: DotStar Library Circuitpython Speed

by vl_martin on Fri Apr 13, 2018 2:29 am

Yes, there's a lot of stuff happening in the libs - and not all of it is very performant. Meanwhile, I had too many issues with Micro/Circuit-Python on the small boards, I ended up translating everything back to Arduino Sketches. They're much faster - and I don't have any memory issues whatsoever. The M0 has 32K of RAM, which is a lot, but not enough for Circuitpython it seems ...

vl_martin
 
Posts: 7
Joined: Tue Apr 03, 2018 3:18 am

Re: DotStar Library Circuitpython Speed

by plutonic on Fri Apr 13, 2018 3:18 am

Yeah I noticed that too, even in the powerup demo for the gemma m0. The dotstar bit banging code is written in python and it's easy to read but it's just slow, doing all that in the interpreter in a not at all optimized way. There's no delay loops or anything you can chop out, it's just slow. I think the right fix is to rewrite the module in C and compile it into micropython. I might do that if someone else doesn't beat me to it.

plutonic
 
Posts: 39
Joined: Wed Jan 06, 2016 3:21 am

Please be positive and constructive with your questions and comments.