Beispiel #1
0
def lcd_toggle_enable():
  # Toggle enable
  time.sleep(E_DELAY)
  GPIO.output(LCD_E, True)
  time.sleep(E_PULSE)
  GPIO.output(LCD_E, False)
  time.sleep(E_DELAY)
def init(delay=0.0015):
    global running, StepCount, StepDir, stepsToDo, StepPosition, StepPins
    global StepCounter, Seq, WaitTime
    # Use physical pin numbers
    GPIO.setmode(GPIO.BCM)

    # Define GPIO signals to use
    #  StepPins = [35,36,32,33]   # RoboHat
    StepPins = [4, 17, 27, 18]  # ZeroPoint

    # Set all pins as output
    for pin in StepPins:
        GPIO.setup(pin, GPIO.OUT)
        GPIO.output(pin, False)

    # Define pin sequence
    Seq = [[1, 0, 0, 1], [1, 0, 1, 0], [0, 1, 1, 0], [0, 1, 0, 1]]

    StepCount = len(Seq)
    StepDir = 1  # 1 == clockwise, -1 = anticlockwise
    StepsToDo = 0  #number of steps to move
    StepPosition = 0  # current steps anti-clockwise from the zero position

    # Initialise variables
    StepCounter = 0
    WaitTime = delay
    running = True
    # Move pointer to zero position
    StepDir = -1
    stepsToDo = 700
    step()
def setup():
    GPIO.setmode(GPIO.BCM)
    for l in LED_GPIO:
        GPIO.setup(l, GPIO.OUT)
        GPIO.output(l, False)

    for b in BUTTON_GPIO:
        GPIO.setup(b, GPIO.IN)
Beispiel #4
0
 def _set_state(self, value):
     if self._pwm:
         try:
             self._pwm.ChangeDutyCycle(value * 100)
         except ValueError:
             raise PinInvalidState('invalid state "%s" for pin %r' % (value, self))
         self._duty_cycle = value
     else:
         try:
             GPIO.output(self._number, value)
         except ValueError:
             raise PinInvalidState('invalid state "%s" for pin %r' % (value, self))
         except RuntimeError:
             raise PinSetInput('cannot set state of pin %r' % self)
Beispiel #5
0
def executeSonosCommand(sonosUri):
    print("Calling '%s'" % sonosUri)

    # Send command
    response = requests.get(sonosUri)
    print(response.json())
    json_response = response.json()
    json_response = str(json_response)
    success = "success"
    if success in json_response:
        print("Sending success signal to LED")
        # Turn On Pin 12 for x Seconds
        GPIO.setup(12, GPIO.OUT)
        GPIO.output(12, GPIO.HIGH)
        time.sleep(5)
        GPIO.output(12, GPIO.LOW)
        # End Turn On Pin 12 for x Seconds
    else:
        print("Sonos Node Server Error")
        # Turn On Pin 31 for x Seconds
        GPIO.setup(31, GPIO.OUT)
        GPIO.output(31, GPIO.HIGH)
        time.sleep(5)
        GPIO.output(31, GPIO.LOW)
        # End Turn On Pin 31 for x Seconds

    if(response.status_code == 200):
        return True
    else:
        return False
def loop():
    old_first = False
    old_left = False
    old_right = False
    old_last = False
    index = 0

    while True:
        # POLL BUTTONS
        # remember they are inverted
        first = not GPIO.input(BUTTON_FIRST)
        left = not GPIO.input(BUTTON_LEFT)
        right = not GPIO.input(BUTTON_RIGHT)
        last = not GPIO.input(BUTTON_LAST)

        # REPORT ANY CHANGED BUTTONS
        if first != old_first:
            print("FIRST=" + str(first))
            old_first = first
        if left != old_left:
            print("LEFT=" + str(left))
            old_left = left
        if right != old_right:
            print("RIGHT=" + str(right))
            old_right = right
        if last != old_last:
            print("LAST=" + str(last))
            old_last = last

        # PROCESS HELD BUTTONS IN PRIORITY ORDER
        if first:
            index = 0

        elif last:
            index = len(LED_GPIO) - 1

        elif left:
            if index > 0:
                index -= 1

        elif right:
            if index < len(LED_GPIO) - 1:
                index += 1

        # FLASH PRESENTLY SELECTED LED
        GPIO.output(LED_GPIO[index], True)
        time.sleep(FLASH_TIME / 2)
        GPIO.output(LED_GPIO[index], False)
        time.sleep(FLASH_TIME / 2)
