Closed
Description
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 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)