Page 1 of 1

Incorporating MyLib.py into the flashed hex file

Posted: Tue May 05, 2020 8:34 am
by pmulvey
I want to put together a large MyLib.py. Currently this kills the microbit once it passes a certain size throwing memory allocation and parser errors. It would be great if his library could be flashed and then allow the user to call it for their own smaller programs. I want to use the microbit to teach micropython and I feel that it would be useful if I could allow the students to use my library for I2C lCD, PCF8574 chip I/O all of which I have written. Any ideas??

Re: Incorporating MyLib.py into the flashed hex file

Posted: Wed May 20, 2020 4:42 am
by jimmo
pmulvey wrote:
Tue May 05, 2020 8:34 am
Currently this kills the microbit once it passes a certain size throwing memory allocation and parser errors.
Unfortunately the micro:bit is just a really tiny CPU (16kiB of RAM).

There isn't really a good solution here sadly... on other ports you might be able to use a frozen module (where you pre-compile mylib.py directly into the firmware, which means it doesn't have to be parsed by the board and the bytecode can be executed directly from ROM) but unfortunately that doesn't seem to be an option on micro:bit MicroPython.

Re: Incorporating MyLib.py into the flashed hex file

Posted: Wed May 20, 2020 1:59 pm
by SpotlightKid
I guess you have to partition you library into smaller modules and let the students import / incorporate only the parts really needed for the current task. Probably makes for a better (more structured) library design too.