bus1 = IoPi(i2c_bus, 0x20) # bus 1 will be inputs
bus2 = IoPi(i2c_bus, 0x21) # bus 2 will be outputs

# Each bus is divided up two 8 bit ports.  Port 0 controls pins 1 to 8, Port 1 controls pins 9 to 16.
# We will read the inputs on pin 1 of bus 1 so set port 0 to be inputs and
# enable the internal pull-up resistors
bus1.set_port_direction(0, 0xFF)
bus1.set_port_pullups(0, 0xFF)

# We will write to the output pin 1 on bus 2 so set port 0 to be outputs and
# turn off the pins on port 0
bus2.set_port_direction(0, 0x00)
bus2.write_port(0, 0x00)

while True:


    # read pin 1 on bus 1.  If pin 1 is high set the output on bus 2 pin 1 to high, otherwise set it to low.
    # connect pin 1 on bus 1 to ground to see the output on bus 2 pin 1 change state.
    if (bus1.read_pin(1) == 1):
    
        bus2.write_pin(1, 1)
    else:
        bus2.write_pin(1, 0)
                             
   

    # wait 0.1 seconds before reading the pins again
    time.sleep(0.1)
i2c_bus = i2c_helper.get_smbus()

# create two instances of the IoPi class called bus1 and bus2 and set the default i2c addresses

bus1 = IoPi(i2c_bus, 0x20)  # bus 1 will be inputs
bus2 = IoPi(i2c_bus, 0x21)  # bus 2 will be outputs

# Each bus is divided up two 8 bit ports.  Port 0 controls pins 1 to 8, Port 1 controls pins 9 to 16.
# We will read the inputs on pin 1 of bus 1 so set port 0 to be inputs and
# enable the internal pull-up resistors
bus1.set_port_direction(0, 0xFF)
bus1.set_port_pullups(0, 0xFF)

# We will write to the output pin 1 on bus 2 so set port 0 to be outputs and
# turn off the pins on port 0
bus2.set_port_direction(0, 0x00)
bus2.write_port(0, 0x00)

while True:

    # read pin 1 on bus 1.  If pin 1 is high set the output on bus 2 pin 1 to high, otherwise set it to low.
    # connect pin 1 on bus 1 to ground to see the output on bus 2 pin 1 change state.
    if (bus1.read_pin(1) == 1):

        bus2.write_pin(1, 1)
    else:
        bus2.write_pin(1, 0)

    # wait 0.1 seconds before reading the pins again
    time.sleep(0.1)
