8000 MemoryError goes away when program is changed slightly · Issue #10359 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

MemoryError goes away when program is changed slightly #10359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dhalbert opened this issue May 18, 2025 · 1 comment
Closed

MemoryError goes away when program is changed slightly #10359

dhalbert opened this issue May 18, 2025 · 1 comment
Assignees
Labels
Milestone

Comments

@dhalbert
Copy link
Collaborator

From https://forums.adafruit.com/viewtopic.php?t=218315

A program mentioned in the thread above happens to trigger a MemoryError in recent 10.0.0 alpha builds. Very slight changes cause the error to go away. This seems like it might be some kind of edge case related to the recent gc changes.

Program is below. This is running on a CPX with 10.0.0-alpha.6. As is, it causes:

MemoryError: memory allocation failed, allocating 1472 bytes

If the line

### a=1 ### uncommenting this causes MemoryError to go away

is uncommented, the error does not occur.

code.py:

# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT

# Circuit Playground digitalio example
# Rick Pump

import time
import board
import digitalio
import countio
import neopixel
a=1 ### uncommenting this causes MemoryError to go away

# start neopixel
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.01, auto_write=False)
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
# GREEN = (0, 255, 0)
# CYAN = (0, 255, 255)
# BLUE = (0, 0, 255)
# PURPLE = (180, 0, 255)
# WHITE = (255, 255, 255)
OFF = (0, 0, 0)
# end neopixel

# Create PIN
testbtn = digitalio.DigitalInOut(board.BUTTON_A)
testbtn.switch_to_input(pull=digitalio.Pull.DOWN)
vcmtimebtn = countio.Counter(board.BUTTON_B, edge=countio.Edge.RISE)
ctsw = digitalio.DigitalInOut(board.A1)
ctsw.switch_to_input(pull=digitalio.Pull.DOWN)
vcmsw = digitalio.DigitalInOut(board.A6)
vcmsw.switch_to_input(pull=digitalio.Pull.DOWN)
fltrsw = digitalio.DigitalInOut(board.A5)
fltrsw.switch_to_input(pull=digitalio.Pull.DOWN)
led = digitalio.DigitalInOut(board.D13)
led.switch_to_output()
rly = digitalio.DigitalInOut(board.A2)
rly.switch_to_output()

vcm = 0
vcmtime = (60.0)  # 5 min test - 3600 sec = 1 hour
vcmoveride = (60.0)  # 55 min test - 86400 sec = 24 hour (86400 - vctime)
dbt = (3)  # debounce

while True:
    if vcm == 1:  # vacuum is commanded
        led.value = True
        rly.value = True
        print("Vacuum Time", vcmtime)
        time.sleep(vcmtime)
        print("Vacuum Done")
        led.value = False
        rly.value = False
        print("Vacuum Overide", vcmoveride)
        time.sleep(vcmoveride)
        print("Vacuum TimeOut")
        vcm = 0
    elif testbtn.value or ctsw.value or vcmsw.value:  # button is pushed
        # time.sleep(dbt)
        vcm = 1
        print("Vacuum Start")
    elif vcmtimebtn.count == 1:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[9] = YELLOW
        pixels.show()
        vcmtime = 5
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 2:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[8] = YELLOW
        pixels.show()
        vcmtime = 10
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 3:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[7] = YELLOW
        pixels.show()
        vcmtime = 15
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 4:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[6] = YELLOW
        pixels.show()
        vcmtime = 20
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 5:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[5] = YELLOW
        pixels.show()
        vcmtime = 25
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 6:
        time.sleep(5)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[9] = YELLOW
        pixels[8] = YELLOW
        pixels[7] = YELLOW
        pixels[6] = YELLOW
        pixels[5] = YELLOW
        pixels.show()
        vcmtime = 30
        print("Vacuum Time Set", vcmtime)
        time.sleep(5)
    elif vcmtimebtn.count == 7:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[4] = YELLOW
        pixels.show()
        vcmtime = 35
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 8:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[3] = YELLOW
        pixels.show()
        vcmtime = 40
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 9:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels
8000
 off
        pixels[2] = YELLOW
        pixels.show()
        vcmtime = 45
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 10:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[1] = YELLOW
        pixels.show()
        vcmtime = 50
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 11:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels[0] = YELLOW
        pixels.show()
        vcmtime = 55
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 12:
        time.sleep(dbt)
        pixels.fill(OFF)  # turn all neopixels off
        pixels.fill(YELLOW)
        pixels.show()
        vcmtime = 60
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
    elif vcmtimebtn.count == 13:
        time.sleep(5)
        pixels.fill(OFF)  # turn all neopixels off
        pixels.show()
        time.sleep(1)
        pixels.fill(RED)  # turn all neopixels off
        pixels.show()
        time.sleep(1)
        pixels.fill(OFF)  # turn all neopixels off
        pixels.show()
        vcmtimebtn.reset()
        print("Vacuum Time Reset", vcmtime)
        time.sleep(5)
    else:
        led.value = False
        pixels.fill(OFF)
        pixels.show()
        print("Vacuum Time Set", vcmtime)
        time.sleep(dbt)
@dhalbert dhalbert added this to the 10.0.0 milestone May 18, 2025
@dhalbert dhalbert changed the title MemoryError which goes away when program is changed slightly. MemoryError goes away when program is changed slightly May 18, 2025
@dhalbert dhalbert self-assigned this May 19, 2025
@dhalbert
Copy link
Collaborator Author

After some more thorough testing, this appears just to be a program that is too big. The current behavior is a bit idiosyncratic, but when re-testing on a Metro M0, it's clear that a slightly smaller or larger program affects whether the MemoryError occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant
0