LCD Backpack + CPX Memory Allocation Error

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dogolearn
 
Posts: 25
Joined: Mon Sep 19, 2022 7:14 pm

LCD Backpack + CPX Memory Allocation Error

Post by dogolearn »

Hi-
I'm getting a memory allocation error while trying to use the I2C backpack with CPX and Circuit Python.
I stripped it down, so it is only using the shipping example and none of my other code.

Traceback (most recent call last):
File "code.py", line 7, in <module>
File "/lib/adafruit_character_lcd/character_lcd_i2c.py", line 37, in <module>
MemoryError: memory allocation failed, allocating 232 bytes

gc.mem_free() = 16864
So, the CPX has 16k bytes and is failing to allocate 96 bytes? Maybe that's a silly observation. Full is full.
I'm using this bundle: adafruit-circuitpython-bundle-8.x-mpy-20230519
from https://github.com/adafruit/Adafruit_Ci ... on_CharLCD, I'm using:
(1) charlcd_i2c_mono_simpletest.py
(2) character_lcd_i2c.py
My backpack is the Stemma-QT version, 3-5V
My LCD is a Sparkfun 2-row. I don't know the pedigree - it was in a drawer
adafruit-circuitpython-circuitplayground_express-en_US-8.0.5.uf2

I've read some other threads about memory allocation and the answer is that some modules just don't fit on some microcontrollers. I'm not sure this passes the sniff test: my CPX can't run an example file at all? It seems like Adafruit would have run into this while testing out the Stemma-QT version

Well, I think the CPX is the bee's knee's but I don't mind switching. So, my follow-on question is: what board should I use? Or, even better (teach me to fish), how do I choose a board? I want to go on to make lots and lots of projects (bwahahaha). I want to add peripherals to my systems without much risk of hitting this kind of issue.

This system needs:
2 digital outputs, 2 buttons & I2C, I2C LCD display, I2C Temp sensor
Not limited in physical space
Wall plug-in; no low-power needs
Not too cost-sensitive
Needs to stay with Circuit Python; I'm old and I want to converge on one dev environment; one tool set

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

Re: LCD Backpack + CPX Memory Allocation Error

Post by dastels »

If you want to stay with CircuitPython then get the board that fits your other (non memory) needs that has as much RAM as you can find. If you like the CPX, have a look at the CircuitPlayground Bluefruit. The CPX only has 32K, the CPBT has 256K, that's 8 times an much and will give you lots of room. It has all the same capabilities plus bluetooth.

Dave
Last edited by dastels on Mon May 22, 2023 8:40 am, edited 1 time in total.
Reason: fix typo

User avatar
dogolearn
 
Posts: 25
Joined: Mon Sep 19, 2022 7:14 pm

Re: LCD Backpack + CPX Memory Allocation Error

Post by dogolearn »

Thanks very much for the feedback!!

User avatar
dogolearn
 
Posts: 25
Joined: Mon Sep 19, 2022 7:14 pm

Re: LCD Backpack + CPX Memory Allocation Error

Post by dogolearn »

Just for closure, I did some more experimenting and never did get the I2C backpack working with the CPX. The problem really seems to be the memory required for CicuitPython. Once circuitPython is installed on the CPX, very little memory is left over. Not enough for this I2C backpack + LCD. The CPX does so many GREAT things, but it is not a good board for adding external peripherals like the I2C backpack + LCD. I did get it working with the MCP9808 temp sensor, but when I added a second peripheral (OLED) it ran into memory errors again.

So, when your project needs external peripherals (displays, radios, GPS....), set your CPX aside and use another board like a feather. I'm now on a Feather (Feather M4 Express with samd51j19) and the project is back on track!

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

Re: LCD Backpack + CPX Memory Allocation Error

Post by dastels »

Feathers are good. If you don't need the battery support and access to FeatherWings, the ItsyBitsy line of boards are good as well. If you want to stick with the CPX format and capabilities you can have a look at the CircuitPlayground Bluefruit. As a bonus, it has BlueTooth capabilities as well as a lot more RAM.

Dave

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

Return to “Adafruit CircuitPython”