Feather MO Express Memory Limit

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
Ritgrad83
 
Posts: 24
Joined: Tue Aug 18, 2015 11:17 pm

Feather MO Express Memory Limit

Post by Ritgrad83 »

I am following the I Vote(d) Pin Example - https://learn.adafruit.com/i-vote-d-pin/code using Feather MO Express and OLED FeatherWing mounted on feather doubler board. The first time I ran - I got this message

Code: Select all

code.py output:
Traceback (most recent call last):
  File "code.py", line 6, in <module>
  File "adafruit_debouncer.py", line 32, in <module>
ImportError: no module named 'adafruit_ticks'
It was missing module named adafruit_ticks which was not mentioned in the documentation on site - so I added it from the latest CP library

This is what the Feather MO Express Lib looks like
Lib_Files.png
Lib_Files.png (43.65 KiB) Viewed 68 times
Every time I try to run the code - I keep getting a memory error like this

Code: Select all

code.py output:
Traceback (most recent call last):
  File "code.py", line 10, in <module>
  File "adafruit_displayio_ssd1306.py", line 60, in <module>
MemoryError: memory allocation failed, allocating 64 bytes
or this

Code: Select all

code.py output:
Traceback (most recent call last):
  File "code.py", line 9, in <module>
MemoryError: memory allocation failed, allocating 1450 bytes
Here is the entire code as copied from the site https://learn.adafruit.com/i-vote-d-pin/code

Code: Select all

# SPDX-FileCopyrightText: 2020 Collin Cunningham for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import board
from adafruit_debouncer import Debouncer
import digitalio
import displayio
from adafruit_display_text import label
import adafruit_displayio_ssd1306
from adafruit_bitmap_font import bitmap_font

displayio.release_displays()

# Set up button pins
pin_a = digitalio.DigitalInOut(board.D9)
pin_a.direction = digitalio.Direction.INPUT
pin_a.pull = digitalio.Pull.UP

pin_b = digitalio.DigitalInOut(board.D6)
pin_b.direction = digitalio.Direction.INPUT
pin_b.pull = digitalio.Pull.UP

pin_c = digitalio.DigitalInOut(board.D5)
pin_c.direction = digitalio.Direction.INPUT
pin_c.pull = digitalio.Pull.UP

button_a = Debouncer(pin_a) #9
button_b = Debouncer(pin_b) #6
button_c = Debouncer(pin_c) #5

# Load font
font = bitmap_font.load_font('/mround-31.bdf')

# Set up display & add group
i2c = board.I2C()
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
group = displayio.Group()
display.show(group)

# Add content to group
default_text = "I VOTE  !"
text_area = label.Label(font, text=default_text, color=0xFFFFFF, x=0, y=17)
group.append(text_area)

while True:

    # Debounce buttons
    button_a.update()
    button_b.update()
    button_c.update()

    # Check for button presses & set text
    if button_a.fell:
        text_area.text = default_text
        text_area.x = 0
    elif button_b.fell:
        text_area.text = "I VOTED!"
        text_area.x = 0
    elif button_c.fell:
        text_area.text = "DID U?"
        text_area.x = 18

    display.show(group)

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

Re: Feather MO Express Memory Limit

Post by dastels »

It's not your code, it's the display code that too big for the SAMD21. IMO, your best alternatives are switching to a Feather M4 Express https://www.adafruit.com/product/3857 (it has a SAMD51 with 6 times more RAM) or programming in C++ (the compiled code is far smaller and lives in flash, not RAM).

Hmm... the Feather M4 Express is out of stock. The Feather RP2040 https://www.adafruit.com/product/4884 is a good alternative and has even more RAM (over 8 times what the SAMD21 has).

Dave

User avatar
Ritgrad83
 
Posts: 24
Joined: Tue Aug 18, 2015 11:17 pm

Re: Feather MO Express Memory Limit

Post by Ritgrad83 »

Thanks again - shouldn't someone update the page so that it features M4 instead of M0? Luckily I snagged a few M4s from Amazon

User avatar
TI545
 
Posts: 98
Joined: Tue Feb 27, 2018 5:25 pm

Re: Feather MO Express Memory Limit

Post by TI545 »

I see that the learn.adafruit page was written in 2020 with an older circuitpython. It might be that now using circuitpython 7, it needs more RAM than it used to.

Line 66 is the instruction:

Code: Select all

  display.show(group)
I was going to suggest using a smaller font, but I see the code bundle only has that one 31 pt font included. Is there a place to try a smaller font?
( bundle at https://learn.adafruit.com/pages/20275/ ... d?type=zip )

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

Re: Feather MO Express Memory Limit

Post by dastels »

Yes, both CircuitPython and the various libraries have evolved over time. Adding features almost invariably means needing more memory. Python is not an speed/space efficient language to start with. What it is efficient with is developer time and comfort, especially for people new to programing.

Dave

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

Return to “Feather - Adafruit's lightweight platform”