Omega2 Dash ADC EXP (Python) not connecting.
-
When I run the script, and change the address in the script (not from the command line), I noted that at first I would get a value (voltage) but eventually it would fail.
0 would work, 1 did not, two worked once, and three worked through several cycles like below. 'station' first number is the address of the adc. the (-num) denotes the actual read_voltage value. This was in a while True: loop with a one second delay. So after three seconds, the error appeared for adc channel 3.
('********** Motion Module Starting **********', 3, 3)
('station: ', 3, 3)
-0.675Setting RELAY0 to OFF
('station: ', 3, 3)
-0.675
Setting RELAY0 to OFF
('station: ', 3, 3)
-0.771
Setting RELAY0 to OFF
('station: ', 3, 3)
onion-i2c:: write issue for register 0x01, errno is 6: No such device or address
Traceback (most recent call last):
File "switch.py", line 54, in <module>
Switch()
File "switch.py", line 15, in init
self.motion = Motion(3, 3, self);
File "/root/OmegaHomeControl/motion.py", line 27, in init
self.listen();
File "/root/OmegaHomeControl/motion.py", line 32, in listen
print(self.adc.read_voltage(0));
File "/usr/lib/python2.7/OmegaExpansion/AdcExp.py", line 230, in read_voltage
return self._convert_to_voltage(self.read_adc(channel, gain, data_rate), gain)
File "/usr/lib/python2.7/OmegaExpansion/AdcExp.py", line 221, in read_adc
return self._read(channel + 0x04, gain, data_rate, ADS1x15_CONFIG_MODE_SINGLE)
File "/usr/lib/python2.7/OmegaExpansion/AdcExp.py", line 149, in _read
self._device.writeBytes(self._devAddr, ADS1x15_POINTER_CONFIG, [(config >> & 0xFF, config & 0xFF])
IOError: I2C transaction failed.
-
@LightSwitch :
Reading the docs, I understand that the ADC-Exp uses TI ADS1115 A/D converter. It offers 4 analog "ports" where sensors can be connected. In your specific setup, the I2C side of the ADC-Exp has I2C address 0x48. We have verified that using "i2cdetect" tool. The remaining part is the Analog side of the ADC where you have connected a sensor (to measure the voltage?)<<
root@Omega-C592:~/OmegaHomeControl# adc-exp 0
A0 Voltage: -0.77 V
root@Omega-C592:~/OmegaHomeControl# adc-exp 1
Error: Write failed
A1 Voltage: -0.77 V
root@Omega-C592:~/OmegaHomeControl# adc-exp 2
Error: Write failed
A2 Voltage: -0.77 V
root@Omega-C592:~/OmegaHomeControl# adc-exp 3
Error: Write failed
A3 Voltage: -0.77 V
<<From the above, I assume that the sensor is connected to port A0, since it doesn't give "Error: Write failed"
<<
I noted that at first I would get a value (voltage) but eventually it would fail.
<<Let us worry about the python script later..
When you connect the ADC-Exp to your other Omega2 (Not the Dash), and if you execute "adc-exp 0" after meeting all that we (such as taking care of /usr/bin/sleep) discussed, what does it show ?
Is the reading correct ?
If not, what reading is the expected ?
Did you check the reading with a voltmeter?
What make/model of sensor is used?Thanks..
-
Other working project, the adc-exp same code working fine. I don't have to do the sleep file link, the file is there.
The adc works, the sensors work and turn off and on relays depending on the sensor logic. if I run the adc-exp # I get
root@Omega-B437:~/projects# adc-exp 0
A0 Voltage: 0 V
root@Omega-B437:~/projects# adc-exp 1
A1 Voltage: 0.79 V
root@Omega-B437:~/projects# adc-exp 2
A2 Voltage: 0.58 V
root@Omega-B437:~/projects# adc-exp 3
A3 Voltage: 0.76 VI had three sensors connected on ports 0, 1, and 3. port 2 has nothing on the adc.
I have a motion sensor, temp sensor, and photo resistor. They all work and toggle the correct relays on my main project where I am not using a dash.Then I power down and change the header plug to the dash, and we get what I have described.
I also did the sleep link like you mentioned, and now I can call time.sleep(2) so that works now. Thanks.
-
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.