Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Trinket M0 Memory Allocation Error
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trinket M0 Memory Allocation Error

by malhonnette on Thu Oct 14, 2021 7:59 pm

I am trying to get the Trinket M0 to work with the DPS310 pressure sensor and I am running into a memory allocation error with CircuitPython.
This is the code I am running. It is the example code from the Adafruit DPS310 page:
Code: Select all | TOGGLE FULL SIZE
import time
import board
import adafruit_dps310

i2c = board.I2C()
dps310 = adafruit_dps310.DPS310(i2c)

while True:
    print("Temperature = %.2f *C" % dps310.temperature)
    print("Pressure = %.2f hPa" % dps310.pressure)
    print("")
    time.sleep(1.0)

This is the error I am getting:
Traceback (most recent call last):
File "code.py", line 3, in <module>
File "adafruit_dps310.py", line 162, in <module>
File "adafruit_dps310.py", line 256, in DPS310
MemoryError: memory allocation failed, allocating 232 bytes

Running gc.mem_free() before the DPS310 import statement on the third line shows 18,224 bytes free.

malhonnette
 
Posts: 2
Joined: Fri Jul 30, 2010 6:26 pm

Re: Trinket M0 Memory Allocation Error

by dastels on Thu Oct 14, 2021 8:51 pm

Unfortunately that code is pretty much as minimal as it gets... there's nothing to trim, really, unless you want to do some surgery on the DPS310 library and strip out what you don't need, if even possible.

The SAMD21 on the Trinket has 32K of RAM which is huge compared to the older ATTiny85 Trinket's 512 bytes, yet still not a lot. Especially when you're using something as RAM hungry as CircuitPython. By way of comparison the QTPy RP2040 has 264K of RAM on a board about the same physical size as the Trinket.

I'm afraid you may be stuck with needing a more capable board/MCU.

Dave

dastels
 
Posts: 7915
Joined: Tue Oct 20, 2015 3:22 pm

Re: Trinket M0 Memory Allocation Error

by malhonnette on Sat Oct 16, 2021 3:26 pm

I was kind of worried that the Trinket just didn't have enough RAM. Thank you for the advice and the quick reply.

malhonnette
 
Posts: 2
Joined: Fri Jul 30, 2010 6:26 pm

Re: Trinket M0 Memory Allocation Error

by dastels on Sat Oct 16, 2021 4:57 pm

It's a great board for simple CircuitPython or quite involved C++/Arduino code.

Dave

dastels
 
Posts: 7915
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.


cron