andyclymer/minikbd

Getting memory allocation error

kglasnapp opened this issue · 5 comments

I got two of your boards and set one of them up as a 6 key. I tried putting the software on the trinket and I get the output below:

Press any key to enter the REPL. Use CTRL-D to reload.
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
main.py output:
Traceback (most recent call last):
File "main.py", line 8, in
MemoryError: memory allocation failed, allocating %u bytes

I tried it both on Circuit Python 2 and 3.0.3 and they both had the same problem. I am attaching a zip of the circuitpy directory that I used with 3.0.3 to help understand what may be wrong.
pack.zip

Note: The boards are beautiful

Thanks for your support
Keith Glasnapp

Hi Keith, thanks for building the MiniKbd! I'm sorry you had this problem...

The memory error happens when main.py tries to import my ButtonMatrix library.

I've built a good number of the six key variety without this problem but I have a thought — is there any chance you're using the device on Windows? I've only tested this configuration on the Mac where it doesn't use the additional Windows driver that comes on the Trinket, so there's a chance that it just exceeds the amount of memory available on the Trinket when it also has to load the additional driver.

My ButtonMatrix library is a little bit over-engineered, it's really built to work with any number of buttons that are set up in a matrix of rows and columns, but this is a little bit overkill for the MiniKbd which will always only be configured with two or six buttons. I'm going to slim the library down just for the MiniKbd to keep its memory usage in line. My six-key build is at my studio space, so I'll update the code tonight and test it when I'm at the studio in the morning. I'll follow back up here once it's all set.

Hi @kglasnapp , I have some updated code that I think should solve this problem. When you have a moment, would you try the new "Six Key" sample code?

The old example used my ButtonMatrix library which is built to work with any number of buttons, this new sample code instead uses a miniKbdButtons library which has been pared down by quite a lot. It will use less storage and memory on the Trinket M0, and I hope that this will resolve the problem of the MemoryError you were having.

It's working for me over here, please let me know if it works for you!

Andy

@kglasnapp Great, let me know if you have any other problems or questions!