Exemplo n.º 1
0
 def __init__(self):
     gpio.init()
     for column in self.columns:
         gpio.setcfg(column, gpio.OUTPUT)
     for row in self.rows:
         gpio.setcfg(row, gpio.INPUT)
         gpio.pullup(row, gpio.PULLDOWN)
Exemplo n.º 2
0
def Buttons(triggers):
    buttons = triggers.sections()
    GPIO.init()
    pins = []
    gpioType = []
    i = 0
    for button in buttons:
        gpioType.append(button[0])
        pins.append(h3pin[int(button[1:])])
        if gpioType[i] == "B":
            GPIO.setcfg(pins[i], GPIO.INPUT)
            GPIO.pullup(pins[i], GPIO.PULLUP)
        if gpioType[i] == "M":
            GPIO.setcfg(pins[i], GPIO.INPUT)
        i = i + 1

    global buttonPressed
    while True:
        i = 0
        for pin in pins:
            if gpioType[i] == "B":
                if not GPIO.input(pin):
                    buttonPressed = "B" + str(pipin[pin])
            if gpioType[i] == "M":
                if GPIO.input(pin):
                    buttonPressed = "M" + str(pipin[pin])
            i = i + 1
        time.sleep(0.020)
 def __init__(self, input_dict):
     gpio.init()
     for key in input_dict:
         tup = input_dict[key]
         gpio.setcfg(key, gpio.INPUT)
         gpio.pullup(key, gpio.PULLUP)
         self.__hk_add_to_dict(key, tup)
Exemplo n.º 4
0
def RUN_INIT():
    print "--> RUN_INIT : "
    gpio.init()
    gpio.setcfg(port.PA6, gpio.OUTPUT)
    gpio.pullup(port.PA6, gpio.PULLDOWN)
    gpio.output(port.PA6, gpio.HIGH)
    time.sleep(0.1)
Exemplo n.º 5
0
def main(argv):

    initial_button_state = 0

    gpio.init()
    gpio.setcfg(POWER_BUTTON, gpio.INPUT)
    gpio.pullup(POWER_BUTTON, gpio.PULLUP)
    gpio.setcfg(LED, gpio.OUTPUT)

    while True:
        # Returns a 1 if open and a 0 if pressed/closed
        current_button_state = gpio.input(POWER_BUTTON)

        #print(initial_button_state, current_button_state)
        #sys.stdout.flush()

        # Check if button state has changed
        if current_button_state != initial_button_state:
            #print('Button pressed')
            gpio.output(LED, 1)
            subprocess.call(CMD,
                            shell=True,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)

        time.sleep(0.1)
Exemplo n.º 6
0
 def __init__(self):
     self._loop = False
     self.detected = False
     self._line1 = port.PA2
     gpio.init()
     gpio.setcfg(self._line1, gpio.INPUT)
     gpio.pullup(self._line1, gpio.PULLUP)
Exemplo n.º 7
0
def Buttons(triggers):
    buttons = triggers.sections()
    GPIO.init()
    pins = []
    gpioType = []
    i = 0
    for button in buttons:
        gpioType.append(button[0])
        pins.append(h3pin[int(button[1:])])
        if gpioType[i] == "B":
            GPIO.setcfg(pins[i], GPIO.INPUT)
            GPIO.pullup(pins[i], GPIO.PULLUP)
        if gpioType[i] == "M":
            GPIO.setcfg(pins[i], GPIO.INPUT)
        i = i + 1

    global buttonPressed
    while True:
        i = 0
        for pin in pins:
            if gpioType[i] == "B":
                if not GPIO.input(pin):
                    buttonPressed = "B" + str(pipin[pin])
            if gpioType[i] == "M":
                if GPIO.input(pin):
                    buttonPressed = "M" + str(pipin[pin])
            i = i + 1
        time.sleep(0.020)
