Omega2 Dash ADC EXP (Python) not connecting.
-
Just out of curiosity, I changed the switch on the adc to 0x49 and I changed the code for the motion sensor to 0x49 and the sensor now triggers the relay! So perhaps there is something about 0x48 and 0x49 on the dash software?
Again, the 0x48 switch and code work on omega2+ but not on dash.
On the dash, the 0x49 works. Here is the motion sensor code for reference.from OmegaExpansion import AdcExp import time import threading class Motion: def __init__(self, station=None, threshold=None, parent=None): print('********** Motion Module Starting **********', station, threshold); if station is None: raise ValueError("An Address must be passed into the constructor argument 1."); if threshold is None: raise ValueError("A Threshold must be passed into the constructor argument 2."); if parent is None: raise ValueError("A Parent self must be passed into the constructor argument 3." self.station = station; self.threshold = threshold; self.adc = AdcExp.AdcExp(address=0x49); self.parent = parent; motionThread = threading.Thread(target=self.listen); motionThread.daemon = True; motionThread.start(); self.listen(); def listen(self): while 1: print('station: ', self.station, self.threshold); print(self.adc.read_voltage(0)); if self.adc.read_voltage(self.station) > self.threshold: self.parent.motionOn(); else: self.parent.motionOff(); time.sleep(1);
and here is the parent switch.py file that calls it.
import time from relays import Relays from motion import Motion from light import Light from temp import Temp class Switch: def __init__(self): self.motionDetected = False; self.relay = Relays(7); self.relay.setAllOff(); self.motion = Motion(0, 3, self); # self.light = Light(3, 1000, self); # self.temp = Temp(1, 85, self); self.start = time.time(); while True: print('||||| SWITCH ACTIVE |||||'); time.sleep(10); self.status = 0; def motionOn(self): self.motionDetected = True; self.relay.set(0, 1); def motionOff(self): self.motionDetected = False; self.relay.set(0, 0); def tempOn(self): self.relay.set(1, 1); def tempOff(self): self.relay.set(1, 0); def testOn(self): print('testOn'); self.status = 1 - self.relay.read(0); self.relay.set(0, self.status); def lightOn(self): if self.motionDetected and self.relay.read(0) == 0: self.relay.set(0, 1); def lightOff(self): if not self.motionDetected and self.relay.read(0) == 1: self.relay.set(0, 0); Switch()
It would be nice to know the diff. I have 4 Dash, so I can try this on the others as well, but it will take time before I can get to them.
For now, I'll focus on just getting one to work.
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
Unless I can use it with just python?
-
Excellent. We should have tried the 0x49 setting. Nice to know that you were be able to sort it out. As per:
https://docs.onion.io/omega2-docs/using-adc-expansion.html#using-adc-expansion : the command
adc-exp 0 works for ADC-Ext @ 0x48 address. For 0x49, the format is:
"adc-exp -s <switch value> <channel>"
or
adc-exp -s 0x49 3, (for a sensor connected to ADC-Exp port 3).<<
It would be nice to know the diff
<<
I don't know. The I2C, in theory should work fine, unless you have a 2nd device with the same address (0x48 in our case) in the I2C bus along with with ADC-Exp configured for 0x48. You can check that by running "i2cdetect". As per your current config, the ADC-Exp should report 0x49, while the "second device" shall report 0x48, if there is one.<<
I can try this on the others as well
<<
That would be great if you could do that. This thread could be of use to many (future) Dash users.<<
I can use the Micropython&LVGL
<<
I read from one of the posts of @crispyoz that Micropython is preferred. I am on the C-side, though.Anyways, pls post your findings, so that it would be useful everyone. Always remember to use the tools (i2c.., adc-exp etc.) before we focus on python programs. python would work only after we solve the issues found by running the tools.
Thanks..
-
@LightSwitch @crispyoz
Please let us know the output of ani2cdetect -y 0
command on your Omega2 DASH board without an Onion ADC Expansion board.
ADC Expansion The ADS1115 analog-to-digital controller chip has one address pin (ADDR) that configures the I2C address of the device. On the Onion's board this pin can be connected to GND or VDD with the Address Switch. ADS1115 I2C device address A6 A5 A4 A3 A2 A1 A0 1 0 0 1 0 0 ? 1 0 0 1 0 0 0 0x48 (ADDR = GND) 1 0 0 1 0 0 1 0x49 (ADDR = VDD) # ----------------------------------------------------------------------------------------------------------------------------------------- Omega2 DASH The XPT7603 resistive touch screen controller chip (MSOP10 package) has one address pin (A0) that configures the I2C address of the device. According to Onion's schematic this pin is NC (??? - so the schematic may be wrong). XPT7603 I2C device address (MSOP10 package) A6 A5 A4 A3 A2 A1 A0 1 0 0 1 0 0 ? 1 0 0 1 0 0 0 0x48 (A0 = GND) 1 0 0 1 0 0 1 0x49 (A0 = VDD)
If the above is correct users should be warned a possible I2C address conflict.
-
@György-Farkas Not sure how I got dragged into this but here is the output on one of my Dash
PS I don't have an ADC expansion.
-
@crispyoz Because I know that you have an Omega2 DASH board.
Thank you.
-
@György-Farkas Are you monitoring me ?
-
@crispyoz
Omega2 Dash now available! You wrote proudly:I was lucky enough to join the Beta for this product.
-
@György-Farkas I wrote "gratefully" because it was a timely release for something I had been working on for a while and Zheng administered the Beta very attentively and professionally.
You know I'm a stickler for nomenclature.
-
With no ADC or any board plugged into the header,
when I run...root@Omega-C592:~# i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
-
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.pyThis 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'
-
@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/packagesroot@Omega-745F:/tmp# opkg files micropython
Package micropython (1.9.2-1f78e7a43130acfa4bedf16c1007a1b0f37c75c3-1) is installed on root and has the following files:
/usr/bin/micropythonThere 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..
-
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-1pyOmegaExpansion - 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 ExpansionWe 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.pyroot@Omega-745F:/tmp/tmp# opkg list-installed |grep adc-exp
adc-exp - 0.3-2
python3-adc-exp - 0.3-2root@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/OmegaExpansionroot@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.htmlEvery 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..
-
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?
-
root@Omega-C592:~/OmegaHomeControl# opkg list | grep -i relay
libonionrelayexp - 0.9-1
pyRelayExp - 0.9-1
relay-exp - 0.9-1