Creating new module for OpenMV

Hello I hope I have not annoued you by my questions concerning C coding.
I have been investigating you omv project. Now I can create new methods for existing omv modules and compile native modules(.mpy files).
But current time I would like to create my own module which I can summon in OpenMV IDE by “import my_module” string.

I have created it but OpenMV IDE informed me that module wasn’t exist.
Seems that my module was compiled but not linked or my_module is not existed in OpenMV IDE database.

So my question is. Is it necessary to have names of modules in OpenMV IDE database to use it?

No, it needs to be added to builtin modules in mpconfigport.h.

Problem is solved.
I found mpconfigport.h file where I added my code. And now my module can be imported.

Thanks :smiley: :smiley: :smiley:

Can you explain in the details how to add a module in OpenMV firmware? Thank you

Sorry for late reply. Too busy. I have not used OpenMV board for almost a year. Probably something can be changed for that year.
You can use existing micropython modules as examples. As I remember the logic was simple.

  1. Open folder in your repository openmv/src/omv/py

  2. Then create .c file. For example foo.c
    This .c file contains you functions and other things

  3. In .h file qstrdefsomv.h add following strings
    Q(module’s name)
    Q(module’s method name)
    Q(second module’s method name)

  4. In folder openmv/src/micropython/ports/stm32 open file mpconfigport.h and add next string
    extern const struct _mp_obj_module_t foo_module;

    you should add following string { MP_OBJ_NEW_QSTR(MP_QSTR_foo), (mp_obj_t)&foo_module },
    It is made for registering you module in system

  6. in makefile (in folder openmv/src ) you should add module’s object by using next string foo.o \ .

  7. in makefile (in folder openmv/src/omv ) you should add string foo.c \ .

I can check this list in detail on weekends if it is necessary. Also you can google how to add your own module in micropython, it looks similar,
as I remember there was useful information about this topic.

пн, 2 авг. 2021 г. в 10:43, Zutroy via OpenMV Forums <>:


Thank you very much! It looks like a tutorial, best answer ever!! Thank you.