Exemplo n.º 8
0
def setup():
    #GPIO.setwarnings(False)
    #GPIO.cleanup()
    #GPIO.setmode(GPIO.BCM)
    GPIO.init()
    #GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setcfg(button, GPIO.INPUT)
    GPIO.pullup(button, GPIO.PULLUP)
    #GPIO.setup(lights, GPIO.OUT)
    GPIO.setcfg(lights[0], GPIO.OUTPUT)
    GPIO.setcfg(lights[1], GPIO.OUTPUT)
    #GPIO.output(lights, GPIO.LOW)
    GPIO.output(lights[0], GPIO.LOW)
    GPIO.output(lights[1], GPIO.LOW)
    while internet_on() == False:
        print(".")
    token = gettoken()
    if token == False:
        while True:
            for x in range(0, 5):
                time.sleep(.1)
                GPIO.output(rec_light, GPIO.HIGH)
                time.sleep(.1)
                GPIO.output(rec_light, GPIO.LOW)
    for x in range(0, 5):
        time.sleep(.1)
        GPIO.output(plb_light, GPIO.HIGH)
        time.sleep(.1)
        GPIO.output(plb_light, GPIO.LOW)
    play_audio(path + "hello.mp3")
Exemplo n.º 9
0
 def pullup(self, pin, mode):
     if EMU:
         print(f"PIN {pin}: pullup {mode}")
         return
     if pin > self.expin:
         self.expander.pullup(pin, mode)
         return
     G.pullup(pin, mode)
Exemplo n.º 10
0
    def read(self):
        gpio.setcfg(self.__pin, gpio.OUTPUT)

        # send initial high
        self.__send_and_sleep(gpio.HIGH, 0.05)

        # pull down to low
        self.__send_and_sleep(gpio.LOW, 0.02)

        # change to input using pull up
        #gpio.setcfg(self.__pin, gpio.INPUT, gpio.PULLUP)
        gpio.setcfg(self.__pin, gpio.INPUT)
        gpio.pullup(self.__pin, gpio.PULLUP)

        # collect data into an array
        data = self.__collect_input()

        # parse lengths of all data pull up periods
        pull_up_lengths = self.__parse_data_pull_up_lengths(data)

        # if bit count mismatch, return error (4 byte data + 1 byte checksum)
        # Fix issue on my Board with AM2301 to ensure at least the data is
        # available
        pull_up_lengths_size = len(pull_up_lengths)
        if (self.__sensor == 22 and pull_up_lengths_size < 40) or (
                self.__sensor == 11 and pull_up_lengths_size != 40):
            return DHTResult(DHTResult.ERR_MISSING_DATA, 0, 0)

        # calculate bits from lengths of the pull up periods
        bits = self.__calculate_bits(pull_up_lengths)

        # we have the bits, calculate bytes
        the_bytes = self.__bits_to_bytes(bits)

        # calculate checksum and check
        checksum = self.__calculate_checksum(the_bytes)
        if the_bytes[4] != checksum:
            return DHTResult(DHTResult.ERR_CRC, 0, 0)

        if self.__sensor == 22:
            # Compute to ensure negative values are taken into account
            c = (float)(((the_bytes[2] & 0x7F) << 8) + the_bytes[3]) / 10

            # ok, we have valid data, return it
            if (c > 125):
                c = the_bytes[2]

            if (the_bytes[2] & 0x80):
                c = -c

            return DHTResult(DHTResult.ERR_NO_ERROR, c,
                             ((the_bytes[0] << 8) + the_bytes[1]) / 10.00)
        else:
            # ok, we have valid data, return it
            return DHTResult(DHTResult.ERR_NO_ERROR, the_bytes[2],
                             the_bytes[0])
Exemplo n.º 11
0
    def __init__(self, port):
        """
        инициализация объекта
        """
        self.port = port
        self.state = gpio.LOW

        gpio.setcfg(self.port, gpio.OUTPUT)
        gpio.pullup(self.port, gpio.PULLDOWN)

        self.off()
def okno():
	window_pin = 14
	gpio.setcfg(window_pin, gpio.INPUT)
	gpio.pullup(window_pin, gpio.PULLUP)

	if gpio.input(window_pin):
		stan_gpio_okno = str('OKNO JEST OTWARTE')
    	else:
		stan_gpio_okno = str('OKNO JEST ZAMKNIETE')
	
	return jsonify(stan_gpio_okno)
Exemplo n.º 13
0
	def __init__(self, savque, ports):#quelock, ports):
		threading.Thread.__init__(self)
		self.savque = savque
		#self.quelock = quelock
		self.ports = ports
		gpio.init()
		for p in self.ports:
			gpio.setcfg(p, gpio.INPUT)
			gpio.pullup(p, gpio.PULLDOWN)
		self.led = connector.LEDp2
		gpio.setcfg(self.led, gpio.OUTPUT)
