Importing a custom class

Ok. I am working on a class for reading a vl53l0x sensor. I got the class in the same folder as the test sketch and using from vl53l0x import * but I keep getting an error about no module with that name. The file name is vl53l0x.py. So the question is how do I do this?

Thanks
Mike

http://wiki.micropython.org/Importing-Modules

Since the internal flash is disabled when the SD card is attached you need to have two copies of the script for each situation.

Thanks. That worked. I also did a sys.path but it returned a empty set. Not sure what that means.

Mike

Unfortunately, the link is not working (502 Bad Gateway).

Can you describe some sort of best practise when working with OpenMV IDE and custom modules?
As far as I know, I need to copy them to the camera board by hand. This is rather tedious during development…

Hi, we will be releasing a library feature for OpenMV using OpenMV IDE in the next version.

So, in your home directory will be a library folder (think Arduino). We may also scan a MP library directory too for general purpose MP code.

Anyway, when you click run for your script OpenMV IDE will regex any import statements, and if it sees a module not built-in it will look on the file system for it. If it doesn’t see it it will look in the library dirs first for the module and if it finds it copy it to the required location. It will fallback to a shipped system library directory otherwise and copy those instead. Note that if it sees a change between the library files on the PC and in your code it will update your system.

While this sounds heavy it only has to do this for any custom libraries you use.

We’ll be shipping a MQTT library with the next OpenMV IDE release.

Hi, library management is now working in OpenMV IDE. It will automatically scan a user folder now along with the examples folder for imports in your code and copy/update modules as necessary.

Boom! OpenMV IDE v1.8.1 is here! | OpenMV

I’m having troubles using the import feature. I can import but ONLY if I specify exactly what I need. For example, if I create a constants.py file with a variable, I can only access it if I import that variable.

constants.py:

AREA_THRESHOLD = 20

Then, from another file, I try this, but it doesn’t work:

import constants
print(AREA_THRESHOLD)

But this works:

from constants import AREA_THRESHOLD
print(AREA_THRESHOLD)

Is this a bug? I’m doing this on a Mac. Or am I just not doing it right?

This works, so I don’t think this is a big issue anymore:

from constants import *

Importing in python is not like C. Imports are under a module name space which is the file name.

So, you could do something like:

import constants
print(constants.AREA_THRESHOLD)

Hi,
I am having the same problem with nano 33 ble. I try every propostion above but does not work.
Any suggestion ?
image