Initialise the IOPi device using the default addresses, you will need to
change the addresses if you have changed the jumpers on the IO Pi
"""
i2c_helper = ABEHelpers()
i2c_bus = i2c_helper.get_smbus()

bus = IoPi(i2c_bus, 0x20)

# We will read the inputs 1 to 8 from bus 2 so set port 0 to be inputs and
# enable the internal pull-up resistors
bus.set_port_direction(0, 0xFF)
bus.set_port_pullups(0, 0xFF)

while True:
    # clear the console
    os.system("clear")

    # read the pins 1 to 8 and print the results
    print "Pin 1: " + str(bus.read_pin(1))
    print "Pin 2: " + str(bus.read_pin(2))
    print "Pin 3: " + str(bus.read_pin(3))
    print "Pin 4: " + str(bus.read_pin(4))
    print "Pin 5: " + str(bus.read_pin(5))
    print "Pin 6: " + str(bus.read_pin(6))
    print "Pin 7: " + str(bus.read_pin(7))
    print "Pin 8: " + str(bus.read_pin(8))

    # wait 0.5 seconds before reading the pins again
    time.sleep(0.1)
Exemple #4
0
    PinNextSend = {}
    TempoPinHIGH = {}
    TempoPinLOW = {}
    Status_pins = {}
    Status_INPUTS = {}
    swtch = {}
    exit = 0
    SetAllLOW = 0
    SetAllHIGH = 0
    SetAllSWITCH = 0
    SetAllPulseLOW = 0
    SetAllPulseHIGH = 0
    pinStr = ''
    for i in range(0, 16):
        bus.set_pin_direction(i + 1, 1)
        input = bus.read_pin(i + 1)
        Status_INPUTS[i] = input
        pinStr += '&IN_' + str(i) + '=' + str(input)
        CounterPinValue[i] = 0
        PinNextSend[i] = 0
        TempoPinHIGH[i] = 0
        TempoPinLOW[i] = 0
        swtch[i] = 0
        Status_pins[i] = '.'

    # Envoi de l'etats des inputs au boot
    if pinStr != '':
        SimpleSend(pinStr)

    threadLock = threading.Lock()
    threads = []
i2c_bus = i2c_helper.get_smbus()

# create two instances of the IoPi class called bus1 and bus2 and set the default i2c addresses

bus1 = IoPi(i2c_bus, 0x20)  # bus 1 will be inputs
bus2 = IoPi(i2c_bus, 0x21)  # bus 2 will be outputs

# Each bus is divided up two 8 bit ports.  Port 0 controls pins 1 to 8, Port 1 controls pins 9 to 16.
# We will read the inputs on pin 1 of bus 1 so set port 0 to be inputs and
# enable the internal pull-up resistors
bus1.set_port_direction(0, 0xFF)
bus1.set_port_pullups(0, 0xFF)

# We will write to the output pin 1 on bus 2 so set port 0 to be outputs and
# turn off the pins on port 0
bus2.set_port_direction(0, 0x00)
bus2.write_port(0, 0x00)

while True:

    # read pin 1 on bus 1.  If pin 1 is high set the output on bus 2 pin 1 to high, otherwise set it to low.
    # connect pin 1 on bus 1 to ground to see the output on bus 2 pin 1 change state.
    if bus1.read_pin(1) == 1:

        bus2.write_pin(1, 1)
    else:
        bus2.write_pin(1, 0)

    # wait 0.1 seconds before reading the pins again
    time.sleep(0.1)
Exemple #6
0
This example uses the write_pin and writePort methods to switch pin 1 on
and off on the IO Pi.
"""
from ABE_helpers import ABEHelpers
from ABE_IoPi import IoPi
import time

i2c_helper = ABEHelpers()
i2c_bus = i2c_helper.get_smbus()

bus = IoPi(i2c_bus, 0x20)

bus.set_pin_direction(1, 1)  # set pin 1 as an input

bus.set_pin_direction(8, 0)  # set pin 8 as an output

bus.write_pin(8, 0)  # turn off pin 8

bus.set_pin_pullup(1, 1)  # enable the internal pull-up resistor on pin 1

bus.invert_pin(1, 1)  # invert pin 1 so a button press will register as 1

while True:

    if bus.read_pin(1) == 1:  # check to see if the button is pressed
        print('button pressed')  # print a message to the screen
        bus.write_pin(8, 1)  # turn on the led on pin 8
        time.sleep(2)  # wait 2 seconds
    else:
        bus.write_pin(8, 0)  # turn off the led on pin 8