Beispiel #7
0
 def _set_state(self, value):
     if self._pwm:
         try:
             self._pwm.ChangeDutyCycle(value * 100)
         except ValueError:
             raise PinInvalidState('invalid state "%s" for pin %r' %
                                   (value, self))
         self._duty_cycle = value
     else:
         try:
             GPIO.output(self._number, value)
         except ValueError:
             raise PinInvalidState('invalid state "%s" for pin %r' %
                                   (value, self))
         except RuntimeError:
             raise PinSetInput('cannot set state of pin %r' % self)
Beispiel #8
0
 def startprocess(self):
     GPIO.output(self.TRIG, True)
     sleep(0.00001)
     GPIO.output(self.TRIG, False)
     while GPIO.input(self.ECHO)==0:
         starttime=time.time()
     while GPIO.input(self.ECHO)==1:
         stoptime=time.time()
         if stoptime-starttime > l_of_box/speedofmoter:
             lol=False
             break
     if lol!= False:
         d_cm=(stoptime-starttime)*34300
         if d_cm > l_of_box:
             return  "go"
         else:
             # if goinginx==True:
             #     objfinded(objco=[mycoo[0]+1,mycoo[1]])
             # elif goinginy==True:
             #     objfinded(objco=[mycoo[0],mycoo[1]+1])
             return "wait"
     else:
         return "go"
Beispiel #9
0
 def distance(self,a=1):
     GPIO.output(self.TRIG, False)
     GPIO.output(self.TRIG, True)
     sleep(0.00001)
     GPIO.output(self.TRIG, False)
     while GPIO.input(self.ECHO)==0:
         starttime=time.time()
     while GPIO.input(self.ECHO)==1:
         stoptime=time.time()
         d_cm=(stoptime-starttime)*34300
         if d_cm>20:
             break
     if a==1:
         return d_cm
     elif a==2:
         if d_cm>19:
             return "go"
         else:
             return "turn"
Beispiel #10
0
def step():
    global running, StepCounter, stepsToDo
    while running and stepsToDo > 0:
        for pin in range(0, 4):
            xpin = StepPins[pin]  # Get GPIO
            if Seq[StepCounter][pin] != 0:
                GPIO.output(xpin, True)
            else:
                GPIO.output(xpin, False)
        StepCounter += StepDir
        if (StepCounter >= StepCount):
            StepCounter = 0
        if (StepCounter < 0):
            StepCounter = StepCount + StepDir
        stepsToDo -= 1
        #print stepsToDo
        time.sleep(WaitTime)
    # clear the output pins
    for pin in StepPins:
        GPIO.output(pin, False)
    running = False
from RTk import GPIO
from time import sleep

Green_LED = 26
Amber_LED = 19
Red_LED = 13
GPIO.setmode(GPIO.BCM)
GPIO.setup(Green_LED, GPIO.OUT)
GPIO.setup(Amber_LED, GPIO.OUT)
GPIO.setup(Red_LED, GPIO.OUT)

Doze = 2.0

while True:
    GPIO.output(Red_LED, 1)
    sleep(Doze)
    GPIO.output(Red_LED, 0)
    GPIO.output(Amber_LED, 0)
    sleep(Doze / 4)
    GPIO.output(Amber_LED, 1)
    sleep(Doze / 4)
    GPIO.output(Amber_LED, 0)
    sleep(Doze / 4)
    GPIO.output(Amber_LED, 1)
    sleep(Doze / 4)
    GPIO.output(Amber_LED, 0)
    sleep(Doze / 4)
    GPIO.output(Amber_LED, 1)
    sleep(Doze / 4)
    GPIO.output(Amber_LED, 0)
    sleep(Doze / 4)
