I'm currently building a small tool with the huzzah (adafruit feather version) which communicates with an OBD-II adaptor via wifi.
I have a neopixel led strip aswell which is live showing me the information I gather. Now that the project is soon to be finalized I'm running into an annoying issue:
Code: Select all
MemoryError: memory allocation failed, allocating 158 bytes
I guess that this issue is based on the variables I initialize in the init part of my sub-modules, but I don't know how I could strip them down to reduce their size (Web-Repl is also disabled). Can anyone help me making this more memory effecient? Thanks a lot.
*BTW if any admin could enable BBCode for this post, would be great...
Above error happens either at the import of "display" or at the import of "elm".
main.py init:
Code: Select all
from time import sleep_ms, ticks_ms
import ujson as json
from states import MPyState, ELMState
from display import Display
from elm import ELM
import network
import machine
Code: Select all
from machine import Pin
from machine import Timer
from time import ticks_ms
from neopixel import NeoPixel
from ema import EMA
from states import MPyState
from constants import Car
import urandom
import math
import machine
class Display:
def __init__(self, numLeds=10, brightnessReadTimeout=10000, pin=0):
dataPin = Pin(pin, Pin.OUT)
self.numLeds = numLeds
self.pixels = [(0,0,0)] * numLeds
self.display = NeoPixel(dataPin, numLeds)
self.way = [False] * numLeds
for i, led in enumerate(self.pixels):
rand = urandom.getrandbits(8)
self.pixels[i] = (0,0,rand)
self.state = MPyState.INIT
self.lastState = MPyState.INIT
self.isSwitching = False
self.delayCounter = 0
self.position = 0
self.mustWait = False
self.adc = machine.ADC(0)
self.ema = EMA()
self.brightness = 100
self.brightnessDelay = ticks_ms()
self.brightnessReadTimeout = brightnessReadTimeout
self.displayBrightness = 100
self.value = -255
self.timer = Timer(-1)
self.timer.init(period=33, mode=Timer.PERIODIC, callback=self.refresh)
self.show()
Code: Select all
from states import BufferState, ELMState
from utime import sleep_ms, ticks_ms
from ema import EMA
import math
import socket
class ELM:
def __init__(self, adress="192.168.0.10", port=35000):
self.adress = adress
self.port = port
self.elmSocket = socket.socket()
self.bufferState = BufferState.NONE
self.elmState = ELMState.INIT
self.rawBarometricPressure = -1
self.rawManifoldAbsolutePressure = -1
self.boostPressure = -1
self.step = 0
self.ema = EMA()
self.waitingTimer = 0
self.barometricTimer = 0
self.mapTimer = 0
self.errors = 0
print("Initialized ELM at \"{0}\" with port {1}".format(adress,port))