importing a third-party module in my script #12328
-
Hi, im new to micropython but ill give my best to describe my issue i have setup my Arduino Nano 33 BLE with the micropython firmware and im using the pyboard.py tool to execute some code and test my setup so far. I can run commands so the communication with the device seems to be setup correctly. Now i want to use this module https://github.com/robert-hh/ads1x15 to use my ads1115. But when i now use: python3 pyboard.py -c "import ads1x15.py" it can not find the module. sorry if its just some simple setup for micropython im forgetting so he also searches in the directory but i dont really know how to proceed from here and was hoping for some help Thank you in advance and i hope i described my problem good enough |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Better use mpremote.py. It's either here https://github.com/micropython/micropython/tree/master/tools/mpremote |
Beta Was this translation helpful? Give feedback.
-
Install it using (The first line below is key!) ❯ mpremote mip install github:robert-hh/ads1x15/ads1x15.py
Install github:robert-hh/ads1x15/ads1x15.py
Downloading github:robert-hh/ads1x15/ads1x15.py to /lib
Installing: /lib/ads1x15.py
Done
❯ mpremote
Connected to MicroPython at /dev/ttyUSB0
Use Ctrl-] to exit this shell
>>> import ads1x15
>>> help(ads1x15)
object <module 'ads1x15' from '/lib/ads1x15.py'> is of type module
ADS1015 -- <class 'ADS1015'>
ADS1114 -- <class 'ADS1114'>
ADS1115 -- <class 'ADS1115'>
_CHANNELS -- {(2, None): 24576, (3, None): 28672, (0, 1): 0, (0, 3): 4096, (1, 3): 8192, (2, 3): 12288, (0, None): 16384, (1, None): 20480}
__file__ -- /lib/ads1x15.py
__name__ -- ads1x15
_RATES -- (0, 32, 64, 96, 128, 160, 192, 224)
_GAINS -- (0, 512, 1024, 1536, 2048, 2560)
ADS1113 -- <class 'ADS1113'>
_GAINS_V -- (6.144, 4.096, 2.048, 1.024, 0.512, 0.256)
time -- <module 'time'>
>>> |
Beta Was this translation helpful? Give feedback.
On esp32, esp8266 and rp2;
/lib
is added to sys.path during firmware initialisation (inmain.c
). It seems that is not universally true for all ports, so you could add it in yourmain.py
:import sys; sys.path.append("/lib")
.