import RTk.GPIO as GPIO
from threading import Thread
BUTTON = 25

RED = 24
YEL = 23
GRN = 22

GPIO.setmode(GPIO.BCM)

GPIO.setup(RED, GPIO.OUT)
GPIO.setup(YEL, GPIO.OUT)
GPIO.setup(GRN, GPIO.OUT)

GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.output(GRN, True)


def pinread():
    while True:
        time.sleep(TIME)
        b = GPIO.input(BUTTON)
        if not b:
            print("pressed")
        else:
            print("released")


def pinwrite():
    while True:
        GPIO.output(GRN, False)
def pinwrite():
    while True:
        GPIO.output(GRN, False)
        GPIO.output(YEL, True)
        time.sleep(TIME * 10)
        GPIO.output(YEL, False)
        GPIO.output(RED, True)
        time.sleep(TIME * 10)
        GPIO.output(YEL, True)
        time.sleep(TIME * 10)
        GPIO.output(RED, False)
        GPIO.output(YEL, False)
        GPIO.output(GRN, True)
        time.sleep(TIME * 10)
Beispiel #14
0
#!/usr/bin/env python3

from RTk import GPIO
from time import sleep

GREEN_LED = 5
RED_LED = 6
BLUE_LED = 13

GPIO.setmode(GPIO.BCM)
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.setup(RED_LED, GPIO.OUT)
GPIO.setup(BLUE_LED, GPIO.OUT)

while True:
    GPIO.output(GREEN_LED, 0)
    GPIO.output(RED_LED, 0)
    GPIO.output(BLUE_LED, 0)
    sleep(0.5)

    GPIO.output(GREEN_LED, 1)
    sleep(0.5)

    GPIO.output(GREEN_LED, 0)
    GPIO.output(RED_LED, 1)
    sleep(0.5)

    GPIO.output(RED_LED, 0)
    GPIO.output(BLUE_LED, 1)
    sleep(0.5)
Beispiel #15
0
 def off(self):
     GPIO.output(self.pin, False)
Beispiel #16
0
def init(pin):
    GPIO.setup(pin,GPIO.OUT)
    GPIO.output(pin,False)
Beispiel #17
0
 def moveB(self,s=30):
     self.p.ChangeDutyCycle(s)
     GPIO.output(self.in1,False)
     GPIO.output(self.in2,True)
Beispiel #18
0
def motor_control(direction):
    #  print direction

    if (direction == "fwd"):
        GPIO.output(12, True)
        GPIO.output(13, False)
        GPIO.output(5, False)
        GPIO.output(6, False)

        print("forward position led flow")

    if (direction == "bwd"):

        GPIO.output(13, True)
        GPIO.output(12, False)
        GPIO.output(5, False)
        GPIO.output(6, False)

        print("backward position led flow")

    if (direction == "left"):
        GPIO.output(5, True)
        GPIO.output(12, False)
        GPIO.output(13, False)
        GPIO.output(6, False)

        print("LEFT position led flow")

    if (direction == "right"):
        GPIO.output(6, True)
        GPIO.output(5, False)
        GPIO.output(12, False)
        GPIO.output(13, False)
        print("RIGHT position led flow")
    if (direction == "stop"):
        GPIO.setmode(GPIO.BCM)
        GPIO.output(12, False)
        GPIO.output(13, False)
        GPIO.output(5, False)
        GPIO.output(6, False)

        print("STOP position led flow")
Beispiel #19
0
 def movef(self,s=30):
     self.p.ChangeDutyCycle(s)
     # GPIO.PWM(self.Ena,1000).ChangeDutyCycle(s)
     GPIO.output(self.in1,True)
     GPIO.output(self.in2,False)
