Incorporating MyLib.py into the flashed hex file

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
pmulvey
Posts: 45
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Incorporating MyLib.py into the flashed hex file

Post by pmulvey » Tue May 05, 2020 8:34 am

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??
Paul Mulvey

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Incorporating MyLib.py into the flashed hex file

Post by jimmo » Wed May 20, 2020 4:42 am

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.

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: Incorporating MyLib.py into the flashed hex file

Post by SpotlightKid » Wed May 20, 2020 1:59 pm

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.

Post Reply