Exemplo n.º 14
0
def RUN_INIT():
    print "--> RUN_INIT : "
    global ser1
    global ser2
    global ser3
    ser1 = serial.Serial(port="/dev/ttyS1", baudrate=1200, timeout=0.1)
    ser2 = serial.Serial(port="/dev/ttyS2", baudrate=1200, timeout=0.1)
    ser3 = serial.Serial(port="/dev/ttyS3", baudrate=1200, timeout=0.1)
    gpio.init()
    gpio.setcfg(port.PA6, gpio.OUTPUT)
    gpio.pullup(port.PA6, gpio.PULLDOWN)
    gpio.output(port.PA6, gpio.LOW)
    time.sleep(0.1)
Exemplo n.º 15
0
def keypad_init():
    print "Keypad init..."
    # set each output as HIGH
    for j in range(4):
        #print "Init col " + repr(j)
        gpio.setcfg(COL[j], gpio.OUTPUT)
        gpio.output(COL[j], 1)

    # set each input as HIGH w/ pull-up resistor
    for i in range(4):
        #print "Init row " + repr(i)
        gpio.setcfg(ROW[i], gpio.INPUT)
        gpio.pullup(ROW[i], gpio.PULLUP)
Exemplo n.º 16
0
    def __init__(self, broker_address="localhost", broker_port=1883):
        self.client = mqtt.Client()  #create new instance
        #logging.basicConfig(level=logging.DEBUG)
        logger = logging.getLogger(__name__)
        self.client.enable_logger(logger)
        #self.client.connect(broker_address,broker_port,60) #connect to broker
        #print("Connected to " + broker_address + ":"+ str(broker_port))
        #time.sleep(1)
        #self.client.subscribe("shutters/commandreply")
        #print("Subscribed to shutters/commandreply")
        #self.client.on_message=self.on_message

        # Set up sequences of motor speeds.
        self.forward_speeds = list(range(0, MAX_SPEED, 2))
        self.reverse_speeds = list(range(0, -MAX_SPEED, -2))

        # pinShutter2closedSensor = connector.gpio3p37
        self.pinShutter2openSensor = port.PA10
        self.pinShutter2closedSensor = port.PA20
        self.pinShutter1openSensor = port.PG7
        self.pinShutter1closedSensor = port.PG6
        """Init gpio module"""
        gpio.init()
        """Set directions"""
        gpio.setcfg(self.pinShutter2openSensor, gpio.INPUT)
        gpio.setcfg(self.pinShutter2closedSensor, gpio.INPUT)
        gpio.setcfg(self.pinShutter1openSensor, gpio.INPUT)
        gpio.setcfg(self.pinShutter1closedSensor, gpio.INPUT)
        """Enable pullup resistor"""
        gpio.pullup(self.pinShutter2openSensor, gpio.PULLUP)
        gpio.pullup(self.pinShutter2closedSensor, gpio.PULLUP)
        gpio.pullup(self.pinShutter1openSensor, gpio.PULLUP)
        gpio.pullup(self.pinShutter1closedSensor, gpio.PULLUP)
Exemplo n.º 17
0
    def __init__(self):
        self.matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9], ['*', 0, '#']]

        self.row = [port.PA8, port.PA9, port.PA10, port.PA20]
        self.col = [port.PG7, port.PG6, port.PG9]

        gpio.init()

        for i in range(len(self.row)):
            gpio.setcfg(self.row[i], gpio.INPUT)
            gpio.pullup(self.row[i], gpio.PULLUP)

        for i in range(len(self.col)):
            gpio.setcfg(self.col[i], gpio.OUTPUT)
            gpio.output(self.col[i], 1)
Exemplo n.º 18
0
 def __init__(self, doorId, config):
     self.id = doorId
     self.name = config['name']
     self.relay_pin = port.PC4 #config['relay_pin']
     self.state_open = port.PA1 #config['open_pin']
     self.state_close = port.PA0 #config['close_pin']
     self.state_pin_closed_value = 0 #config.get('state_pin_closed_value', 0)
     self.time_to_close = config.get('time_to_close', 10)
     self.time_to_open = config.get('time_to_open', 10)
     self.openhab_name = config.get('openhab_name')
     self.open_time = time.time()
     gpio.init();
     gpio.setcfg(self.relay_pin, gpio.OUTPUT)
     gpio.setcfg(self.state_open, gpio.INPUT)
     gpio.pullup(self.state_open, gpio.PULLUP)
     gpio.setcfg(self.state_close, gpio.INPUT)
     gpio.pullup(self.state_close, gpio.PULLUP)
     gpio.output(self.relay_pin, True)
Exemplo n.º 19
0
	def __init__(self):
		gpio.init()
		
		self.sensorPin = port.PA8 #Port for the light barrier on the column bottom
		self.sleepPin = port.PA9 #Sleep Pin of the Polulu
		self.stepPin = port.PA10 #Step Pin of the Polulu
		self.dirPin = port.PA20 #Direction Pin of the Polulu
		
		
		
		self.height = 8450
		
		#Configure the Pins
		gpio.setcfg(self.sensorPin, gpio.INPUT)
		gpio.pullup(self.sensorPin, gpio.PULLUP)

		gpio.setcfg(self.sleepPin, gpio.OUTPUT)
		gpio.setcfg(self.stepPin, gpio.OUTPUT)
		gpio.setcfg(self.dirPin, gpio.OUTPUT)
Exemplo n.º 20
0
    def read(self):
        gpio.setcfg(self.__pin, gpio.OUTPUT)

        # send initial high
        self.__send_and_sleep(gpio.HIGH, 0.05)

        # pull down to low
        self.__send_and_sleep(gpio.LOW, 0.02)

        # change to input using pull up
        #gpio.setcfg(self.__pin, gpio.INPUT, gpio.PULLUP)
        gpio.setcfg(self.__pin, gpio.INPUT)
        gpio.pullup(self.__pin, gpio.PULLUP)

        # collect data into an array
        data = self.__collect_input()

        # parse lengths of all data pull up periods
        pull_up_lengths = self.__parse_data_pull_up_lengths(data)

        # if bit count mismatch, return error (4 byte data + 1 byte checksum)
        if len(pull_up_lengths) != 40:
            return DHT22Result(DHT22Result.ERR_MISSING_DATA, 0.0, 0.0)

        # calculate bits from lengths of the pull up periods
        bits = self.__calculate_bits(pull_up_lengths)

        # we have the bits, calculate bytes
        the_bytes = self.__bits_to_bytes(bits)

        hum = (the_bytes[0] << 8 | the_bytes[1])/float(10)

        temp = (((the_bytes[2] & 0x7F) << 8) + the_bytes[3])/float(10)
        if the_bytes[2] & 0x80:
            temp = -temp

        # calculate checksum and check
        checksum = self.__calculate_checksum(the_bytes)
        if the_bytes[4] != checksum:
            return DHT22Result(DHT22Result.ERR_CRC, 0.0, 0.0)

        # ok, we have valid data, return it
        return DHT22Result(DHT22Result.ERR_NO_ERROR, temp, hum)
Exemplo n.º 21
0
def setup_gpio():
	#initialize the gpio module
	gpio.init()

	#setup the port (same as raspberry pi's gpio.setup() function)
	gpio.setcfg(gp_led, gpio.OUTPUT)
	gpio.setcfg(boot_pin, gpio.OUTPUT)
	gpio.setcfg(smsError, gpio.OUTPUT)
	gpio.setcfg(statusLed, gpio.OUTPUT)
	gpio.setcfg(network_OK, gpio.OUTPUT)
	gpio.setcfg(Button0, gpio.INPUT)
	gpio.setcfg(Button1, gpio.INPUT)

	"""Enable pullup resistor"""
	gpio.pullup(Button0, gpio.PULLUP)
	gpio.pullup(Button1, gpio.PULLUP)

	gpio.output(gp_led, gpio.LOW)
	gpio.output(boot_pin, gpio.HIGH)
	gpio.output(smsError, gpio.LOW)
	gpio.output(statusLed, gpio.HIGH)
	gpio.output(network_OK, gpio.LOW)
Exemplo n.º 22
0
    def read(self):
        gpio.setcfg(self.__pin, gpio.OUTPUT)
        self.__send_and_sleep(gpio.HIGH, 0.05)
        self.__send_and_sleep(gpio.LOW, 0.02)
        gpio.setcfg(self.__pin, gpio.INPUT)
        gpio.pullup(self.__pin, gpio.PULLUP)
        data = self.__collect_input()
        pull_up_lengths = self.__parse_data_pull_up_lengths(data)

        if len(pull_up_lengths) != 40:
            return DHT11Result(DHT11Result.ERR_MISSING_DATA, 0, 0)

        bits = self.__calculate_bits(pull_up_lengths)

        the_bytes = self.__bits_to_bytes(bits)

        checksum = self.__calculate_checksum(the_bytes)
        if the_bytes[4] != checksum:
            return DHT11Result(DHT11Result.ERR_CRC, 0, 0)

        return DHT11Result(DHT11Result.ERR_NO_ERROR, the_bytes[2],
                           the_bytes[0])
Exemplo n.º 23
0
    def __init__(self):
        super(self.__class__, self).__init__()
        self.exiting = False

        self.matrix = [
            [1, 2, 3, 'A'],
            [4, 5, 6, 'B'],
            [7, 8, 9, 'C'],
            ['*', 0, '#', 'D']
        ]

        self.row = [port.PG7, port.PG6, port.PA20, port.PA10]
        self.col = [port.PG9, port.PA9, port.PA8, port.PG8]

        gpio.init()

        for i in range(4):
            gpio.setcfg(self.col[i], gpio.OUTPUT)
            gpio.output(self.col[i], 1)

            gpio.setcfg(self.row[i], gpio.INPUT)
            gpio.pullup(self.row[i], gpio.PULLUP)
Exemplo n.º 24
0
def initiatePin(): #Initialiser les GPIO
	gpio.init()
	pin = port.PG6

	gpio.setcfg(pin, gpio.OUTPUT)
	gpio.input(pin)

	gpio.setcfg(pin, 0)
	gpio.pullup(pin, 0)
	gpio.pullup(pin, gpio.PULLDOWN)
	gpio.pullup(pin, gpio.PULLUP)
Exemplo n.º 25
0
def initiatePin(): #Enable a pin

	gpio.init()
	pin = port.PG7

	gpio.setcfg(pin, gpio.OUTPUT)
	gpio.input(pin)

	gpio.setcfg(pin, 0)
	gpio.pullup(pin, 0)
	gpio.pullup(pin, gpio.PULLDOWN)
	gpio.pullup(pin, gpio.PULLUP)
Exemplo n.º 26
0
    def __init__(self, nasabah, ambil):
        super(self.__class__, self).__init__()
        self.nasabah = nasabah
        self.ambil = ambil
        self.saldo = self.nasabah[2] - self.ambil

        gpio.init()

        # SEBAGAI INPUT
        self.LS_KATUP_ATAS_BUKA = port.PA14
        self.LS_KATUP_BAWAH_BUKA = port.PC4
        self.LS_BAKI_ATAS = port.PA2
        # self.LS_BAKI_BAWAH = port.PC7

        # SEBAGAI OUTPUT
        self.MOTOR_KATUP_ATAS = port.PA6
        self.ARAH_MOTOR_KATUP_ATAS = port.PA1
        self.MOTOR_KATUP_BAWAH = port.PA0
        self.ARAH_MOTOR_KATUP_BAWAH = port.PA3
        self.MOTOR_BAKI = port.PC0
        self.POWER_2_LITER = port.PD14
        self.POWER_3_LITER = port.PA13

        gpio.setcfg(self.LS_KATUP_ATAS_BUKA, gpio.INPUT)
        gpio.setcfg(self.LS_KATUP_BAWAH_BUKA, gpio.INPUT)
        gpio.setcfg(self.LS_BAKI_ATAS, gpio.INPUT)
        # gpio.setcfg(self.LS_BAKI_BAWAH, gpio.INPUT)

        gpio.pullup(self.LS_KATUP_ATAS_BUKA, gpio.PULLUP)
        gpio.pullup(self.LS_KATUP_BAWAH_BUKA, gpio.PULLUP)
        gpio.pullup(self.LS_BAKI_ATAS, gpio.PULLUP)
        # gpio.pullup(self.LS_BAKI_BAWAH, gpio.PULLUP)

        gpio.setcfg(self.MOTOR_KATUP_ATAS, gpio.OUTPUT)
        gpio.setcfg(self.ARAH_MOTOR_KATUP_ATAS, gpio.OUTPUT)
        gpio.setcfg(self.MOTOR_KATUP_BAWAH, gpio.OUTPUT)
        gpio.setcfg(self.ARAH_MOTOR_KATUP_BAWAH, gpio.OUTPUT)
        gpio.setcfg(self.MOTOR_BAKI, gpio.OUTPUT)
        gpio.setcfg(self.POWER_2_LITER, gpio.OUTPUT)
        gpio.setcfg(self.POWER_3_LITER, gpio.OUTPUT)

        # reset output ke low semua untuk motor (just in case)
        gpio.output(self.MOTOR_KATUP_ATAS, gpio.LOW)
        gpio.output(self.MOTOR_KATUP_BAWAH, gpio.LOW)
        gpio.output(self.MOTOR_BAKI, gpio.LOW)
        gpio.output(self.POWER_2_LITER, gpio.LOW)
        gpio.output(self.POWER_3_LITER, gpio.LOW)
