Debugging MicroPython program size issues

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
adamnfish
Posts: 2
Joined: Wed Aug 30, 2017 1:40 pm

Debugging MicroPython program size issues

Post by adamnfish » Wed Aug 30, 2017 9:18 pm

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!

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Debugging MicroPython program size issues

Post by pythoncoder » Thu Aug 31, 2017 8:16 am

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.

adamnfish
Posts: 2
Joined: Wed Aug 30, 2017 1:40 pm

Re: Debugging MicroPython program size issues

Post by adamnfish » Thu Aug 31, 2017 5:02 pm

This is a very helpful resource, thank you.

Post Reply