Skip to content

MemoryError: memory allocation failed while using adafruit_circuitplayground.express #7

@JohannaE

Description

@JohannaE

Code is working without including adafruit_circuitplayground.express:

import board
import busio
import gc
import adafruit_ltr390

gc.collect()

i2c = busio.I2C(board.SCL, board.SDA)
ltr = adafruit_ltr390.LTR390(i2c)

print("UV:", ltr.uvs, "\t\tAmbient Light:", ltr.light)
print("UV Index:", ltr.uvi, "\t\tLux:", ltr.lux)
print("mem: ", gc.mem_free())

As you can see in the output only 4752 bytes are free after importing import adafruit_ltr390:

code.py output:
UV: 0 		Ambient Light: 224
UV Index: 0.0 		Lux: 179.2
mem:  4752

Code done running.

The code to measure free memory:

import gc

gc.collect()
print("mem: ", gc.mem_free())

Without including anything and measuring the free memory the circuit playground express has 19648 bytes free.

code.py output:
mem:  19648

Code done running.

The code which includes the adafruit_ltr390 toghter with the adafruit_circuitplayground.express libraries:

from time import sleep
import board
import busio
from adafruit_circuitplayground.express import cpx
import adafruit_ltr390

i2c = busio.I2C(board.SCL, board.SDA)
ltr = adafruit_ltr390.LTR390(i2c)

print("mem: ", gc.mem_free())

As a result of including both libraries the memory allocation failes:

code.py output:
Traceback (most recent call last):
  File "code.py", line 5, in <module>
  File "adafruit_ltr390.py", line 90, in <module>
MemoryError: memory allocation failed, allocating 184 bytes

The problem is that I cannot use any other funcionalty of my board in combination with the ltr390 uv sensor. I don`t unterstand why the ltr390 library causes the memory allocation failure.

My usecase involves visualizing the uv index value using the neo pixels and speakers. Because of the memory failure I can only use either the neo pixels + sound or the ltr390 uv sensor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions