Trinket M0 Memory Allocation Error

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
malhonnette
 
Posts: 2
Joined: Fri Jul 30, 2010 6:26 pm

Trinket M0 Memory Allocation Error

Post by malhonnette »

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

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.

User avatar
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: Trinket M0 Memory Allocation Error

Post by dastels »

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

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

Re: Trinket M0 Memory Allocation Error

Post by malhonnette »

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

User avatar
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: Trinket M0 Memory Allocation Error

Post by dastels »

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

Dave

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

Return to “Trinket ATTiny, Trinket M0”