import RTk.GPIO as GPIO

outputs = [22, 23, 24, 5]
BUTT = 25

GPIO.setmode(GPIO.BCM)
sleep(t)
GPIO.setup(outputs, GPIO.OUT)
sleep(t)

GPIO.setup(BUTT, GPIO.IN)
sleep(t)

try:
    while True:
        GPIO.output(22, True)
        sleep(t)
        GPIO.output(23, True)
        sleep(t)
        GPIO.output(24, True)
        sleep(2)
        GPIO.output(22, False)
        sleep(t)
        GPIO.output(23, False)
        sleep(t)
        GPIO.output(24, False)
        sleep(2)

finally:
    GPIO.cleanup()
from RTk import GPIO
import time

LED_PIN = 4

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(LED_PIN, GPIO.OUT)

while True:

    print("LED on")
    GPIO.output(LED_PIN, GPIO.HIGH)
    time.sleep(1)
    print("LED off")
    GPIO.output(LED_PIN, GPIO.LOW)
    time.sleep(1)
Beispiel #22
0
 def on(self):
     GPIO.output(self.pin, True)
Beispiel #23
0
OUT2 = 23
OUT3 = 24
OUT4 = 25

GPIO.setmode(GPIO.BCM)
GPIO.setup(RED, GPIO.OUT)
GPIO.setup(YEL, GPIO.OUT)
GPIO.setup(GRN, GPIO.OUT)
GPIO.setup(OUT1, GPIO.OUT)
GPIO.setup(OUT2, GPIO.OUT)
GPIO.setup(OUT3, GPIO.OUT)
GPIO.setup(OUT4, GPIO.OUT)

try:
    while True:
        GPIO.output(RED, True)
        sleep(t)
        GPIO.output(YEL, True)
        sleep(t)
        GPIO.output(GRN, True)
        sleep(t)
        GPIO.output(OUT1, True)
        sleep(t)
        GPIO.output(OUT2, True)
        sleep(t)
        GPIO.output(OUT3, True)
        sleep(t)
        GPIO.output(OUT4, True)
        sleep(t)
        GPIO.output(RED, False)
        sleep(t)
Beispiel #24
0
# testLED.py - 06/06/2014 D.J.Whale
# Modified by Ryan Walmsley
# Test flashing an LED

from time import sleep
t = 0.01

# RTk.GPIO
import RTk.GPIO as GPIO

P = 22

GPIO.setmode(GPIO.BCM)
GPIO.setup(P, GPIO.OUT)

while True:
    GPIO.output(P, True)
    sleep(t)
    GPIO.output(P, False)
    sleep(t)

# END
Beispiel #25
0
 def Stop(self):
     GPIO.output(self.in1,False)
     GPIO.output(self.in2,False)
     self.p.ChangeDutyCycle(0)
Beispiel #26
0
def lcd_byte(bits, mode):
  # Send byte to data pins
  # bits = data
  # mode = True  for character
  #        False for command

  GPIO.output(LCD_RS, mode) # RS

  # High bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x10==0x10:
    GPIO.output(LCD_D4, True)
  if bits&0x20==0x20:
    GPIO.output(LCD_D5, True)
  if bits&0x40==0x40:
    GPIO.output(LCD_D6, True)
  if bits&0x80==0x80:
    GPIO.output(LCD_D7, True)

  # Toggle 'Enable' pin
  lcd_toggle_enable()

  # Low bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x01==0x01:
    GPIO.output(LCD_D4, True)
  if bits&0x02==0x02:
    GPIO.output(LCD_D5, True)
  if bits&0x04==0x04:
    GPIO.output(LCD_D6, True)
  if bits&0x08==0x08:
    GPIO.output(LCD_D7, True)

  # Toggle 'Enable' pin
  lcd_toggle_enable()