Initialise the IOPi device using the default addresses, you will need to
change the addresses if you have changed the jumpers on the IO Pi
"""
i2c_helper = ABEHelpers()
i2c_bus = i2c_helper.get_smbus()

bus = IoPi(i2c_bus, 0x20)

# We will read the inputs 1 to 8 from bus 2 so set port 0 to be inputs and
# enable the internal pull-up resistors
bus.set_port_direction(0, 0xFF)
bus.set_port_pullups(0, 0xFF)

while True:
    # clear the console
    os.system('clear')

    # read the pins 1 to 8 and print the results
    print ('Pin 1: ' + str(bus.read_pin(1)))
    print ('Pin 2: ' + str(bus.read_pin(2)))
    print ('Pin 3: ' + str(bus.read_pin(3)))
    print ('Pin 4: ' + str(bus.read_pin(4)))
    print ('Pin 5: ' + str(bus.read_pin(5)))
    print ('Pin 6: ' + str(bus.read_pin(6)))
    print ('Pin 7: ' + str(bus.read_pin(7)))
    print ('Pin 8: ' + str(bus.read_pin(8)))

    # wait 0.5 seconds before reading the pins again
    time.sleep(0.1)
class App:
    global i2c_helper
    global newbus
    global bus2

    def __init__(self, master):
        self.i2c_helper = ABEHelpers()
        self.newbus = self.i2c_helper.get_smbus()
        self.bus2 = IoPi(
            self.newbus, 0x21
        )  # create an instance of Bus 2 which is on I2C address 0x21 by default
        self.bus2.set_port_direction(
            0, 0x00)  # set pins 1 to 8 to be outputs and turn them off
        self.bus2.write_port(0, 0x00)

        self.bus2.set_port_direction(
            1, 0x00)  # set pins 9 to 16 to be outputs and turn them off
        self.bus2.write_port(1, 0x00)

        frame = Frame(master)  # create a frame for the GUI
        frame.pack()

        # create 16 buttons which run the togglepin function when pressed
        self.button = Button(frame,
                             text="Pin 1",
                             command=lambda: self.togglepin(1))
        self.button.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 2",
                             command=lambda: self.togglepin(2))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 3",
                             command=lambda: self.togglepin(3))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 4",
                             command=lambda: self.togglepin(4))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 5",
                             command=lambda: self.togglepin(5))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 6",
                             command=lambda: self.togglepin(6))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 7",
                             command=lambda: self.togglepin(7))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 8",
                             command=lambda: self.togglepin(8))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 9",
                             command=lambda: self.togglepin(9))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 10",
                             command=lambda: self.togglepin(10))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 11",
                             command=lambda: self.togglepin(11))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 12",
                             command=lambda: self.togglepin(12))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 13",
                             command=lambda: self.togglepin(13))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 14",
                             command=lambda: self.togglepin(14))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 15",
                             command=lambda: self.togglepin(15))
        self.slogan.pack(side=LEFT)

        self.slogan = Button(frame,
                             text="Pin 16",
                             command=lambda: self.togglepin(16))
        self.slogan.pack(side=LEFT)

    def togglepin(self, pin):
        # read the status from the selected pin, invert it and write it back to the pin
        pinstatus = self.bus2.read_pin(pin)
        if (pinstatus == 1):
            pinstatus = 0
        else:
            pinstatus = 1
        self.bus2.write_pin(pin, pinstatus)
Exemple #9
0
Initialise the IOPi device using the default addresses, you will need to
change the addresses if you have changed the jumpers on the IO Pi
"""
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

bus1 = IoPi(bus, 0x22)

# We will read the inputs 1 to 8 from bus 2 so set port 0 to be inputs and
# enable the internal pull-up resistors
bus1.set_port_direction(0, 0xFF)
bus1.set_port_pullups(0, 0xFF)

while True:
    # clear the console
    os.system('clear')

    # read the pins 1 to 8 and print the results
    print 'Pin 1: ' + str(bus1.read_pin(1))
    print 'Pin 2: ' + str(bus1.read_pin(2))
    print 'Pin 3: ' + str(bus1.read_pin(3))
    print 'Pin 4: ' + str(bus1.read_pin(4))
    print 'Pin 5: ' + str(bus1.read_pin(5))
    print 'Pin 6: ' + str(bus1.read_pin(6))
    print 'Pin 7: ' + str(bus1.read_pin(7))
    print 'Pin 8: ' + str(bus1.read_pin(8))

    # wait 0.5 seconds before reading the pins again
    time.sleep(0.1)
and off on the IO Pi.
"""
from ABE_helpers import ABEHelpers
from ABE_IoPi import IoPi
import time

i2c_helper = ABEHelpers()
i2c_bus = i2c_helper.get_smbus()

bus = IoPi(i2c_bus, 0x20)

bus.set_pin_direction(1, 1)  # set pin 1 as an input

bus.set_pin_direction(8, 0)  # set pin 8 as an output

bus.write_pin(8, 0)  # turn off pin 8

bus.set_pin_pullup(1, 1)  # enable the internal pull-up resistor on pin 1

bus.invert_pin(1, 1)  # invert pin 1 so a button press will register as 1


while True:

    if bus.read_pin(1) == 1:  # check to see if the button is pressed
        print 'button pressed'  # print a message to the screen
        bus.write_pin(8, 1)  # turn on the led on pin 8
        time.sleep(2)  # wait 2 seconds
    else:
        bus.write_pin(8, 0)  # turn off the led on pin 8