コード例 #1
0
 def __new__(cls, number):
     if not cls._PINS:
         GPIO.setmode(GPIO.BCM)
         GPIO.setwarnings(False)
     if cls.PI_INFO is None:
         cls.PI_INFO = pi_info("900092")
         #Fake a Pi Zero 1.2, Closest device as just has GPIO Pins and no camera.
         #cls.PI_INFO = 900092
     try:
         return cls._PINS[number]
     except KeyError:
         self = super(RTkGPIOPin, cls).__new__(cls)
         try:
             cls.PI_INFO.physical_pin('GPIO%d' % number)
         except PinNoPins:
             warnings.warn(
                 PinNonPhysical('no physical pins exist for GPIO%d' %
                                number))
         self._number = number
         self._pull = 'up' if cls.PI_INFO.pulled_up('GPIO%d' %
                                                    number) else 'floating'
         self._pwm = None
         self._frequency = None
         self._duty_cycle = None
         self._bounce = -666
         self._when_changed = None
         self._edges = GPIO.BOTH
         GPIO.setup(self._number, GPIO.IN, self.GPIO_PULL_UPS[self._pull])
         cls._PINS[number] = self
         return self
コード例 #2
0
 def __new__(cls, number):
     if not cls._PINS:
         GPIO.setmode(GPIO.BCM)
         GPIO.setwarnings(False)
     if cls.PI_INFO is None:
         cls.PI_INFO = pi_info("900092")
         #Fake a Pi Zero 1.2, Closest device as just has GPIO Pins and no camera.
         #cls.PI_INFO = 900092
     try:
         return cls._PINS[number]
     except KeyError:
         self = super(RTkGPIOPin, cls).__new__(cls)
         try:
             cls.PI_INFO.physical_pin('GPIO%d' % number)
         except PinNoPins:
             warnings.warn(
                 PinNonPhysical(
                     'no physical pins exist for GPIO%d' % number))
         self._number = number
         self._pull = 'up' if cls.PI_INFO.pulled_up('GPIO%d' % number) else 'floating'
         self._pwm = None
         self._frequency = None
         self._duty_cycle = None
         self._bounce = -666
         self._when_changed = None
         self._edges = GPIO.BOTH
         GPIO.setup(self._number, GPIO.IN, self.GPIO_PULL_UPS[self._pull])
         cls._PINS[number] = self
         return self
コード例 #3
0
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()
コード例 #4
0
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)
コード例 #5
0
def main():
  # Main program block

  #GPIO.setwarnings(False)
  GPIO.setmode(GPIO.BCM)       # Use BCM GPIO numbers
  GPIO.setup(LCD_E, GPIO.OUT)  # E
  GPIO.setup(LCD_RS, GPIO.OUT) # RS
  GPIO.setup(LCD_D4, GPIO.OUT) # DB4
  GPIO.setup(LCD_D5, GPIO.OUT) # DB5
  GPIO.setup(LCD_D6, GPIO.OUT) # DB6
  GPIO.setup(LCD_D7, GPIO.OUT) # DB7


  # Initialise display
  lcd_init()

  while True:

    # Send some test
    lcd_string("RTk.GPIO",LCD_LINE_1)
    lcd_string("16x2 LCD Test",LCD_LINE_2)

    time.sleep(3) # 3 second delay

    # Send some text
    lcd_string("1234567890123456",LCD_LINE_1)
    lcd_string("abcdefghijklmnop",LCD_LINE_2)



    time.sleep(3) # 3 second delay

    # Send some text
    lcd_string("Code by",LCD_LINE_1)
    lcd_string("RPiSPY",LCD_LINE_2)

    time.sleep(3)

    # Send some text
    lcd_string("Wow, Very LCD",LCD_LINE_1)
    lcd_string("Such Magic",LCD_LINE_2)

    time.sleep(3)

    lcd_string("All done on a", LCD_LINE_1)
    lcd_string("Desktop Computer", LCD_LINE_2)
    time.sleep(3)
コード例 #6
0
ファイル: home_automation.py プロジェクト: nvmanh/plant
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")
コード例 #7
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")
コード例 #8
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)
コード例 #9
0
#import RPi.GPIO as GPIO
# For RTK.GPIO board
#from RTk import GPIO
import RTk.GPIO as GPIO
import MFRC522
import argparse
import math
import NFCHelper
import signal
import SonosController
# time added for LEDs
import time

## _________LED Setup____________
# Set GPIO to Broadcom chip used in Raspberry Pi
GPIO.setmode(GPIO.BOARD)
## _________End LED Setup____________

continue_reading = True
is_test = False


## Capture SIGINT for cleanup when the script is aborted
def end_read(signal, frame):
    global continue_reading
    print("Ctrl+C captured, ending read.")
    continue_reading = False
    GPIO.cleanup()
    print("GPIO Cleaned")

コード例 #10
0
def setup():
  GPIO.setmode(GPIO.BCM)
  GPIO.setup(BUTTON, GPIO.IN)
コード例 #11
0
#Program that tests each pin of the RTk.GPIO port
#Import the RTk.GPIO Board
import RTk.GPIO as RTKGPIO
#And now the RPi header
import RPi.GPIO as RPIGPIO
import sys
from time import sleep

#Set the modes
RPIGPIO.setmode(RPIGPIO.BCM)
RTKGPIO.setmode(RTKGPIO.BCM)

#
#Define GPIO pins
gpios = [
    4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
    24, 25
]
#2,3,26 and 27 removed for now
errorPins = []

print("Setting up GPIO Outs on the RTK Board")
#Setup the RPi
for gpio in gpios:
    print(gpio)
    RTKGPIO.setup(gpio, RTKGPIO.IN)
    #sleep(0.1)

print("Setting up GPIO Ins on the RPi Board")
for gpio in gpios:
    print(gpio)
コード例 #12
0
ファイル: home_automation.py プロジェクト: nvmanh/plant
# client side
import time
# import RPi.GPIO as GPIO
from RTk import GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(6, GPIO.OUT)
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")
   
コード例 #13
0
ファイル: test.py プロジェクト: kerzhang/installation-scripts
#import RPi.GPIO as GPIO
import RTk.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)  # Broadcom pin-numbering scheme

ledPin = 21

GPIO.setup(ledPin, GPIO.OUT)
GPIO.output(ledPin, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(ledPin, GPIO.LOW)
time.sleep(0.2)

ledPin = 20

while True:
    GPIO.setup(ledPin, GPIO.OUT)
    GPIO.output(ledPin, GPIO.HIGH)
    time.sleep(0.002)
    GPIO.output(ledPin, GPIO.LOW)
    time.sleep(0.002)