MemoryError when importing library on ItsyBitsy ExpressM0

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
manzin
 
Posts: 2
Joined: Thu Jul 11, 2019 3:38 pm

MemoryError when importing library on ItsyBitsy ExpressM0

Post by manzin »

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!

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: MemoryError when importing library on ItsyBitsy ExpressM

Post by tannewt »

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

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: MemoryError when importing library on ItsyBitsy ExpressM

Post by tannewt »

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

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

Re: MemoryError when importing library on ItsyBitsy ExpressM

Post by manzin »

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?

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: MemoryError when importing library on ItsyBitsy ExpressM

Post by tannewt »

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.

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

Return to “Adafruit CircuitPython”