[Microbit-Python] User modules?

Damien George damien.p.george at gmail.com
Fri Feb 26 18:34:03 EST 2016


There is now (experimental) support for frozen bytecode, where your
.py file is compiled offline and then frozen into the firmware when
the firmware is built.  This approach does not use any RAM (just
flash).  But it requires compiling the firmware each time you change
the module.

This stuff is pretty advanced, probably out of scope of the microbit.

On Fri, Feb 26, 2016 at 10:58 AM, Joe Glancy <joe.t.glancy at gmail.com> wrote:
> You can make your own modules in C/C++ using one of the existing modules as
> guidance. It's (almost) as simple as creating a couple of files and adding
> your module to a few files.
>
>
> On Fri, 26 Feb 2016 9:37 am M.-A. Lemburg <mal at egenix.com> wrote:
>>
>> On 25.02.2016 20:33, Christopher Arndt wrote:
>> > Is there any possibility to modularize MicroPython code for the
>> > micro:bit?
>> >
>> > Since there isn't a flash file system, I guess there's no way to store
>> > user modules. Or is there a way to embed additional modules into the
>> > firmware?
>>
>> We had discussed this a few weeks ago. It should be possible
>> to the uflash tool to combine several modules into one and
>> then playing a few tricks to get the namespaces right.
>>
>> MicroPython appears to be using classes for the module namespaces,
>> so putting the code into a class wrapper appears to be a good
>> solution for the namespaces:
>>
>> >>> import music
>> >>> type(music)
>> <class 'module'>
>>
>> All that said, I don't know how much flash memory is available
>> for Python scripts, and of course, the memory constraints don't
>> allow for many code objects to exist anyway. The 32kB retail
>> version of the MB should reduce the latter problem a bit.
>>
>> Perhaps Cython could be used to compile Python modules into
>> C and then have those added to the firmware when flashing the
>> MB. That should reduce the code object overhead.
>>
>> --
>> Marc-Andre Lemburg
>> eGenix.com
>>
>> Professional Python Services directly from the Experts (#1, Feb 26 2016)
>> >>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>> >>> Python Database Interfaces ...           http://products.egenix.com/
>> >>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
>> ________________________________________________________________________
>> 2016-02-19: Released eGenix PyRun 2.1.2 ...       http://egenix.com/go88
>>
>> ::: We implement business ideas - efficiently in both time and costs :::
>>
>>    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>>     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>>            Registered at Amtsgericht Duesseldorf: HRB 46611
>>                http://www.egenix.com/company/contact/
>>                       http://www.malemburg.com/
>>
>> _______________________________________________
>> Microbit mailing list
>> Microbit at python.org
>> https://mail.python.org/mailman/listinfo/microbit
>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>


More information about the Microbit mailing list