Exemplo n.º 27
0
from pyA20.gpio import gpio
from pyA20.gpio import connector
from pyA20.gpio import port

button_reset = port.PA9  #PIN 33  Orange PI
button_shutdown = port.PA7  #PIN 29  Orange PI

#Init gpio module
gpio.init()

#Set directions
gpio.setcfg(button_reset, gpio.INPUT)
gpio.setcfg(button_shutdown, gpio.INPUT)

#Enable pullup resistor
gpio.pullup(button_reset, gpio.PULLUP)
gpio.pullup(button_shutdown, gpio.PULLUP)


def delay_milliseconds(milliseconds):
    seconds = milliseconds / float(1000)
    sleep(seconds)


def run_cmd(cmd):
    p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
    output = p.communicate()[0]
    return output


reset_pressed = 1
Exemplo n.º 28
0
gpio.setcfg(button4, gpio.INPUT)
gpio.setcfg(button5, gpio.INPUT)
gpio.setcfg(button6, gpio.INPUT)
gpio.setcfg(button7, gpio.INPUT)
gpio.setcfg(button8, gpio.INPUT)
gpio.setcfg(button9, gpio.INPUT)
gpio.setcfg(button10, gpio.INPUT)
gpio.setcfg(button11, gpio.INPUT)
gpio.setcfg(button12, gpio.INPUT)
gpio.setcfg(button13, gpio.INPUT)
gpio.setcfg(button14, gpio.INPUT)
gpio.setcfg(button15, gpio.INPUT)
gpio.setcfg(button16, gpio.INPUT)
gpio.setcfg(button17, gpio.INPUT)
'''Enable pullup resistor'''
gpio.pullup(button1, gpio.PULLUP)
gpio.pullup(button2, gpio.PULLUP)
gpio.pullup(button3, gpio.PULLUP)
gpio.pullup(button4, gpio.PULLUP)
gpio.pullup(button5, gpio.PULLUP)
gpio.pullup(button6, gpio.PULLUP)
gpio.pullup(button7, gpio.PULLUP)
gpio.pullup(button8, gpio.PULLUP)
gpio.pullup(button9, gpio.PULLUP)
gpio.pullup(button10, gpio.PULLUP)
gpio.pullup(button11, gpio.PULLUP)
gpio.pullup(button12, gpio.PULLUP)
gpio.pullup(button13, gpio.PULLUP)
gpio.pullup(button14, gpio.PULLUP)
gpio.pullup(button15, gpio.PULLUP)
gpio.pullup(button16, gpio.PULLUP)
Exemplo n.º 29
0
import os
import sys

if not os.getegid() == 0:
    sys.exit('Script must be run as root')

from pyA20.gpio import gpio
from pyA20.gpio import connector
from pyA20.gpio import port

pir = port.PA10
"""Init gpio module"""
gpio.init()
"""Set directions"""
gpio.setcfg(pir, gpio.INPUT)
"""Enable pullup resistor"""
gpio.pullup(pir, gpio.PULLUP)
#gpio.pullup(pir, gpio.PULLDOWN)     # Optionally you can use pull-down resistor

try:
    print("Press CTRL+C to exit")
    old = 0
    while True:
        state = gpio.input(pir)  # Read pir state
        if (old != state):
            print(state)
            old = state

