0

Should I create NeoPixel modules in CP to avoid mem allocati
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Should I create NeoPixel modules in CP to avoid mem allocati

by Monsterz on Sat Jul 13, 2019 4:33 pm

I'm not a pro user, so apologies upfront if this is a stupidity issue.
I'm trying to use a Trinket MO in CircuitPython to run ten or twenty different patterns on a single string of 19 Neopixels. The program accepts a single text string (from a Feather which runs the GUI on a touchscreen) and parses that to determine which effect, which two RGB colors, and what pace to run the Neopixel string at. It runs a few cycles of its selected pattern and then rechecks to see if there's a new string present. If there is, it accepts the new values and runs the new pattern. Otherwise it continues the old pattern and repeats the process. The patterns are simple subroutines based on the ones in the neopixel tutorial - nothing fancy, no big arrays or anything. This has worked fine up to 220 lines of code. But then I added in a new effect, very similar to a previous one, and now I get Memory Allocation error.
Does it seem likely that such a simple program would be too large? Unfortunately, I need to import random, board, digitalio, time, neopixel, and busio in the code.py. Are they eating up my space?
Running a properties on the Trinket I get 56K used space, 4K unused space when it's got the working 220 line program. Does this seem right? Is this too big of a job for the Trinket MO? It's physically a tight fit in my gizmo, so I'd like to stay small (and low power) if at all possible.
Could I have generated trash files on the Trinket that need to be cleaned out?
Some googling turned up that I could separate out the program into modules. Question - is that a good workaround for MemAlloc issues, and if so, is there a good starter tutorial on modules in CircuitPython?
What are the bare minimum files I need on the Trinket to do this? Can I delete the demo sketch and Win7 support etc? Will that help?
A more extreme fix - would the same functionality re-written as an Arduino sketch take up less memory than using the Trinket M0 in CircuitPython mode?

Monsterz
 
Posts: 4
Joined: Fri May 04, 2018 8:49 am

Re: Should I create NeoPixel modules in CP to avoid mem allo

by adafruit_support_mike on Mon Jul 15, 2019 12:10 am

Any interpreted code will consume about 10x as much memory and run about 10x slower than compiled code. That’s just a fact of life for interpreters.. all the stuff they do in the background consumes resources and runtime.

CircuitPython has some limits on the amount of RAM it allocates for garbage-collected variables, and that might be related to the allocation messages you’re getting. Try reducing the amount of information you hold in RAM while the code is running and see if that helps.

Adding libraries does gave an effect on RAM use, since the libraries have to allocate their own variables and data structures to work.

adafruit_support_mike
 
Posts: 57856
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.