How to import my driver(e.g private ".py" file)

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
lc2047
Posts: 5
Joined: Wed Jul 25, 2018 4:23 am

How to import my driver(e.g private ".py" file)

Post by lc2047 » Thu Apr 30, 2020 1:54 am

Hi

With python(PC ver.), we can split something(e.g. function, diver, or data) in a separate file. And import it when using it.
Shell we do that in micropython?

However, the system(not sure in IDE or board) seem to accept ONE file(main.py or main.hex) only.

If not possible, the script file(main.py) will be very big and difficult to read.

I saw some 3rd party provide their library in ".hex". This style like a ".dll" in PC system. Do we have another way to except this method?

Please share your experience/ comment.


Thanks

User avatar
T-Wilko
Posts: 30
Joined: Thu Sep 19, 2019 8:08 am

Re: How to import my driver(e.g private ".py" file)

Post by T-Wilko » Thu Apr 30, 2020 1:19 pm

Hi there,

You are correct in your observation that MicroPython reads main.py, but it actually reads a boot.py before that as well.

To import a driver file (e.g. 'driver.py' that you have uploaded to the board's flash already) you do exactly what you do in Python and simply

Code: Select all

import driver
and from there you can utilise classes/functions/variables that exist in that .py file.

I personally haven't dealt with any hex file in relation to MicroPython so I'm afraid I'm of no assistance there, although I don't think there's any relation there to MicroPython drivers.

lc2047
Posts: 5
Joined: Wed Jul 25, 2018 4:23 am

Re: How to import my driver(e.g private ".py" file)

Post by lc2047 » Thu May 07, 2020 2:00 am

Hi @T-Wilko

Thanks for your share.

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

Re: How to import my driver(e.g private ".py" file)

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

lc2047 wrote:
Thu Apr 30, 2020 1:54 am
However, the system(not sure in IDE or board) seem to accept ONE file(main.py or main.hex) only.
Which board are you using? .hex file suggests maybe micro:bit ?

Post Reply