Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.

Stick with CircuitPython or convert over to C++?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Stick with CircuitPython or convert over to C++?

by evstar on Thu Jul 22, 2021 10:04 pm

Hi all,

I have been working on game project on my clue for a few months now and at this point it seems to have become too large? 1781 lines over 10 .py files at 64Kb. Max 14 sprites on screen at a time. 44 classes. Gc.mem_free() usually reads in the 31,000's range. I've been running into memory allocation errors left and right that I'm guessing are due to the amount of code I'm trying to write. I make sure to call the garbage collector quite regularly but still, creating new files and methods generate the memory allocation error.

I've been running the 6.x CircuitPython firmware and hoped that perhaps upgrading to 7.0.0 alpha may help things. Unfortunately, I couldn't get it to run as there seemed to be a library that used the outdated "gamepad" library that still needs to be migrated to the new "keypad".

Then I stumbled across the Arduino side of things and using C++ and the native libraries. I created an Arduino project and tried some sample code and it seemed to be promising. I began converting my Python project into C++ and realized that it may be quite of a pain. Specifically dealing with bitmap sprites. Thus far I've really enjoyed using displayio on Python and there just doesn't seem to be an established library in C++. I tried Arcada but it still seems that I'll be doing a lot of the display manipulation work myself. I looked for some pre-built libraries or example code for quite a while and didn't really stumble upon anything that seemed to jump out at me.

My questions are this; am I missing something on the Python side? Is my project aggressively large? Should I dig deep into the Arduino side and write a new display/sprite manipulation system?

Posts: 13
Joined: Wed Jun 02, 2021 9:41 pm

Re: Stick with CircuitPython or convert over to C++?

by dastels on Fri Jul 23, 2021 12:53 pm

I've run into this repeatedly on projects that have grown. I usually end up switching to C++... usually after giving up in frustration and chucking the whole thing in a dark corner for a while while I regroup and plan a different approach. CircuitPython is wonderful for relatively simple, relatively small projects, but it's hungry for memory and CPU cycles (I.e. big and slow). In contrast, C++ is lean and fast, but is objectively harder to work with. C++ is still the language of choice for embedded projects that are substantial and/or need high performance.

To me it sounds like a case of needing to switch to a more appropriate language. As for libraries. I'm sure they're out there. C++ is the primary gaming language, especially for small/mobile/handheld platforms.

Did you have a look at the GFX library? https://learn.adafruit.com/adafruit-gfx-graphics-library


Posts: 9728
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.