except KeyboardInterrupt:
    print("Goodbye.")
Exemplo n.º 30
0
Col4 = port.PA8
Row4 = port.PA7
Row3 = port.PA19
Row2 = 0
Row1 = port.PC2

gpio.init()
gpio.setcfg(Col1, gpio.INPUT)
gpio.setcfg(Col2, gpio.INPUT)
gpio.setcfg(Col3, gpio.INPUT)
gpio.setcfg(Col4, gpio.INPUT)
gpio.setcfg(Row1, gpio.OUTPUT)
gpio.setcfg(Row2, gpio.OUTPUT)
gpio.setcfg(Row4, gpio.OUTPUT)

gpio.pullup(Col1, gpio.PULLUP)
gpio.pullup(Col2, gpio.PULLUP)
gpio.pullup(Col3, gpio.PULLUP)
gpio.pullup(Col4, gpio.PULLUP)

try:
    print("Press CTRL+C to exit")
    while True:
        gpio.output(Row4, 0)
        if gpio.input(Col4) == 0:
            print("*")
            while (gpio.input(Col4) == 0):
                pass
                sleep(0.2)
        if gpio.input(Col3) == 0:
            print("0")
Exemplo n.º 31
0
    def __init__(self, nasabah):
        super(self.__class__, self).__init__()
        self.nasabah = nasabah
        self.saldo = self.nasabah[2] - 3

        gpio.init()

        # SEBAGAI INPUT
        self.LS_KATUP_ATAS_BUKA = port.PD14
        self.LS_KATUP_ATAS_TUTUP = port.PC4
        self.LS_KATUP_BAWAH_BUKA = port.PC7
        self.LS_KATUP_BAWAH_TUTUP = port.PA2
        self.LS_SEDOT_PLASTIK_MAJU = port.PC3
        self.LS_SEDOT_PLASTIK_MUNDUR = port.PA21

        # SEBAGAI OUTPUT
        self.MOTOR_KATUP_ATAS = port.PA6
        self.MOTOR_KATUP_BAWAH = port.PA1
        self.MOTOR_SEDOT_PLASTIK = port.PA0
        self.ARAH_MOTOR = port.PA3
        self.VACUM = port.PC0

        gpio.setcfg(self.LS_KATUP_ATAS_BUKA, gpio.INPUT)
        gpio.setcfg(self.LS_KATUP_ATAS_TUTUP, gpio.INPUT)
        gpio.setcfg(self.LS_KATUP_BAWAH_BUKA, gpio.INPUT)
        gpio.setcfg(self.LS_KATUP_BAWAH_TUTUP, gpio.INPUT)
        gpio.setcfg(self.LS_SEDOT_PLASTIK_MAJU, gpio.INPUT)
        gpio.setcfg(self.LS_SEDOT_PLASTIK_MUNDUR, gpio.INPUT)

        gpio.pullup(self.LS_KATUP_ATAS_BUKA, gpio.PULLUP)
        gpio.pullup(self.LS_KATUP_ATAS_TUTUP, gpio.PULLUP)
        gpio.pullup(self.LS_KATUP_BAWAH_BUKA, gpio.PULLUP)
        gpio.pullup(self.LS_KATUP_BAWAH_TUTUP, gpio.PULLUP)
        gpio.pullup(self.LS_SEDOT_PLASTIK_MAJU, gpio.PULLUP)
        gpio.pullup(self.LS_SEDOT_PLASTIK_MUNDUR, gpio.PULLUP)

        gpio.setcfg(self.MOTOR_KATUP_ATAS, gpio.OUTPUT)
        gpio.setcfg(self.MOTOR_KATUP_BAWAH, gpio.OUTPUT)
        gpio.setcfg(self.MOTOR_SEDOT_PLASTIK, gpio.OUTPUT)
        gpio.setcfg(self.ARAH_MOTOR, gpio.OUTPUT)
        gpio.setcfg(self.VACUM, gpio.OUTPUT)

        # reset output ke low semua untuk motor (just in case)
        gpio.output(self.MOTOR_KATUP_ATAS, gpio.LOW)
        gpio.output(self.MOTOR_KATUP_BAWAH, gpio.LOW)
        gpio.output(self.MOTOR_SEDOT_PLASTIK, gpio.LOW)
        gpio.output(self.VACUM, gpio.LOW)
