(very simple) Example for UniPi direct via PIGPIO



  • Hi all,

    I am experimenting with the UniPi and I have to say, it is indeed very easy with the evok-api.
    Within minutes was the board installed, the evok-api build and the webinterface running!

    One small comment about the install script:
    use with the "sudo apt-get" and the "sudo pip" the -E option of sudo. This way the script also
    will work in a network with a proxy. (if the proxy env is set of course)

    But I need a little help with my next experiment:
    I want to "skip" the evok-api and try to use python and the PIGPIO lib to read the input
    and switch the relay direct. I keep using the PIGPIO Deamon which came wit the install.
    And also I import the pigpio.py which came with the evok-api.

    My bigest problem is that I do not fuly understand the I2C Bus principals with the UniPi
    And that the evok-api is compleetly open, is fantastic! But I could not extract the complete
    code for a very simple proof of concept.

    So can somebody help me and post a minimal block of code for reading a Digital Input
    and switch one of the relays ?

    import pigpio
    import time
    
    def main():
       i2cbus = 1
       address = 0x20
    
       pi = pigpio.pi()
       handle = pi.i2c_open(i2cbus, address, 0)
    
       > and here I get stock <
    
       pi.i2c_close(handle)
       pi.stop()
    
    if __name__ == '__main__':
        main()
    
    


  • Hi all,

    I am experimenting with the UniPi and I have to say, it is indeed very easy with the evok-api.
    Within minutes was the board installed, the evok-api build and the webinterface running!

    One small comment about the install script:
    use with the "sudo apt-get" and the "sudo pip" the -E option of sudo. This way the script also
    will work in a network with a proxy. (if the proxy env is set of course)

    But I need a little help with my next experiment:
    I want to "skip" the evok-api and try to use python and the PIGPIO lib to read the input
    and switch the relay direct. I keep using the PIGPIO Deamon which came wit the install.
    And also I import the pigpio.py which came with the evok-api.

    My bigest problem is that I do not fuly understand the I2C Bus principals with the UniPi
    And that the evok-api is compleetly open, is fantastic! But I could not extract the complete
    code for a very simple proof of concept.

    So can somebody help me and post a minimal block of code for reading a Digital Input
    and switch one of the relays ?

    import pigpio
    import time
    
    def main():
       i2cbus = 1
       address = 0x20
    
       pi = pigpio.pi()
       handle = pi.i2c_open(i2cbus, address, 0)
    
       > and here I get stock <
    
       pi.i2c_close(handle)
       pi.stop()
    
    if __name__ == '__main__':
        main()
    
    


  • A new day, a big cup of coffee and a smart collega (mh)…
    ...and we solved one part of the question:

    import pigpio
    import time
    
    def main():
        i2cbus = 1
        address = 0x20
    
        pi = pigpio.pi()
        handle = pi.i2c_open(i2cbus, address, 0)
        print('status: ' + str(pi.i2c_read_byte_data(handle, 9)))
    
        pi.i2c_write_byte_data(handle, 9, 0)
        print('status: ' + str(pi.i2c_read_byte_data(handle, 9)))
        time.sleep(2)
    
        pi.i2c_write_byte_data(handle, 9, 15)
        print('status: ' + str(pi.i2c_read_byte_data(handle, 9)))
        time.sleep(2)
    
        pi.i2c_write_byte_data(handle, 9, 255)
        print('status: ' + str(pi.i2c_read_byte_data(handle, 9)))
        time.sleep(2)
    
        pi.i2c_write_byte_data(handle, 9, 0)
        print('status: ' + str(pi.i2c_read_byte_data(handle, 9)))
    
        pi.i2c_close(handle)
        pi.stop()
    
    if __name__ == '__main__':
        main()
    
    

    Any comments ?
    Please reply!



  • Hello,

    nice job.

    The digital input is not difficult once you have this done. Just do not forget to set the PULL-UP resistor on each GPIO - the list of the GPIOs can be found in the documentation.

    See unipig.py file line 646

    Keep me updated with your progress