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.



  • I have some code up and running on an existing project for Omega2. I recently received the Dash and wanted to begin building the project with a GUI.

    I have run into several issues when using Dash, most of them I think I have figured out, one of them being that using the LVGL lib through micropython requires a few more dependancies mainly the micropython-lib.

    When I run the python script, I get the following issues.
    ...
    self.adc = AdcExp.AdcExp(address=0x48)
    ...

    ('station: ', 0)
    onion-i2c:: write issue for register 0x01, errno is 6: No such device or address
    Exception in thread Thread-1:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
      File "/usr/lib/python2.7/threading.py", line 754, in run
      File "/root/OmegaHomeControl/motion.py", line 30, in listen
        if self.adc.read_voltage(self.station) > self.threshold:
      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 >> 8) & 0xFF, config & 0xFF])
    IOError: I2C transaction failed.
    

    This code runs just fine when using the previous omega2 setup. It is only when I plug in the adc module to the dash that I get this issue.

    So code is working fine on existing omega2 with same adc. Then I move the adc over to dash and the same script will not run.



  • I would like to add the code as well.

    import time
    from OmegaExpansion import AdcExp
    import threading
    
    class Motion:
    
      def __init__(self, address=None, threshold=None, parent=None):
        print('********** Motion Module Starting **********');
    
        if address 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.address = address;
        self.threshold = threshold;
        self.adc = AdcExp.AdcExp(address=0x48)
        self.parent = parent;
        motionThread = threading.Thread(target=self.listen);
        motionThread.daemon = True;
        motionThread.start();
    
      def listen(self):
        while 1:
          if self.adc.read_voltage(self.address) > self.threshold:
            self.parent.motionOn();
          else:
            self.parent.motionOff();
          time.sleep(0.5);
    

    That's the code. self.address is 0 when failure occurs, this also happens for 1, 2, and 3 of the adcexp. It's like the dash does not recognize the AdcExp channels or perhaps even the AdcExp.

    My thought is that this is some library problem between the two devices. I do not have any import issues so I think the library is present. The one I test for says its there.

    There are several installed:
    python-adc-exp - 0.3-2
    adc-exp - 0.3-2



  • @LightSwitch :
    I do not have Dash nor ADC Exp. Still, going though various docs makes me believe that ADC Exp should work with Dash. As per:
    https://onion.io/omega2-dash-guide/

    "The Omega2 Dash is compatible with the existing ecosystem of plug-and-play Omega2 expansions."

    Please verify that i2c pins are configured for i2c (not for gpio), in the dash.

    root@Omega-745F:/tmp# omega2-ctrl gpiomux get
    Group i2c - [i2c] gpio (configured for i2c)
    Group i2c - i2c [gpio] (configured for gpio)

    If is is configure for gpio , change to i2c
    root@Omega-745F:/tmp# omega2-ctrl gpiomux set i2c i2c

    As per the docs:
    https://docs.onion.io/omega2-docs/using-adc-expansion.htm, ADC exp can have 0x48 or 0x49 addresses(settable).

    Please see if the i2cdetect reports ADC exp at either 0x48 or 0x49:

    root@Omega-745F:/tmp# i2cdetect 0
    WARNING! This program can confuse your I2C bus, cause data loss and worse!
    I will probe file /dev/i2c-0.
    I will probe address range 0x03-0x77.
    Continue? [Y/n] Y
    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --

    Since Omega2 has only one I2C, trying to access a bus other than 0 fails.
    root@Omega-745F:/tmp# i2cdetect 1
    Error: Could not open file /dev/i2c-1' or /dev/i2c/1': No such file or directory

    I have connected a device with address 0x27 to the I2C bus. But any compatible I2C device shall respond to the i2cdetect.

    From the opkg file listing adc-exp and python3-adc-exp install different files:

    root@Omega-745F:/tmp# opkg files adc-exp
    Package adc-exp (0.3-2) is installed on root and has the following files:
    /usr/bin/adc-exp
    root@Omega-745F:/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

    /usr/bin/adc-exp is a script that makes use of the various programs installed by i2c-tools. adc-exp can be tried as the next step.

    root@Omega-745F:/tmp# adc-exp -h shall provide various options.

    Thanks ..



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

    opkg files python3-adc-exp

    Ok, I went through the instructions provided. Here is what was displayed:

    root@Omega-C592:~# omega2-ctrl gpiomux get
    Group i2c - [i2c] gpio
    Group uart0 - [uart] gpio
    Group uart1 - [uart] gpio pwm01
    Group uart2 - [uart] gpio pwm23
    Group pwm0 - pwm [gpio]
    Group pwm1 - pwm [gpio]
    Group refclk - refclk [gpio]
    Group spi_s - spi_s [gpio] pwm01_uart2
    Group spi_cs1 - [spi_cs1] gpio refclk
    Group i2s - i2s [gpio] pcm
    Group ephy - ephy [gpio]
    Group wled - wled [gpio]

    root@Omega-C592:~# i2cdetect 0
    WARNING! This program can confuse your I2C bus, cause data loss and worse!
    I will probe file /dev/i2c-0.
    I will probe address range 0x03-0x77.
    Continue? [Y/n] Y
    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --
    root@Omega-C592:~# i2cdetect 1
    Error: Could not open file /dev/i2c-1' or /dev/i2c/1': No such file or directory

    root@Omega-C592:~# opkg files adc-exp
    Package adc-exp (0.3-2) is installed on root and has the following files:
    /usr/bin/adc-exp
    root@Omega-C592:~# 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

    It appears to be present for address 48, and that is also the address I am using the code on both Omega units, the working one (which is the non dash) and the non working one (which is the dash)

    Additional info commands

    root@Omega-C592:~/OmegaHomeControl# adc-exp -h
    ERROR: Expecting channel input

    Usage: adc-exp [options] <channel>

    FUNCTIONALITY:
    Onion ADC Expansion: Read voltage value of an analog input channel
    valid channel: 0-3, or 'all'

    OPTIONS:
    -s <0|1> specify address switch value
    -j json output
    -h help: show this prompt

    root@Omega-C592:~/OmegaHomeControl# adc-exp 0
    /usr/bin/adc-exp: line 208: /usr/bin/sleep: not found
    A0 Voltage: 0 V
    root@Omega-C592:~/OmegaHomeControl# adc-exp 1
    Error: Write failed
    /usr/bin/adc-exp: line 208: /usr/bin/sleep: not found
    A1 Voltage: 0 V
    root@Omega-C592:~/OmegaHomeControl# adc-exp 2
    Error: Write failed
    /usr/bin/adc-exp: line 208: /usr/bin/sleep: not found
    A2 Voltage: 0 V
    root@Omega-C592:~/OmegaHomeControl# adc-exp 3
    Error: Write failed
    /usr/bin/adc-exp: line 208: /usr/bin/sleep: not found
    A3 Voltage: 0 V

    There is no /usr/bin/sleep file.

    so I created a test.py file that only uses the adcExp module.

    from OmegaExpansion import AdcExp

    class Test:
    def init(self):
    self.adc = AdcExp.AdcExp(address=0x48);
    print(self.adc.read_voltage(0));

    Test();

    At first I had import time at the top, and I had the same error. I removed import time, and now I do get the voltage value form the adcExp. So the error from above where /usr/bin/sleep not present issue is of course related to the import time.

    I would like to use the sleep function of the time module as well, so not this troubleshooting why there is no time module present.

    Any help on how to make sure I have access to the time module both in regular python but as well micropython which the dash is using for the GUI software.

    If I isolate in the test.py file just import time, and then I create a class like so
    import time
    from OmegaExpansion import AdcExp

    class Test:
    def init(self):
    print(time.time());
    # self.adc = AdcExp.AdcExp(address=0x48);root@Omega-C592:~# python test.py
    1601145313.58
    # print(self.adc.read_voltage(0));

    Test();

    The time is printed out like it should.

    root@Omega-C592:~# python test.py
    1601145313.58


    And if i just leave the print commented out, all is well.

    import time
    from OmegaExpansion import AdcExp

    class Test:
    def init(self):
    print(time.time());
    self.adc = AdcExp.AdcExp(address=0x48);
    # print(self.adc.read_voltage(0));

    Test();

    This works as well, no bug and time is printed out.

    However, when I try to read_voltage(0) I get the error from above:

    root@Omega-C592:~# python test.py
    1601145446.04
    onion-i2c:: write issue for register 0x01, errno is 6: No such device or address
    Traceback (most recent call last):
    File "test.py", line 10, in <module>
    Test();
    File "test.py", line 8, in init
    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.

    so time works as expected, the adcExp works as expected, but when combine together is it breaking on the /usr/bin/sleep file

    I just went to /usr/bin/ and created a blank sleep.py file, cuz why not.

    The error comes back even when I am not importing anything regarding the time module. Is there some sleep module that I need to import?

    I went over to the working omega2 project I have and found that there is a file called sleep and it has contents in it. I can probably copy the file over, but it gets me thinking that the opkg should in some way do this. So I am missing a step here somewhere.

    Any ideas on the getting the sleep file present in /usr/bin/sleep



  • Found the issue is that there is a sleep binary in /usr/bin/ on my working machine, that is NOT on the dash machine. I'm not sure how it gets there as I cannot find a package called sleep available for download.

    I added some comments here but I don't think they were saved as I missed the edit time.

    So I'll say them here in this reply.

    I created a test.py file where I can import time and use it without the adcExp, and i can use the adcExp if I don't import time as well. It is when I try to use them together that it breaks due to the lack of a sleep file or folder in the usr/bin.

    I tried to copy over the binary but I have been able to do it yet. In my code I am using the import time
    and time.sleep() method.

    I need to use this, so how do I get the package required that installs the sleep package that is avaialbe on one of my machines, but not the dash?



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

    opkg files python3-adc-exp

    Ok, I went through the instructions provided. Here is what was displayed:

    root@Omega-C592:~# omega2-ctrl gpiomux get
    Group i2c - [i2c] gpio
    Group uart0 - [uart] gpio
    Group uart1 - [uart] gpio pwm01
    Group uart2 - [uart] gpio pwm23
    Group pwm0 - pwm [gpio]
    Group pwm1 - pwm [gpio]
    Group refclk - refclk [gpio]
    Group spi_s - spi_s [gpio] pwm01_uart2
    Group spi_cs1 - [spi_cs1] gpio refclk
    Group i2s - i2s [gpio] pcm
    Group ephy - ephy [gpio]
    Group wled - wled [gpio]

    root@Omega-C592:~# i2cdetect 0
    WARNING! This program can confuse your I2C bus, cause data loss and worse!
    I will probe file /dev/i2c-0.
    I will probe address range 0x03-0x77.
    Continue? [Y/n] Y
    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --
    root@Omega-C592:~# i2cdetect 1
    Error: Could not open file /dev/i2c-1' or /dev/i2c/1': No such file or directory

    root@Omega-C592:~# opkg files adc-exp
    Package adc-exp (0.3-2) is installed on root and has the following files:
    /usr/bin/adc-exp
    root@Omega-C592:~# 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

    It appears to be present for address 48, and that is also the address I am using the code on both Omega units, the working one (which is the non dash) and the non working one (which is the dash)

    Additional info commands

    root@Omega-C592:~/OmegaHomeControl# adc-exp -h
    ERROR: Expecting channel input

    Usage: adc-exp [options] <channel>

    FUNCTIONALITY:
    Onion ADC Expansion: Read voltage value of an analog input channel
    valid channel: 0-3, or 'all'

    OPTIONS:
    -s <0|1> specify address switch value
    -j json output
    -h help: show this prompt

    root@Omega-C592:~/OmegaHomeControl# adc-exp 0
    /usr/bin/adc-exp: line 208: /usr/bin/sleep: not found
    A0 Voltage: 0 V
    root@Omega-C592:~/OmegaHomeControl# adc-exp 1
    Error: Write failed
    /usr/bin/adc-exp: line 208: /usr/bin/sleep: not found
    A1 Voltage: 0 V
    root@Omega-C592:~/OmegaHomeControl# adc-exp 2
    Error: Write failed
    /usr/bin/adc-exp: line 208: /usr/bin/sleep: not found
    A2 Voltage: 0 V
    root@Omega-C592:~/OmegaHomeControl# adc-exp 3
    Error: Write failed
    /usr/bin/adc-exp: line 208: /usr/bin/sleep: not found
    A3 Voltage: 0 V

    There is no /usr/bin/sleep file.

    so I created a test.py file that only uses the adcExp module.

    from OmegaExpansion import AdcExp

    class Test:
    def init(self):
    self.adc = AdcExp.AdcExp(address=0x48);
    print(self.adc.read_voltage(0));

    Test();

    At first I had import time at the top, and I had the same error. I removed import time, and now I do get the voltage value form the adcExp. So the error from above where /usr/bin/sleep not present issue is of course related to the import time.

    I would like to use the sleep function of the time module as well, so not this troubleshooting why there is no time module present.

    Any help on how to make sure I have access to the time module both in regular python but as well micropython which the dash is using for the GUI software.

    If I isolate in the test.py file just import time, and then I create a class like so
    import time
    from OmegaExpansion import AdcExp

    class Test:
    def init(self):
    print(time.time());
    # self.adc = AdcExp.AdcExp(address=0x48);root@Omega-C592:~# python test.py
    1601145313.58
    # print(self.adc.read_voltage(0));

    Test();

    The time is printed out like it should.

    root@Omega-C592:~# python test.py
    1601145313.58


    And if i just leave the print commented out, all is well.

    import time
    from OmegaExpansion import AdcExp

    class Test:
    def init(self):
    print(time.time());
    self.adc = AdcExp.AdcExp(address=0x48);
    # print(self.adc.read_voltage(0));

    Test();

    This works as well, no bug and time is printed out.

    However, when I try to read_voltage(0) I get the error from above:

    root@Omega-C592:~# python test.py
    1601145446.04
    onion-i2c:: write issue for register 0x01, errno is 6: No such device or address
    Traceback (most recent call last):
    File "test.py", line 10, in <module>
    Test();
    File "test.py", line 8, in init
    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.

    so time works as expected, the adcExp works as expected, but when combine together is it breaking on the /usr/bin/sleep file

    I just went to /usr/bin/ and created a blank sleep.py file, cuz why not.

    The error comes back even when I am not importing anything regarding the time module. Is there some sleep module that I need to import?

    I went over to the working omega2 project I have and found that there is a file called sleep and it has contents in it. I can probably copy the file over, but it gets me thinking that the opkg should in some way do this. So I am missing a step here somewhere.

    Any ideas on the getting the sleep file present in /usr/bin/sleep

    [ fwtool ots tail
    [[ getrandom oupgrade tee
    adc-exp gpioctl passwd telnet
    awk head pgrep test
    base64 hexdump printf time
    basename id python top
    bc iwinfo python2 tr
    bunzip2 jshn python2.7 traceroute
    bzcat jsonfilter python3 traceroute6
    clear killall python3.6 uniq
    cmp ldd readlink updateHostname
    console-install-tool less reset uptime
    crontab logger rsync urldecode
    cut md5sum scp urlencode
    dbclient mkfifo seq usign
    dirname mosquitto_passwd sha256sum wc
    dropbearkey mosquitto_pub signify wget
    du mosquitto_sub sleep wget-ssl
    env nc sort which
    expled node-red-install-tool spi-config wifisetup
    expr nslookup spi-pipe xargs
    find omega2-ctrl ssh yes
    free onion strings



  • @LightSwitch :
    <<
    40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
    <<
    So the ADC chip is reporting itself at address 0x48; Good.

    <<
    # print(self.adc.read_voltage(0));
    <<

    So far, we know that the ADC "sits well" on the Dash and reports itself at 0x48. Next step is accessing the channels (0-3) on the ADC using /usr/bin/adc-exp

    As per:
    https://docs.onion.io/omega2-docs/using-adc-expansion.html#using-adc-expansion
    +++
    For example, if we want to read channel 0:

    adc-exp 0
    Will return something like

    A0 Voltage: 2.12 V
    +++

    If the reader is connected to channel 0 of ADC (btw, the top 3 images are wrong, they show A0 & A1 twice, not A2 or A3, where as the photograph(the 5th), correctly shows A0, A1, A2 & A3), issuing "adc-exp 0", it would reply:

    A0 Voltage: 2.12 V (or some valid value)

    Are you there yet? You would need to issue "adc-exp 3" if your sensor is connected to ADC channel 3.
    Please read below, about correcting the /usr/bin/sleep, required for /usr/bin/adc-exp:

    <<
    root@Omega-C592:~/OmegaHomeControl# adc-exp 0
    /usr/bin/adc-exp: line 208: /usr/bin/sleep: not found
    <<

    /usr/bin/acd-exp has /usr/bin/sleep declared at line:85 as:

    84: # wait for the conversion delay before reading the conversion register
    85: /usr/bin/sleep $deviceConversionDelay

    It doesn't seem that /usr/bin/sleep is present in Omega2+ either (FW b233)

    root@Omega-745F:~# ls -l /usr/bin/sleep
    ls: /usr/bin/sleep: No such file or directory

    /bin/sleep is present though, which is a link to /usr/bin/gnu-sleep

    root@Omega-745F:~# which sleep
    /bin/sleep

    root@Omega-745F:~# ls -l /bin/sleep
    lrwxrwxrwx 1 root root 18 Sep 21 04:11 /bin/sleep -> /usr/bin/gnu-sleep

    root@Omega-745F:~# opkg search /usr/bin/gnu-sleep
    coreutils-sleep - 8.23-4

    You can modify line 85 of the /usr/bin/adc-exp script to point to /bin/sleep (instead of /usr/bin/sleep)
    or create a link to gnu-sleep as sleep in /usr/bin

    root@Omega-745F:~# ln -s /usr/bin/gnu-sleep /usr/bin/sleep (preferred)

    <<
    I created a test.py file that only uses the adcExp module.
    <<

    I don't have ADC-Exp, so I can't test any script that is pointing to ADC-Exp.

    <<
    So the error from above where /usr/bin/sleep not present issue is of course related to the import time
    <<

    I am positive that the time implementation of python is not dependent on any Linux executable that we see under /bin, /usr/bin etc.

    If:
    root@Omega-745F:~# python3
    Python 3.6.11 (default, Jul 14 2020, 21:51:14)
    [GCC 7.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import time
    >>> time.sleep(2) (should return the >>> prompt after 2s)
    >>>
    >>> exit()
    root@Omega-745F:~#
    then, time in python3 works fine.

    Once issuing "adc-exp [0-3]" returns something like "A[0-3] Voltage: 2.12 V", we know it works, and we can try implementing it in python.

    Thanks..



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

    adc-exp 0

    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

    This is the error I’m getting when running the original script. Just adding here again. I still get this.
    onion-i2c:: write issue for register 0x01, errno is 6: No such device or address
    Exception in thread Thread-1:
    Traceback (most recent call last):
    File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    File "/usr/lib/python2.7/threading.py", line 754, in run
    File "/root/OmegaHomeControl/motion.py", line 30, in listen
    if self.adc.read_voltage(self.station) > self.threshold:
    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.

    I get the same results in my test file. I an read 0, but not 1, 2, or 3.



  • 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.675

    Setting 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 V

    I 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?



  • @LightSwitch :

    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 an i2cdetect -y 0 command on your Omega2 DASH board without an Onion ADC Expansion board.


    @Lazar-Demin

    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

    16298622-6dfa-468c-96cd-efd71658b84a-image.png

    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.



  • @György-Farkas

    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: -- -- -- -- -- -- -- --


Log in to reply
 

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