Exemplo n.º 32
0
        print("{}Recording Finished.{}".format(bcolors.OKBLUE, bcolors.ENDC))
        rf = open(path + 'recording.wav', 'w')
        rf.write(audio)
        rf.close()
        inp = None
        alexa_speech_recognizer()


if __name__ == "__main__":
    #	GPIO.setwarnings(False)
    #	GPIO.cleanup()
    #	GPIO.setmode(GPIO.BCM)
    gpio.init()
    #	GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    gpio.setcfg(button, gpio.INPUT)
    gpio.pullup(button, gpio.PULLUP)
    #	GPIO.setup(lights, GPIO.OUT)
    gpio.setcfg(lights[0], gpio.OUTPUT)
    gpio.setcfg(lights[1], gpio.OUTPUT)
    #	GPIO.output(lights, GPIO.LOW)
    gpio.output(lights[0], gpio.LOW)
    gpio.output(lights[1], gpio.LOW)
    while internet_on() == False:
        print(".")
    token = gettoken()
    play_audio("hello.mp3")
    for x in range(0, 3):
        time.sleep(.1)
        #		GPIO.output(plb_light, GPIO.HIGH)
        gpio.output(plb_light, gpio.HIGH)
        time.sleep(.1)
Exemplo n.º 33
0
	def setup(self):
		GPIO.init()
		GPIO.setcfg(self._pconfig['button'], GPIO.INPUT)
		GPIO.pullup(self._pconfig['button'], GPIO.PULLUP)
		GPIO.setcfg(self._pconfig['rec_light'], GPIO.OUTPUT)
		GPIO.setcfg(self._pconfig['plb_light'], GPIO.OUTPUT)
Exemplo n.º 34
0
#import the library
from pyA20.gpio import gpio
from pyA20.gpio import port
from time import sleep


def createParser ():
    parser = argparse.ArgumentParser()
    parser.add_argument ('name', nargs='?')

    return parser


# Read pin 40 
gpio.setcfg(port.PG7, gpio.INPUT)   #Configure PE11 as input
gpio.setcfg(port.PG7, 0)   #Same as above

gpio.pullup(port.PG7, 0)   #Clear pullups
gpio.pullup(port.PG7, gpio.PULLDOWN)    #Enable pull-down
gpio.pullup(port.PG7, gpio.PULLUP)      #Enable pull-up

while True:
      if gpio.input(port.PG7) != 1:
         gpio.output(port.PA20, gpio.LOW)
         gpio.output(port.PA20, 0)
	 print ("PUSH!!!")
      else:
         gpio.output(port.PA20, gpio.HIGH)
         gpio.output(port.PA20, 1)
Exemplo n.º 35
0
def setup():
    gpio.setcfg(PIN_BUTTON, gpio.INPUT)
    gpio.pullup(PIN_BUTTON, gpio.PULLDOWN)
    gpio.setcfg(PIN_AUTOPLAY, gpio.OUTPUT)

    initialize_graphics()
Exemplo n.º 36
0
				audio += data
		print("{}Recording Finished.{}".format(bcolors.OKBLUE, bcolors.ENDC))
		rf = open(path+'recording.wav', 'w')
		rf.write(audio)
		rf.close()
		inp = None
		alexa_speech_recognizer()

if __name__ == "__main__":
#	GPIO.setwarnings(False)
#	GPIO.cleanup()
#	GPIO.setmode(GPIO.BCM)
	gpio.init()
#	GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        gpio.setcfg(button, gpio.INPUT)
        gpio.pullup(button, gpio.PULLUP)
#	GPIO.setup(lights, GPIO.OUT)
        gpio.setcfg(lights[0], gpio.OUTPUT)
        gpio.setcfg(lights[1], gpio.OUTPUT)
#	GPIO.output(lights, GPIO.LOW)
        gpio.output(lights[0], gpio.LOW)
        gpio.output(lights[1], gpio.LOW)
	while internet_on() == False:
		print(".")
	token = gettoken()
	play_audio("hello.mp3")
	for x in range(0, 3):
		time.sleep(.1)
#		GPIO.output(plb_light, GPIO.HIGH)
		gpio.output(plb_light, gpio.HIGH)
		time.sleep(.1)