Beispiel #27
0
 def __init__(self,TRIG,ECHO):
     self.TRIG=TRIG
     self.ECHO=ECHO
     GPIO.setup(self.TRIG,GPIO.OUT)
     GPIO.setup(self.ECHO,GPIO.IN)
     GPIO.output(self.TRIG, False)
Beispiel #28
0
 def __init__(self, pin):
     self.pin = pin
     GPIO.setup(pin, GPIO.OUT)
     GPIO.output(pin, False)
Beispiel #29
0
is_test = args.test
SonosController.SONOS_BASE_URI = args.sonosUri
SonosController.SONOS_ROOM = args.sonosRoom

last_nfc_uri = ""
last_time = datetime.now() - timedelta(seconds=60)
debounce = timedelta(seconds=args.debounce)
card_timeout = timedelta(seconds=args.cardTimeout)

MIFAREReader = MFRC522.MFRC522()

## _________LED Test____________
# Turn On IO 29 for x Seconds
GPIO.setup(29, GPIO.OUT)
GPIO.output(29, GPIO.HIGH)
time.sleep(1)
GPIO.output(29, GPIO.LOW)
# End Turn On Pin 29 for x Seconds
## _________End LED Test____________

print("Add NFC Tag ...")

# Program start
# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:

    now = datetime.now()

    # Debounce card reader
    if last_time + debounce > now:
Green_LED = 26
Amber_LED = 19
Red_LED = 13

G2LED = 4
A2LED = 3
R2LED = 2

GPIO.setmode(GPIO.BCM)
GPIO.setup(Green_LED, GPIO.OUT)
GPIO.setup(Amber_LED, GPIO.OUT)
GPIO.setup(Red_LED, GPIO.OUT)

GPIO.setup(G2LED, GPIO.OUT)
GPIO.setup(A2LED, GPIO.OUT)
GPIO.setup(R2LED, GPIO.OUT)

Doze = 2.0

AllLED = (Green_LED, Amber_LED, Red_LED, G2LED, A2LED, R2LED)

#def AllOff():
for count in AllLED:

    print(count)
    GPIO.output(count, 1)
    sleep(Doze)
    GPIO.output(count, 0)
    sleep(Doze)
Beispiel #31
0
#TrafficHAT KS Demo
from time import sleep
t = 0.1
import RTk.GPIO as GPIO

gpios = [
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    21, 22, 23, 24, 25, 26, 27
]

GPIO.setmode(GPIO.BCM)
while True:
    for cGPIO in gpios:
        print("Testing GPIO", cGPIO)
        GPIO.setup(cGPIO, GPIO.OUT)
        raw_input("Press enter to continue")
        GPIO.output(cGPIO, 1)
    sleep(1)
    for cGPIO in gpios:
        #sleep(t)
        raw_input("Press enter to continue")
        GPIO.output(cGPIO, 0)
        #sleep(t)
    sleep(1)
Beispiel #32
0
def motor_control(direction):
#  print direction
  
  
  if (direction == "fwd"):
    GPIO.output(12, True)
    GPIO.output(13, False)
    GPIO.output(5, False)
    GPIO.output(6, False)

    print ("forward position led flow")

 
  if (direction == "bwd"):
   
    GPIO.output(13, True)
    GPIO.output(12, False)
    GPIO.output(5, False)
    GPIO.output(6, False)

    print ("backward position led flow")
   
  if (direction == "left"):     
    GPIO.output(5, True)
    GPIO.output(12, False)
    GPIO.output(13, False)
    GPIO.output(6, False)

    print ("LEFT position led flow")
   
  if (direction == "right"):
    GPIO.output(6, True)
    GPIO.output(5, False)
    GPIO.output(12, False)
    GPIO.output(13, False)
    print ("RIGHT position led flow")
  if (direction == "stop"):
    GPIO.setmode(GPIO.BCM)
    GPIO.output(12, False)
    GPIO.output(13, False)
    GPIO.output(5, False)
    GPIO.output(6, False)


    print ("STOP position led flow")