I've been building a little game for the micro:bit using MicroPython, but I've been finding that beyond a certain complexity the program fails to load on my device. The loading light flashes for a while as normal but as far as I can tell the program never starts. There is no feedback on what causes the problem, it just silently fails. I'm aware the micro:bit is a very constrained environment and I've made no effort to keep the program small so this isn't a huge surprise, but it's tricky to know what to change without information about what the problem is.
My question is how I'd be able to debug what is causing the problem with the program's compilation/execution. If possible, it would be great to also hear tips on the limitations in general, and any advice on Python features to avoid (classes?) to fit reasonable sized programs onto the device.
Here's the source code:
https://github.com/adamnfish/microbit
To make my life easier I built a mini-framework that abstracts away common application patterns to make it really easy build working programs (microbit-lib.py). This works great, but I suspect it has contributed to the problem mentioned above, in particular my use of an overridable Python class as the basis for that framework.
The "Dodge" game is the application in question.
https://github.com/adamnfish/microbit/b ... b/dodge.py
It works fine as is, but uncommenting the following block causes it to silently fail.
https://github.com/adamnfish/microbit/b ... dge.py#L36
This is such a small change that I must be right up against some limit the micro:bit has. I'd like to know what the nature of that limit is before I re-write everything, to make sure I'm not wasting effort.
The "build.py" script assembles the final output, I'm using `uflash` to transfer the program. To reproduce the build, you can run the following (assuming a virtualenv with uflash installed):
venv/bin/uflash build.py dodge.py
This will assemble an intermediate Python file (`program-src.py` by default) and then use uflash to send that program to the attached device.
I'd be very grateful for any advice, general or specific. Thanks for your time!
Debugging MicroPython program size issues
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Debugging MicroPython program size issues
You might like to read http://docs.micropython.org/en/latest/e ... ained.html which provides advice on programming resource constrained targets.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Debugging MicroPython program size issues
This is a very helpful resource, thank you.