(very simple) Example for UniPi direct via PIGPIO

it5l
Posts: 2
Joined: Thu Apr 30, 2015 1:10 pm

(very simple) Example for UniPi direct via PIGPIO

Postby it5l » Thu Apr 30, 2015 2:02 pm

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 ?

Code: Select all

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()
it5l
Posts: 2
Joined: Thu Apr 30, 2015 1:10 pm

Re: (very simple) Example for UniPi direct via PIGPIO

Postby it5l » Fri May 01, 2015 10:04 am

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

Code: Select all

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!
tomas_hora
Site Admin
Posts: 298
Joined: Wed Oct 29, 2014 9:56 am

Re: (very simple) Example for UniPi direct via PIGPIO

Postby tomas_hora » Mon May 04, 2015 11:28 am

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

Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 1 guest