0

MemoryError when importing library on ItsyBitsy ExpressM0
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MemoryError when importing library on ItsyBitsy ExpressM0

by manzin on Thu Jul 11, 2019 3:46 pm

I am simply trying to import both libraries for TCS334725 and SSD1306 (and their dependencies) in my code, but I get a MemoryError.
Both of them are saved in my lib folder in .mpy format.
I am running CircuiPython 4.0.2 and the most recent library bundle.

Is it possible that the board does not have enough memory to store just two libraries? It seems weird.
It looks like I am only using a few kbytes so far.
I have tried resetting the board and changing my import order.
If I import the libraries individually, it works.

Thank you!

manzin
 
Posts: 2
Joined: Thu Jul 11, 2019 3:38 pm

Re: MemoryError when importing library on ItsyBitsy ExpressM

by tannewt2 on Thu Jul 11, 2019 6:06 pm

What is the full stack trace on the error? Is it as the second library is imported?

tannewt2
 
Posts: 1211
Joined: Thu Oct 06, 2016 8:48 pm

Re: MemoryError when importing library on ItsyBitsy ExpressM

by tannewt2 on Thu Jul 11, 2019 6:14 pm

You can use `gc.mem_free()` to measure how big each library is. The SSD1306 definitely has room for optimization. For example, adding _ to the start of these constant names will cause them to be omited from the mpy and therefore memory: https://github.com/adafruit/Adafruit_Ci ... 306.py#L45

tannewt2
 
Posts: 1211
Joined: Thu Oct 06, 2016 8:48 pm

Re: MemoryError when importing library on ItsyBitsy ExpressM

by manzin on Fri Jul 12, 2019 11:15 am

Thank you for your reply!

I am loading these import statements and no further code:

import board
import busio
import time
from analogio import AnalogIn
import adafruit_tcs34725
import adafruit_ssd1306
import stepper

When I run gc.mem_free(), it always returns the same value no matter what: 20656. Am I using it incorrectly?

Import order seems to matter. If I import TCS, then SSD, then Stepper, I get a Memory Error referring to SSD:

Traceback (most recent call last):
File "main.py", line 11, in <module>
File "adafruit_ssd1306.py", line 38, in <module>
File "adafruit_framebuf.py", line 342, in <module>
MemoryError: memory allocation failed, allocating 136 bytes

If I import SSD, then TCS, then Stepper, I get a Memory Error referring to Stepper:

Traceback (most recent call last):
File "main.py", line 12, in <module>
MemoryError: memory allocation failed, allocating 232 bytes

My circuitpy folder seems to be mostly empty, but I am not sure if that matters, because this looks like a RAM issue.
I have tried modifying the constants in the SSD library as you suggested, but without success. Still, I am not sure if I am doing it correctly.

Do you have any further suggestion?

manzin
 
Posts: 2
Joined: Thu Jul 11, 2019 3:38 pm

Re: MemoryError when importing library on ItsyBitsy ExpressM

by tannewt2 on Mon Jul 15, 2019 2:56 am

What are you trying to use the display for? I have a new displayio driver that may save space. I'm hoping to get the code in this week.

tannewt2
 
Posts: 1211
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.