We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Omega2 Dash ADC EXP (Python) not connecting.



  • @tjoseph1

    Although Micropython is preferred, it doesn't work for the dash I have. The micropython command for some reason lacks access to the same libraries that python has.

    Again, I can run python mypython.py file
    where I cannot run the same file with micropython mypython.py file.

    "
    The next part of this is getting the call micropython swtich.py to be what activates the swtich file instead of calling python switch.py

    This is so that I can use the Micropython & LVGL support of the Dash. link
    "

    but when I call micropython switch.py it dumps this error: ImportError: no module named 'OmegaExpansion'


  • administrators

    @György-Farkas said in Omega2 Dash ADC EXP (Python) not connecting.:

    If the above is correct users should be warned a possible I2C address conflict.

    Yes, this is correct, the Omega2 Dash uses an XPT7603 I2C-based touch screen controller. Didn't realize it conflicts with the ADC Expansion.

    Where is the best place to document this so users are aware?



  • @LightSwitch :
    I guess you installed micropython by uncommenting the 5th line of /etc/opkg/distfeeds.conf, followed by an "opkg update" and then "opkg install micropython"
    root@Omega-745F:/tmp# cat /etc/opkg/distfeeds.conf
    line5: src/gz openwrt_packages http://downloads.openwrt.org/releases/18.06-SNAPSHOT/packages/mipsel_24kc/packages

    root@Omega-745F:/tmp# opkg files micropython
    Package micropython (1.9.2-1f78e7a43130acfa4bedf16c1007a1b0f37c75c3-1) is installed on root and has the following files:
    /usr/bin/micropython

    There is one more package that would be required:

    root@Omega-745F:/tmp# opkg install micropython-lib

    root@Omega-745F:/tmp# opkg files micropython-lib
    Package micropython-lib (1.9-f5fe55aaef1a39d3d56f07040c0ff9f7e841fdf7-1) is installed on root and has the following files:
    /usr/lib/micropython/binhex.py
    ...(There are about 196 .py files/libs)
    /usr/lib/micropython/time.py
    (even "time" is part of micropython-lib and micropython points to the libs provided by micropython-lib)
    ...
    root@Omega-745F:/tmp# micropython
    MicroPython v1.9.2 on 2020-09-28; linux version
    Use Ctrl-D to exit, Ctrl-E for paste mode
    >>> import sys
    >>> print(sys.path)
    ['', '/root/.micropython/lib', '/usr/lib/micropython']
    >>> <Ctrl-d>
    root@Omega-745F:/tmp#

    I have not done any micropython on Omega, but on an STM32 board, using the download provided at:
    https://www.micropython.org/download/stm32/ and I guess there could be differences (v1.13-77 vs Omega's Linux port shows v1.9.2 ?). There is no Linux on STM32, micropython is the alpha and omega there.

    This:
    https://www.oreilly.com/library/view/programming-with-micropython/9781491972724/
    was very useful..

    I am not sure if "micropython-lib" contain all that you need, but micropython with out "micropython-lib", it is pretty retarded.
    It is up to you to chose.

    Thanks..



  • @tjoseph1

    I have both of those installed, however it still throws the OmegaExpansion error is missing.

    root@Omega-C592:~/OmegaHomeControl# opkg list | grep -i micropython
    lv_micropython - 1.9.2-2
    micropython-lib - 1.9-f5fe55aaef1a39d3d56f07040c0ff9f7e841fdf7-1



  • @LightSwitch :
    "opkg list-installed" gives you the list of pkgs that are already installed. Pls try opkg --help to get all the switches that opkg accepts.



  • @tjoseph1 said in Omega2 Dash ADC EXP (Python) not connecting.:

    "opkg list-installed

    This does list the installed packages. The issue I now have is that when I run "micropython script.name.py" command with the file, I get an error "ImportError: no module named 'OmegaExpansion'"

    The same file works with the non-dash omega, AND the dash when I run "python script.name.py".

    As far as I know, I have to use micropython to run the GUI library.

    This is installed:
    lv_micropython - 1.9.2-2
    micropython-lib - 1.9-f5fe55aaef1a39d3d56f07040c0ff9f7e841fdf7-1

    pyOmegaExpansion - 0.9-1
    python3-omega-expansion - 0.9-1



  • @LightSwitch try typing echo $PYTHONPATH check OmegaExpansion is accessible in your python search path.



  • @crispyoz said in Omega2 Dash ADC EXP (Python) not connecting.:

    echo $PYTHONPATH

    This just creates a new blank line. Nothing is returned.



  • @LightSwitch :
    root@Omega-745F:/tmp/tmp# opkg list | grep -i adc-exp
    adc-exp - 0.3-2 - Command line utility for ADC Expansion
    python-adc-exp - 0.3-2 - Python module to interact with Onion ADC Expansion
    python3-adc-exp - 0.3-2 - Python3 module to interact with Onion ADC Expansion

    We have two choices, python-adc-exp (python 2) and python3-adc-exp (python3)

    From https://micropython.org :
    "MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments"

    So we shall limit ourselves to python3 libs while working with micropython. Also, python2 has reached EOL and is not advised for new projects.

    root@Omega-745F:/tmp/tmp# opkg install python3-adc-exp
    Package python3-adc-exp (0.3-2) installed in root is up to date.

    root@Omega-745F:/tmp/tmp# opkg files python3-adc-exp
    Package python3-adc-exp (0.3-2) is installed on root and has the following files:
    /usr/lib/python3.6/OmegaExpansion/AdcExp.py

    root@Omega-745F:/tmp/tmp# opkg list-installed |grep adc-exp
    adc-exp - 0.3-2
    python3-adc-exp - 0.3-2

    root@Omega-745F:/tmp/tmp# micropython
    MicroPython v1.9.2 on 2020-09-28; linux version
    Use Ctrl-D to exit, Ctrl-E for paste mode
    >>> from OmegaExpansion import AdcExp
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: no module named 'OmegaExpansion'
    >>>
    >>> import sys
    >>> sys.version
    '3.4.0' (The uPython confirms to Python3, v 3.4.0)
    >>> sys.path
    ['', '/root/.micropython/lib', '/usr/lib/micropython'] (these are the PATH python will look for libs; micropython-lib resides under "/usr/lib/micropython")
    >>> <Ctrl-d>

    Let us add non-"micropython-lib" libraries to /root/.micropython/lib which is "compiled into" micropython.

    root@Omega-745F:/tmp/tmp# mkdir -p /root/.micropython/lib (the dir is non-existant; let us create it..)
    root@Omega-745F:/tmp/tmp# ln -s /usr/lib/python3.6/OmegaExpansion /root/.micropython/lib/

    root@Omega-745F:/tmp/tmp# ls -l /root/.micropython/lib
    lrwxrwxrwx 1 root root 33 Sep 29 05:39 OmegaExpansion -> /usr/lib/python3.6/OmegaExpansion

    root@Omega-745F:/tmp/tmp# micropython
    MicroPython v1.9.2 on 2020-09-28; linux version
    Use Ctrl-D to exit, Ctrl-E for paste mode
    >>> locals()
    {'__name__': '__main__'}
    >>>
    >>> from OmegaExpansion import AdcExp (OmegaExpansion is directly "visible" under sys.path after the "ln -s", above)
    >>> import time
    >>> locals()
    {'time': <module 'time' from '/usr/lib/micropython/time.py'>, '__name__': '__main__', 'AdcExp': <module 'OmegaExpansion.AdcExp' from '/root}
    >>>

    To add another python3 lib, install it; create its link under "/root/.micropython/lib". as above..
    Again, every python3 lib might NOT be compatible with micropython.

    More info about sys lib is here:
    http://docs.micropython.org/en/v1.9.2/pyboard/library/sys.html

    Every language "author" has made certain choices while designing it. As application developers, it pays off if we understand the "under-the-hood" design. Every minute on that direction is well-spent.

    Thanks..



  • @tjoseph1

    Thank you for your assistance. Certainly, the more I know the better I will understand how this all pulls together. What you've shared so far is helping quite a bit. I'm onto the next issue now.

    root@Omega-C592:~/OmegaHomeControl# micropython dash.py
    Traceback (most recent call last):
      File "dash.py", line 5, in <module>
      File "/root/OmegaHomeControl/switch.py", line 3, in <module>
      File "/root/OmegaHomeControl/relays.py", line 1, in <module>
    ImportError: no module named 'OmegaExpansion.relayExp'
    root@Omega-C592:~/OmegaHomeControl# micropython
    MicroPython reboot-7475-ge6757b4765-dirty on 2020-07-14; linux version
    Use Ctrl-D to exit, Ctrl-E for paste mode
    >>> from OmegaExpansion import RelayExp
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: no module named 'OmegaExpansion.RelayExp'
    >>> from OmegaExpansion import relayExp
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: no module named 'OmegaExpansion.relayExp'
    >>>
    

    So now its how to add the relayExp as well. I'm working through what you shared but in the context of the relayExp. I haven't figured this one out yet.

    Any ideas here?



  • @LightSwitch

    root@Omega-C592:~/OmegaHomeControl# opkg list | grep -i relay
    libonionrelayexp - 0.9-1
    pyRelayExp - 0.9-1
    relay-exp - 0.9-1



  • @LightSwitch :

    From these two:

    https://docs.onion.io/omega2-docs/relay-expansion.html
    https://docs.onion.io/omega2-docs/relay-expansion-python-module.html#relay-expansion-python-module

    it appears that RelayExp is a python2 module.

    Pls try if it works as advertised (under python2).

    Just need to invoke the the python prompt and do the import and then type in each statement one-by-one at the prompt. See if each stmt succeeds.

    We need to worry about incorporating it into the current environment only if it does...

    Thanks..



  • @tjoseph1

    root@Omega-C592:~# python --version
    Python 2.7.18
    root@Omega-C592:~# python
    Python 2.7.18 (default, Jul 14 2020, 21:51:14)
    [GCC 7.3.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.

    from OmegaExpansion import relayExp
    import time
    locals()
    {'builtins': <module 'builtin' (built-in)>, 'relayExp': <module 'OmegaExpansion.relayExp' from '/usr/lib/python2.7/OmegaExpansion/relayExp.so'>, 'package': None, 'time': <module 'time' from '/usr/lib/python2.7/lib-dynload/time.so'>, 'name': 'main', 'doc': None}

    Is this what you meant to do above? It seams like it works.

    I already have this entire setup running on the dash and all the sensors work and all the omegaexpansion modules as well. It just does not work when I run the micropython command.

    Can this too be sym linked?



  • @LightSwitch

    root@Omega-C592:~# python --version
    Python 2.7.18
    root@Omega-C592:~# python
    Python 2.7.18 (default, Jul 14 2020, 21:51:14)
    [GCC 7.3.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from OmegaExpansion import relayExp
    >>> import time
    >>> locals()
    {'__builtins__': <module '__builtin__' (built-in)>, 'relayExp': <module 'OmegaExpansion.relayExp' from '/usr/lib/python2.7/OmegaExpansion/relayExp.so'>, '__package__': None, 'time': <module 'time' from '/usr/lib/python2.7/lib-dynload/time.so'>, '__name__': '__main__', '__doc__': None}
    >>>
    


  • @LightSwitch :

    Even though the online docs provide examples based on python2, there are corresponding python3 packages available.

    root@Omega-745F:~# opkg list | grep -i omega | grep -i exp
    pyOmegaExpansion - 0.9-1 - Setup for OmegaExpansion Python Package (I guess this is python2)
    python3-omega-expansion - 0.9-1 - Setup for OmegaExpansion Python3 Package (python3)

    root@Omega-745F:~# opkg list | grep -i py | grep -i relay
    pyRelayExp - 0.9-1 - Python module to control the Onion Relay Expansion (this is python2)
    python3-relay-exp - 0.9-1 - Python3 module to control the Onion Relay Expansion (python3)

    As the docs say, the programs make use of the underlying i2c C libs. Onion programmers have created the python2/3 libs for both ADC/Relay Exp that can interact with the "base" C libs. Those are the above packages.

    I do not see any equivalent micropython packages in the repo. My best guess is that micropython Relay Exp is not an option, unless you create your own python packages using the C source of i2c.
    https://github.com/OnionIoT/i2c-exp-driver

    Here the basic howto:
    https://docs.micropython.org/en/latest/develop/cmodules.html#
    to create a C lib that can be called from micropython.

    Since you already have the required h/w docks, you can give it a try.. or stay with the python3 packages that Onion repos provide.

    Or request the Onion team to provide micropython packages for Relay Exp. The micropython port is not of much use unless Onion team extends the py lib support to the entire range of Docks as they have done in the case of py2 and py3.

    Is the ADC Exp working fine from micropython ? I can only import; but won't be able to create objects since I do not have ADC Exp.

    Thanks..



  • @tjoseph1 @LightSwitch Not sure if Onion will update this libraries since the relay expansion is discontinued:

    https://onion.io/discontinuing-3-expansion-and-a-kit/



  • @crispyoz :

    Yes. The chances of supporting a "discontinued" h/w is almost nil.

    If we consider py2, py3 and micropython are 3 different streams of py the libs have to be made available in all three. Many developers are using python, all 3 variants of it. May be there is a reason Onion didn't release the libs that work with micropython ?

    It can still be ordered, say from mouser.com (sparkfun make)
    https://www.mouser.com/ProductDetail/SparkFun/DEV-14444?qs=wd5RIQLrsJgP0vNuuZBr2Q%3D%3D

    A "HOWTO" to build the micropython modules would be helpful and appreciated very much. People do not have to spend hours/days knitting pieces of information scattered all over the Internet into a working procedure-set. And the sad part is, it not sure if if is ever going to work, until we see it working...

    While running the time.sleep(10) py script, py3 takes 2MB straight, and micropython takes about 100kB+.

    root@Omega-745F:~# free
    total used free shared buffers cached
    Mem: 124808 56120 68688 92 15988 18588

    root@Omega-745F:~# python3 sleep.py &

    root@Omega-745F:~# free
    total used free shared buffers cached
    Mem: 124808 58172 66636 92 15988 18588

    root@Omega-745F:~# python3 sleep.py &

    root@Omega-745F:~# free
    total used free shared buffers cached
    Mem: 124808 60280 64528 92 15988 18588

    root@Omega-745F:~# ps
    1989 root 5512 S python3 sleep.py
    1991 root 5512 S python3 sleep.py

    root@Omega-745F:~# free
    total used free shared buffers cached
    Mem: 124808 56536 68272 92 15988 18952

    root@Omega-745F:~# micropython sleep.py &

    root@Omega-745F:~# free
    total used free shared buffers cached
    Mem: 124808 56660 68148 92 15988 18952

    root@Omega-745F:~# ps
    1995 root 2600 S micropython sleep.py

    Thanks..



  • @tjoseph1 Why not just call the c library functions directly.



  • @crispyoz :

    Why not just call the c library functions directly.

    From python3/micropython, how to do that ?

    Thanks..



  • @tjoseph1 There are some docs/discussions for calling musl libc using micropython, just google it. Another approach would be to write a micropython specific c function that calls libc functionality.

    Just another reason to dislike python 🙂


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.