示例#1
0
def configureHardware(postMotionEvent, postButtonClickEvent):
    wiringpi.wiringPiSetupGpio()

    # PIR motion detector
    def reportMotion():
        if wiringpi.digitalRead(BCM_PIR) == 1:
            postMotionEvent()

    wiringpi.pinMode(BCM_PIR, wiringpi.GPIO.INPUT)
    wiringpi.pullUpDnControl(BCM_PIR, wiringpi.GPIO.PUD_OFF)
    wiringpi.wiringPiISR(BCM_PIR, wiringpi.GPIO.INT_EDGE_BOTH, reportMotion)

    # Display buttons
    for btnNum, bcmPin in (
        (1, BCM_BTN_1),
        (2, BCM_BTN_2),
        (3, BCM_BTN_3),
    ):

        @debounce(0.02)
        def reportClick(_bcmPin=bcmPin, _btnNum=btnNum):
            if wiringpi.digitalRead(_bcmPin) == 0:
                postButtonClickEvent(_btnNum)

        wiringpi.pinMode(bcmPin, wiringpi.GPIO.INPUT)
        wiringpi.pullUpDnControl(bcmPin, wiringpi.GPIO.PUD_UP)
        wiringpi.wiringPiISR(bcmPin, wiringpi.GPIO.INT_EDGE_BOTH, reportClick)

    # Servos
    wiringpi.pinMode(BCM_SERVO_ACTIVATION, wiringpi.GPIO.OUTPUT)
    wiringpi.pinMode(BCM_SERVO_SPRING, wiringpi.GPIO.OUTPUT)
    wiringpi.pinMode(BCM_SERVO_HOLDER, wiringpi.GPIO.OUTPUT)
示例#2
0
def mode_select():
    pushSW_PIN = 15
    slideSW_PIN = 14

    pi.wiringPiSetupGpio()
    pi.pullUpDnControl(pushSW_PIN, pi.PUD_DOWN)
    pi.pullUpDnControl(slideSW_PIN, pi.PUD_DOWN)
    pi.pinMode(pushSW_PIN, pi.INPUT)
    pi.pinMode(slideSW_PIN, pi.INPUT)

    if (pi.digitalRead(slideSW_PIN) == pi.HIGH
            and pi.digitalRead(pushSW_PIN) == pi.LOW):
        print("slideSwitch On")
        print("pushSwitch Off")
        mode_select = 1
        print("TRANSLATIONAL MODE")
        print('mode_select=%d' % mode_select)
    elif (pi.digitalRead(slideSW_PIN) == pi.HIGH
          and pi.digitalRead(pushSW_PIN) == pi.HIGH):
        print("slideSwitch On")
        print("pushSwitch On")
        mode_select = 2
        print("ROTATIONAL MODE")
        print('mode_select=%d' % mode_select)
    else:
        print("slideSwitch Off")
        print("pushSwitch Off")
        mode_select = 0
        print("PUPPET MODE")
        print('mode_select=%d' % mode_select)

    return (mode_select)
def setup():
    wpi.wiringPiSetup()
    wpi.pinMode(pCLK, wpi.INPUT)
    wpi.pinMode(pDT, wpi.INPUT)
    wpi.pinMode(pSW, wpi.INPUT)
    wpi.pullUpDnControl(pSW, wpi.PUD_UP)
    rotaryClear()
示例#4
0
    def read_sensor(self):
        temp = 0.0
        humi = 0.0

        pi.pinMode(self.pin, pi.OUTPUT)
        pi.digitalWrite(self.pin, pi.HIGH)
        time.sleep(0.05)
        pi.digitalWrite(self.pin, pi.LOW)
        time.sleep(0.02)

        pi.pinMode(self.pin, pi.INPUT)
        pi.pullUpDnControl(self.pin, pi.PUD_UP)

        data = self.collect_input()

        lengths = self.parse_data(data)

        if (len(lengths) != 40):
            return (-1, 0.0, 0.0)

        bit = self.calc_bit(lengths)
        byte = self.bit_to_byte(bit)

        check = byte[0] + byte[1] + byte[2] + byte[3] & 255
        if (byte[4] != check):
            return (-2, 0, 0)

        return (0, byte[2], byte[0])

        return (temp, humi)
示例#5
0
文件: bot.py 项目: ionhedes/ItachiBOT
def setup():
    global pwmL, pwmR
    GPIO.setmode(GPIO.BOARD)
    print("GPIO pin mode was set to GPIO.BOARD")
    GPIO.setup(pinHighL, GPIO.OUT)
    print("Using pin " + str(pinHighL) + " as GPIO.OUT")
    GPIO.setup(pinLowL, GPIO.OUT)
    print("Using pin " + str(pinLowR) + " as GPIO.OUT")
    GPIO.setup(pinHighR, GPIO.OUT)
    print("Using pin " + str(pinHighR) + " as GPIO.OUT")
    GPIO.setup(pinLowR, GPIO.OUT)
    print("Using pin " + str(pinLowR) + " as GPIO.OUT")
    GPIO.setup(pinPwmL, GPIO.OUT)
    print("Using pin " + str(pinPwmL) + " as GPIO.OUT")
    GPIO.setup(pinPwmR, GPIO.OUT)
    print("Using pin " + str(pinPwmR) + " as GPIO.OUT")
    pwmL = GPIO.PWM(pinPwmL, pwmFreq)
    print("Initiated PWM instance on pin " + str(pinPwmL))
    pwmR = GPIO.PWM(pinPwmR, pwmFreq)
    print("Initiated PWM instance on pin " + str(pinPwmR))
    pwmL.start(0)
    print("[PWM] Left speed: 0%")
    pwmR.start(0)
    print("[PWM] Right speed: 0%")
    print("RPi.GPIO setup complete!")
    print("Setting up WiringPi for the line sensors...")
    wp.wiringPiSetupPhys()
    for pin in pinsSensor:
        wp.pullUpDnControl(pin, wp.PUD_DOWN)
    print("WiringPi setup complete!")
示例#6
0
def configureHardware(postMotionEvent, postButtonClickEvent):
    wiringpi.wiringPiSetupGpio()

    # PIR motion detector
    def reportMotion():
        if wiringpi.digitalRead(BCM_PIR) == 1:
            postMotionEvent()

    wiringpi.pinMode(BCM_PIR, wiringpi.GPIO.INPUT)
    wiringpi.pullUpDnControl(BCM_PIR, wiringpi.GPIO.PUD_OFF)
    wiringpi.wiringPiISR(BCM_PIR, wiringpi.GPIO.INT_EDGE_BOTH, reportMotion)

    # Display buttons
    for btnNum, bcmPin in (
                (1, BCM_BTN_1),
                (2, BCM_BTN_2),
                (3, BCM_BTN_3),
            ):
        @debounce(0.02)
        def reportClick(_bcmPin=bcmPin, _btnNum=btnNum):
            if wiringpi.digitalRead(_bcmPin) == 0:
                postButtonClickEvent(_btnNum)

        wiringpi.pinMode(bcmPin, wiringpi.GPIO.INPUT)
        wiringpi.pullUpDnControl(bcmPin, wiringpi.GPIO.PUD_UP)
        wiringpi.wiringPiISR(bcmPin, wiringpi.GPIO.INT_EDGE_BOTH, reportClick)

    # Servos
    wiringpi.pinMode(BCM_SERVO_ACTIVATION, wiringpi.GPIO.OUTPUT)
    wiringpi.pinMode(BCM_SERVO_SPRING, wiringpi.GPIO.OUTPUT)
    wiringpi.pinMode(BCM_SERVO_HOLDER, wiringpi.GPIO.OUTPUT)
示例#7
0
文件: hotword.py 项目: shinhaha/HARU
 def __init__(self):
     self.PUSH_BUTTON = 14
     self.interrupted = False
     self.model = ''.join([os.path.dirname(__file__), '/HARU.pmdl'])
     wiringpi.wiringPiSetupGpio()
     wiringpi.pinMode(self.PUSH_BUTTON, wiringpi.GPIO.INPUT)
     wiringpi.pullUpDnControl(self.PUSH_BUTTON, wiringpi.GPIO.PUD_UP)
示例#8
0
def main():

    print("Program: " + program_path)
    print("")
    p = None  # process holding variable

    wiringpi.wiringPiSetup()
    wiringpi.pinMode(26, 0)  # Pinmode input
    wiringpi.pullUpDnControl(26, 2)  # Internal pullup

    last_prog_sw = None

    running = False

    while True:
        sw_state = prog_sw()
        if sw_state != last_prog_sw:
            time.sleep(0.1)
            sw_state = prog_sw()

            if running == True:
                if sw_state != last_prog_sw and sw_state == 1:
                    print("Starting program...")
                    p = subprocess.Popen(program_path,
                                         shell=True,
                                         preexec_fn=os.setsid)
                else:
                    print("Stopping program!")
                    kill_prog(p)
                    p = None
            elif running == False and sw_state == 0:
                running = True
        last_prog_sw = sw_state
        time.sleep(0.05)
示例#9
0
    def __init__(self,
                 n_address_bits=10,
                 enable_reset=True,
                 support_read=True):
        self.n_address_bits = n_address_bits
        self.support_read = support_read

        wiringpi.wiringPiSetupGpio()
        for i in range(0, n_address_bits):
            wiringpi.pinMode(DP_ADDRPINS[i], WPI_OUT)

        for datapin in DP_DATAPINS:
            wiringpi.pinMode(datapin, WPI_IN)

        wiringpi.pinMode(DP_W, WPI_OUT)
        wiringpi.pinMode(DP_CE, WPI_OUT)

        wiringpi.digitalWrite(DP_W, 1)
        wiringpi.digitalWrite(DP_CE, 1)

        if self.support_read:
            wiringpi.pinMode(DP_R, WPI_OUT)
            wiringpi.digitalWrite(DP_R, 1)

        wiringpi.pinMode(DP_INTR, WPI_IN)
        wiringpi.pullUpDnControl(DP_INTR, 2)

        if (enable_reset):
            wiringpi.pinMode(ISA_RESET, WPI_OUT)
            wiringpi.digitalWrite(ISA_RESET, 0)
示例#10
0
def setup_pi(): 
    print("setup_pi started")
    wiringpi.wiringPiSetupGpio()
    
    for pins in byte1:
        wiringpi.pinMode(pins, 0)
        wiringpi.pullUpDnControl(pins, wiringpi.PUD_DOWN) # PUD_OFF, (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP 
        
    for pins in byte2:
        wiringpi.pinMode(pins, 0)
        wiringpi.pullUpDnControl(pins, wiringpi.PUD_DOWN) # PUD_OFF, (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP 
        
    wiringpi.pinMode(reset, 1)
    wiringpi.digitalWrite(reset, 0);
    
    #wiringpi.pinMode(rclk, 1)
    #wiringpi.digitalWrite(rclk, 0);
    
    for opins in byteSelect:
        wiringpi.pinMode(opins, 1)
        wiringpi.digitalWrite(opins, 1)
       
    wiringpi.pinMode(relay[0], 1)
    wiringpi.pinMode(relay[1], 1)
    wiringpi.digitalWrite(relay[0], 1);
    wiringpi.digitalWrite(relay[1], 1);
    
    wiringpi.digitalWrite(reset, 1);
    wiringpi.delay(1000) # Delay for 1000 useconds
示例#11
0
    def __init__(self, name, pin):
        self.name = name
        self.pin = pin
        self.active = False

        # Save the pin used for this sensor.
        wiringpi.pinMode(self.pin, 0)
        wiringpi.pullUpDnControl(self.pin, 2)
示例#12
0
def gpioinit():
    """
    GPIOの初期化
    """
    wp.wiringPiSetupGpio()
    wp.pinMode(LEDPIN, wp.GPIO.OUTPUT)
    wp.pinMode(SWPIN, wp.GPIO.INPUT)
    wp.pullUpDnControl(SWPIN, wp.GPIO.PUD_UP)
def setup():
    piwiring.wiringPiSetup()
    piwiring.pinMode(SigPin, piwiring.INPUT)
    piwiring.pullUpDnControl(
        SigPin, piwiring.PUD_UP
    )  # Set Pin's mode is input, and pull up to high level(3.3V)
    piwiring.wiringPiISR(SigPin, piwiring.INT_EDGE_RISING,
                         count)  # wait for falling
示例#14
0
def initGPIO():
   try :
      io.wiringPiSetupGpio()
   except :
      print"start IDLE with 'gksudo idle' from command line"
      os._exit(1)
   for pin in range (0,len(pinList)):
      io.pinMode(pinList[pin],0) # make pin into an input
      io.pullUpDnControl(pinList[pin],2) # enable pull up
示例#15
0
 def __init__(self, controls, pin=None, key=None):
     self.pin = pin
     self.key = key
     self.press = Subject()
     self.pressed = False
     if wiringpi:
         wiringpi.pinMode(pin, 0)
         wiringpi.pullUpDnControl(pin, 2)
         self.pressed = 1 - wiringpi.digitalRead(self.pin)
示例#16
0
def init_wiringpi(sCon):

    wiringpi.wiringPiSetup()

    wiringpi.pinMode(sCon.mosipin, 1)
    wiringpi.pinMode(sCon.misopin, 0)
    wiringpi.pinMode(sCon.clkpin,  1)
    wiringpi.pinMode(sCon.cspin,   1)
    wiringpi.pullUpDnControl(sCon.misopin, 0)
示例#17
0
 def pullUpDnControl(self,pud:str):
     try:
         if self.pinmode == INPUT:
             if pud in _dict_:
                 gpio.pullUpDnControl(self.pin,_dict_[pud])
                 return True
     except Exception as e :
         print(str(e))
     return False
示例#18
0
    def __init__(self, serial_interface_path, baudrate,
                 proximity_pin_BCM_number):

        self.serial_interface = serial.Serial(serial_interface_path, baudrate)
        self.proximity_pin_BCM_number = proximity_pin_BCM_number

        wiringpi.wiringPiSetupGpio()
        wiringpi.pinMode(proximity_pin_BCM_number, wiringpi.GPIO.INPUT)
        wiringpi.pullUpDnControl(proximity_pin_BCM_number, wiringpi.PUD_DOWN)
示例#19
0
 def __init__(self, gpio_pin, minimum_delay=0.5):
     volumio_buddy_setup()
     self._callback_function = False
     self._callback_args = False
     self.last_push = 0
     self.minimum_delay = minimum_delay
     self.gpio_pin = gpio_pin
     wiringpi.pinMode(gpio_pin, wiringpi.GPIO.INPUT)
     wiringpi.pullUpDnControl(gpio_pin, wiringpi.GPIO.PUD_OFF)
示例#20
0
def init():
    wiringpi.wiringPiSetupGpio()

    wiringpi.pinMode(PWM_PIN, wiringpi.PWM_OUTPUT)
    wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)
    wiringpi.pwmSetClock(3840)
    wiringpi.pwmSetRange(250)

    wiringpi.pinMode(SPEED_SENSE_PIN, wiringpi.INPUT)
    wiringpi.pullUpDnControl(SPEED_SENSE_PIN, PUD_DOWN)
示例#21
0
 def __init__(self, door_close_event_callback, door_open_event_callback):
     threading.Thread.__init__(self)
     self.closed = True
     self.door_pin_number = 29
     self.last_closure = time.time()
     self.door_close_event_callback = door_close_event_callback
     self.door_open_event_callback = door_open_event_callback
     # use pin 29 as door sensor (active LOW)
     wpi.pinMode(self.door_pin_number, wpi.INPUT)
     wpi.pullUpDnControl(self.door_pin_number, wpi.PUD_UP)
示例#22
0
 def WiringPiInit(self):
     '''
     WiringPiの初期化
     '''
     # BCMモードで初期化
     wiringpi.wiringPiSetupGpio()
     # IoExpICのINT出力監視先ポートの設定
     wiringpi.pinMode(c.GPIO_I2CINT_IN, wiringpi.GPIO.INPUT)
     # プルアップの設定
     wiringpi.pullUpDnControl(c.GPIO_I2CINT_IN, wiringpi.GPIO.PUD_UP)
示例#23
0
    def __init__(self, pin):
        super(WiringPiPump, self).__init__(pin)

        # wiringpi.wiringPiSetupGpio()
        wiringpi.wiringPiSetupPhys()

        wiringpi.pinMode(pin, wiringpi.GPIO.INPUT)
        wiringpi.pullUpDnControl(
            pin, wiringpi.GPIO.PUD_OFF)  # use external pull-down resistor
        wiringpi.wiringPiISR(pin, wiringpi.GPIO.INT_EDGE_BOTH, self.event)
示例#24
0
 def __init__(self, remotedef, radio_data_pin=17):
     """ Initialize the remote control with it's commands and the GPIO
         pin on which the radio is connected
     """
     self.radio_data_pin = radio_data_pin
     self.commands = remotedef['symbols']
     self.resend_delay_us = remotedef['parms']['inter_packet_gap_us']
     self.repeat_count = remotedef['parms']['repeat_count']
     wiringpi.wiringPiSetupGpio()
     wiringpi.pinMode(radio_data_pin, wiringpi.INPUT)
     wiringpi.pullUpDnControl(radio_data_pin, wiringpi.PUD_DOWN)
示例#25
0
def init():
	#BCM numbering
	wp.wiringPiSetupGpio()
	wp.pinMode(22, 0)#input
	wp.pullUpDnControl(22, wp.PUD_UP)

	wp.pinMode(11, 0)
	wp.pullUpDnControl(11, wp.PUD_UP)

	if ser.isOpen() == False:
		ser.open()
示例#26
0
def setupTacho():
	global rpmChkStartTime

	print("Setting up Tacho input pin")
	wiringpi.wiringPiSetupGpio()
	wiringpi.pinMode(tachoPin,wiringpi.INPUT)
	wiringpi.pullUpDnControl(tachoPin,wiringpi.PUD_UP)
	rpmChkStartTime=time.time()
	#print("{:4d}".format(wiringpi.INT_EDGE_FALLING))
	wiringpi.wiringPiISR(tachoPin,wiringpi.INT_EDGE_FALLING,tachoISR)
	return
示例#27
0
 def __init__(self):
     try:
         # ヒット検知用スイッチのピン番号をコンフィグから取得
         self.SW_PIN = int(ci.hit_switch_pin)
         pi.pinMode(self.SW_PIN, pi.INPUT)
         pi.pullUpDnControl(self.SW_PIN, pi.PUD_DOWN)
         self.hit_deadline = int(ci.hit_deadline)
     except:
         err = "ヒット検知用スイッチピンの初期設定に失敗.\n"
         log.logging.error(err + traceback.format_exc())
         raise
示例#28
0
    def __init__(self, name: str, control_pin: int, sensor: BaseSensor):
        if 1 <= control_pin <= 40:
            self._control_pin = control_pin
            # set control pin as output
            wiringpi.pinMode(self._control_pin, wiringpi.OUTPUT)
            # set pulldown resistor
            wiringpi.pullUpDnControl(self._control_pin, wiringpi.PUD_DOWN)
            self._state = HeaterController.State.COOLING
        else:
            raise ValueError("Control pin must be an integer in the range [0, 40]")

        self._sensor = sensor
        super().__init__(name)
示例#29
0
def setup():
    global pwmValue
    print "Setup Starting"
    wpi.wiringPiSetup()
    for pin in inputPins:
        wpi.pinMode(pin, wpi.INPUT)
    wpi.pullUpDnControl(pSW, wpi.PUD_UP)
    wpi.pinMode(pSideLight, wpi.OUTPUT)
    wpi.digitalWrite(pSideLight, sideLightsOn)
    wpi.pinMode(pPWM, wpi.PWM_OUTPUT)
    pwmValue = 0
    wpi.pwmWrite(pPWM, pwmValue)
    rotaryButtonSetup()
示例#30
0
    def __init__(self):
        if os.getuid():
            raise RuntimeError("MotorDriver can only be used by sudoer.")
        super(MotorDriver, self).__init__()
        for pin in self.OUTPUT_PINS:
            wiringpi.pinMode(pin, wiringpi.OUTPUT)

        for pin in self.PWM_OUTPUTS:
            wiringpi.pinMode(pin, wiringpi.PWM_OUTPUT)

        for pin in self.INPUT_PINS:
            wiringpi.pinMode(pin, wiringpi.INPUT)
            # Make sure all annex_pin are set LOW
            wiringpi.pullUpDnControl(pin, wiringpi.PUD_DOWN)
示例#31
0
    def init(self):
        wiringpi.wiringPiSetupGpio()
    
        wiringpi.pinMode(self.MOTOR_A, wiringpi.GPIO.OUTPUT)
        wiringpi.pinMode(self.MOTOR_B, wiringpi.GPIO.OUTPUT)

        wiringpi.pullUpDnControl(self.MOTOR_A, wiringpi.GPIO.PUD_UP)
        wiringpi.pullUpDnControl(self.MOTOR_B, wiringpi.GPIO.PUD_UP)
    
        wiringpi.pinMode(self.RUL, wiringpi.GPIO.PWM_OUTPUT)
    
        wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
        wiringpi.pwmSetClock(192)
        wiringpi.pwmSetRange(2000)
示例#32
0
def init():
    wiringpi.wiringPiSetupGpio()

    for p in (LOOP_ENABLE, LOOP_DISABLE, FRONTEND_RESET, FRONTEND_RX_ENABLE,
              FRONTEND_SAMPLE_HOLD, LED_RED, LED_GREEN):
        wiringpi.pinMode(p, wiringpi.OUTPUT)
        wiringpi.digitalWrite(p, 0)

    wiringpi.pinMode(LOOP_STATUS, wiringpi.INPUT)
    wiringpi.pullUpDnControl(LOOP_STATUS, wiringpi.PUD_UP)

    frontendReset()

    loop(False)
示例#33
0
文件: inputs.py 项目: rm-hull/HD44780
    def __init__(self, ui, pinmap):
        if not isinstance(ui.display.backend, GPIOBackend):
            raise NotImplementedError("The GPIO input module can only be used with the GPIO backend.")

        self.key_pressed = False

        import wiringpi
        self.ui = ui
        self.gpio = self.ui.display.backend.gpio
        self.reverse_pinmap = dict([(value, key) for key, value in pinmap.iteritems()])
        for pin, output in pinmap.iteritems():
            setattr(self, 'PIN_%s' % pin, output)
            is_input = pin in ('UP', 'LEFT', 'OK', 'RIGHT', 'DOWN')
            self.gpio.pinMode(output, self.gpio.INPUT if is_input else self.gpio.OUTPUT)
            if is_input:
                wiringpi.pullUpDnControl(output, wiringpi.PUD_UP)
示例#34
0
 def __init__(self, callback):
     log.debug('GpioButtons.__init__')
     wiringpi.wiringPiSetupGpio()
     self.debounce = dict()
     self.debounce_time = fire_pong.util.config['InputManager']['gpio']['debounce_time']
     self.callback = callback
     for action in ['quit', 'start', 'swipe1', 'swipe2']:
         try:
             pin = fire_pong.util.config['InputManager']['gpio'][action]
             wiringpi.pinMode(pin, wiringpi.GPIO.INPUT)
             wiringpi.pullUpDnControl(pin, wiringpi.GPIO.PUD_UP)
             wiringpi.wiringPiISR(pin, wiringpi.GPIO.INT_EDGE_FALLING, getattr(self, action))
             self.debounce[action] = 0
             log.debug('GpioButtons.__init__() %s => pin %s' % (action, pin))
             
         except KeyError as e:
             log.warning('GpioButtons.__init__(): %s' % e)
             pass
示例#35
0
文件: main.py 项目: darkomen/Python
def setup_gpio():
  wiringpi.wiringPiSetup()
  # Set pin directions.
# outputs :
  for pin in [DIN, SCLK, DC, RST, SCE]:
    wiringpi.pinMode(pin, OUT)
# inputs :
  for pin in [UP, RIGHT, DOWN, LEFT, SELECT]:
    wiringpi.pinMode(pin, IN)
 
# enable pull downs for the switches
  wiringpi.pullUpDnControl(UP, wiringpi.PUD_DOWN)
  wiringpi.pullUpDnControl(RIGHT, wiringpi.PUD_DOWN)
  wiringpi.pullUpDnControl(DOWN, wiringpi.PUD_DOWN)
  wiringpi.pullUpDnControl(LEFT, wiringpi.PUD_DOWN)
  wiringpi.pullUpDnControl(SELECT, wiringpi.PUD_DOWN)
 
  wiringpi.pinMode(LED,2) # pwm mode
  wiringpi.pwmWrite(LED,128) # mid-level
示例#36
0
文件: color.py 项目: macole/note
red = 0
blue = 0
green = 0
select = 0

SPI_CH = 0
READ_CH = 0

pi.wiringPiSetupGpio()
pi.pinMode( green_pin, 1 )
pi.pinMode( blue_pin, 1 )
pi.pinMode( red_pin, 1 )

pi.pinMode( button_pin, 0 )
pi.pullUpDnControl( button_pin, 2 )

pi.softPwmCreate( green_pin, 0, 100 )
pi.softPwmCreate( blue_pin, 0, 100 )
pi.softPwmCreate( red_pin, 0, 100 )

mcp3002 = mcp3002( pi, SPI_CH )

while True:
	if ( pi.digitalRead( button_pin ) == 0 ):
		time.sleep( 0.01 )
		if ( select == 0 ):
			select = 1
			print( "Control Green." )
		elif ( select == 1 ):
			select = 2
示例#37
0
#Define sensor type (DHT22) and GPIO number
SENSOR = 22
PIN = 4

#Define GPIO relay
PIN_WIRE = 18
PIN_FAN = 23
ON = 1
OFF = 0

#Calibrate DHT22
DHT_CAL = 0.6

wiringpi.wiringPiSetupGpio()
wiringpi.pullUpDnControl(PIN_FAN, OFF)  
wiringpi.pullUpDnControl(PIN_WIRE, OFF)

#Define log file
logging.basicConfig(filename='/var/log/inkoutpi.log', 
                    level=logging.DEBUG, 
                    format='%(asctime)s %(levelname)s: %(message)s',
                    datefmt='%d/%m/%Y %I:%M:%S')

# Define temperature/humidity range
TEMP_MAX = 32.10
TEMP_MIN = 32.00
HUMI_MIN = 70.00


# Try to grab a sensor reading.  Use the read_retry method which will retry up
示例#38
0
import wiringpi as pi
import time

DIP_PIN = [14, 15, 23, 24]

STATE = ["ON", "OFF"]

dip = [0, 0, 0, 0]

pi.wiringPiSetupGpio()

for i in DIP_PIN:
    pi.pinMode(i, pi.INPUT)
    pi.pullUpDnControl(i, pi.PUD_UP)

while True:
    i = 0
    while i < len(DIP_PIN):
        dip[i] = pi.digitalRead(DIP_PIN[i])
        i = i + 1
    print("DIP1:", STATE[ dip[0] ], " DIP2:", STATE[ dip[1] ], " DIP3:", STATE[ dip[2] ], " DIP4:", STATE[ dip[3] ])
    time.sleep(1)
示例#39
0
文件: led.py 项目: macole/note
import wiringpi as pi, time

switch_mode_time = 15
blank_time = 10

led_pin = 23
sw_pin = 17

pi.wiringPiSetupGpio()
pi.pinMode( led_pin, 1 )

pi.pinMode( sw_pin, 0 )
pi.pullUpDnControl( sw_pin, 2)

last_time = 0
before_sw = 0
mode = 0
sw_mode = 1
led = 0
data = [ 1, blank_time ]
count = 0

while True:
	now_time = time.time()

	if ( mode == 0 ):
		if ( pi.digitalRead( sw_pin ) == 0 ):
			time.sleep( 0.01 )
			pi.digitalWrite( led_pin, 0 )
			mode = 1
			last_time = now_time
示例#40
0
def goodbye():
    print "You are now leaving readCapSensAndPlaySounds.py"
    s.mixer.quit()

print "Start reading..."

while 1:
	repeats = 2
	total = 0.0

	for i in range(0, repeats):
		io.pinMode(pin, io.OUTPUT)
		io.digitalWrite(pin, io.LOW)
		
		io.pinMode(pin, io.INPUT)
		io.pullUpDnControl(pin, io.PUD_OFF)
	
		maxCycles = 1000
		cycles = 0
		
		while (cycles<maxCycles and io.digitalRead(pin)==0):
			cycles += 1
		total += cycles
	mean = total / repeats

	print mean

	if(mean < 10): 
		print ">>>>>>>>>>>>>  Touched! " + str(mean)
		if(not s.mixer.music.get_busy()):
			s.mixer.music.play()
示例#41
0
def reset_ports():                          # resets the ports for a safe exit
    wiringpi.pullUpDnControl(22, wiringpi.PUD_OFF) #unset pullup on button port
    wiringpi.pinMode(button,0)              # set button port to input mode
    wiringpi.pinMode(red_led,0)             # set red led port to input mode
    wiringpi.pinMode(yellow_led,0)          # set yellow led port to input mode
    wiringpi.pinMode(green_led,0)           # set red led port to input mode
示例#42
0
def setup_wiringpi(args):
    import wiringpi
    wiringpi.wiringPiSetupGpio()
    wiringpi.pinMode(args.pinin, 0)
    wiringpi.pullUpDnControl(args.pinin, 1)
    wiringpi.wiringPiISR(args.pinin, wiringpi.INT_EDGE_RISING, callback_wiringpi)
示例#43
0
# GPIO初期化
wiringpi.wiringPiSetupGpio()

# ボタンスイッチを入力モード(0)に設定
wiringpi.pinMode( button_pin  , 0 )

# モータードライバーは出力モード(1)に設定
wiringpi.pinMode( motor1_pin, 1 )
wiringpi.pinMode( motor2_pin, 1 )


# 端子に何も接続されていない場合の状態を設定
# 3.3Vの場合には「2」(プルアップ)
# (0Vの場合は「1」と設定する(プルダウン))
wiringpi.pullUpDnControl( button_pin  , 2 )

# whileの処理は字下げをするとループの範囲になる
while True:
    # GPIO端子の状態を読み込む
    # ボタンを押すと直進
    # GPIOの状態が0V(0)であるか比較
    if( wiringpi.digitalRead(button_pin) == 1 ):
        # ボタンを離している時は「3.3V(1)」
        # (1の場合に停止というのもわかりにくい)
        print ("停止")
        # モーターを停止
        wiringpi.digitalWrite( motor1_pin, 1 )
        wiringpi.digitalWrite( motor2_pin, 0 )
    else:
        # ボタンを押している時は「0V(0)」
示例#44
0
#!/usr/bin/env python2.7
# Python 2.7 version by Alex Eames of http://RasPi.TV 
# functionally equivalent to the Gertboard buttons test 
# by Gert Jan van Loo & Myra VanInwegen
# Use at your own risk - I'm pretty sure the code is harmless, 
# but check it yourself.

import wiringpi

wiringpi.wiringPiSetupGpio()                        # initialise wiringpi
for port_num in range(23,26):
    wiringpi.pinMode(port_num, 0)                   # set up ports for input
    wiringpi.pullUpDnControl(port_num, wiringpi.PUD_UP) #set pullups

def reset_ports():                          # resets the ports for a safe exit
    for i in range(23,26):
        wiringpi.pinMode(i,0)               # set ports to input mode

print "These are the connections for the buttons test:" # Print Instructions
print "GP25 in J2 --- B1 in J3"
print "GP24 in J2 --- B2 in J3"
print "GP23 in J2 --- B3 in J3"
print "Optionally, if you want the LEDs to reflect button state do the following:"
print "jumper on U3-out-B1"
print "jumper on U3-out-B2"
print "jumper on U3-out-B3"
raw_input("When ready hit enter.\n")

button_press = 0                            # set intial values for variables
previous_status = ''
示例#45
0
 def __init__(self):
     wp.wiringPiSetupGpio()
     wp.pinMode(22, 0)
     wp.pullUpDnControl(22, 2)
示例#46
0
# GPIOを制御するライブラリ
import wiringpi

# タイマーのライブラリ
import time

# GPIO端子の設定
hall_switch_pin = 17

# GPIO出力モードを1に設定する
wiringpi.wiringPiSetupGpio()
# GPIOを入力モード(0)にする
wiringpi.pinMode(hall_switch_pin, 0)
# 入力はプルアップに設定
wiringpi.pullUpDnControl(hall_switch_pin, 2)

while True:
    # GPIO端子の状態を読み込み
    # S極 : 0
    # N極 : 1
    if wiringpi.digitalRead(hall_switch_pin) == 1:
        # 入力が0の時がS極
        print("South Pole")
    else:
        print("North Pole")
    # 1秒ごとに検出# 出力が1の時がN極
    time.sleep(1)
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# -----------------------------------------------------------------------------


# Import dependancies
from config import *
import wiringpi                                              # Source: https://github.com/WiringPi/WiringPi-Python

wiringpi.wiringPiSetup()                                     # Set WiringPi ports. See http://wiringpi.com/pins/

wiringpi.pinMode(button1, 0)                                 # Set button1 to input mode
wiringpi.pullUpDnControl(button1, 2)                         # Set pull-up

wiringpi.pinMode(button2, 0)                                 # Set button2 to input mode
wiringpi.pullUpDnControl(button2, 2)                         # Set pull-up

wiringpi.pinMode(ac_detect_port_1, 0)                        # Set ac_detect_port_1 to input mode
wiringpi.pullUpDnControl(ac_detect_port_1, 1)                # Set pull-down

wiringpi.pinMode(ac_detect_port_2, 0)                        # Set ac_detect_port_2 to input mode
wiringpi.pullUpDnControl(ac_detect_port_2, 1)                # Set pull-down

wiringpi.pinMode(motor_pwr, 1)                               # Set motor_pwr to output mode
wiringpi.pinMode(motor_relay, 1)                             # Set motor_relay to output mode
wiringpi.pinMode(buffer1, 1)                                 # Set buffer1 to output mode
wiringpi.pinMode(buffer2, 1)                                 # Set buffer2 to output mode
wiringpi.pinMode(buffer3, 1)                                 # Set buffer3 to output mode
示例#48
0
import wiringpi
INPUT = 0
OUTPUT = 1
LOW = 0
HIGH = 1
BUTTONS = [13,12,10,11]
LEDS = [0,1,2,3,4,5,6,7,8,9]
PUD_UP = 2

wiringpi.wiringPiSetup()

for button in BUTTONS:
	wiringpi.pinMode(button,INPUT)
	wiringpi.pullUpDnControl(button,PUD_UP)

for led in LEDS:
	wiringpi.pinMode(led,OUTPUT)

while 1:
	for index,button in enumerate(BUTTONS):
		button_state = wiringpi.digitalRead(button)
		first_led = LEDS[index*2]
		second_led = LEDS[(index*2)+1]
		#print str(button) + ' ' + str(button_state)
		wiringpi.digitalWrite(first_led,1-button_state)
		wiringpi.digitalWrite(second_led,1-button_state)
	wiringpi.delay(20)
示例#49
0
文件: camera.py 项目: macole/note
import wiringpi as pi, time
import picamera

inv_time = 300
wait_time = 1

save_dir = "/home/pi/camera/"

hl_pin = 17

camera = picamera.PiCamera()
camera.resolution = ( 1920 , 1080 )

pi.wiringPiSetupGpio()
pi.pinMode( hl_pin, 0 )
pi.pullUpDnControl( hl_pin, 2)

cap_time = 0

while True:
	now_time = round( time.time() )
	if ( pi.digitalRead( hl_pin ) == 1 ):
		if ( now_time > cap_time + inv_time ):
			save_file = save_dir + time.strftime("%Y%m%d%H%M%S") + ".jpg"
			camera.capture( save_file )
			cap_time = now_time
			print ( "capture:", save_file )

	time.sleep( wait_time )
示例#50
0
import wiringpi as pi
import time
import subprocess

SW_PIN = 15

pi.wiringPiSetupGpio()
pi.pinMode(SW_PIN, pi.INPUT)
pi.pullUpDnControl(SW_PIN, pi.PUD_DOWN)


def timer():
    start = time.time()
    print('init time')
    print('start', start)
    def diff():
        nonlocal start
        return time.time() - start
    return diff


prevtime = {}
def check_chattering(timekey):
    global prevtime
    if prevtime.get(timekey) == None:
        prevtime[timekey] = time.time() - 10
    currenttime = time.time()
    diff = currenttime - prevtime[timekey]
    prevtime[timekey] = currenttime

    if diff <= 0.01:
示例#51
0
import wiringpi
PIN_TO_SENSE = 23

def gpio_callback():
    print "GPIO_CALLBACK!"

wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(PIN_TO_SENSE, wiringpi.GPIO.INPUT)
wiringpi.pullUpDnControl(PIN_TO_SENSE, wiringpi.GPIO.PUD_UP)

wiringpi.wiringPiISR(PIN_TO_SENSE, wiringpi.GPIO.INT_EDGE_BOTH, gpio_callback)

while True:
    wiringpi.delay(2000)
示例#52
0
文件: rele.py 项目: rbioque/inKoutPi
	def __init__(self):
		wiringpi.wiringPiSetupGpio()
		wiringpi.pullUpDnControl(PIN_FAN, OFF)
		wiringpi.pullUpDnControl(PIN_WIRE, OFF)
示例#53
0
import wiringpi as wiringpi
from time import sleep

pin_base = 65  # lowest available starting number is 65
i2c_addr = 0x20  # A0, A1, A2 pins all wired to GND

wiringpi.wiringPiSetup()  # initialise wiringpi
wiringpi.mcp23017Setup(pin_base, i2c_addr)  # set up the pins and i2c address

wiringpi.pinMode(65, 1)  # sets GPA0 to output
wiringpi.digitalWrite(65, 0)  # sets GPA0 to 0 (0V, off)

wiringpi.pinMode(80, 0)  # sets GPB7 to input
wiringpi.pullUpDnControl(80, 2)  # set internal pull-up

# Note: MCP23017 has no internal pull-down, so I used pull-up and inverted
# the button reading logic with a "not"

try:
    while True:
        wiringpi.digitalWrite(65, 1)  # sets port GPA1 to 1 (3V3, on)
        sleep(1)
        wiringpi.digitalWrite(65, 0)  # sets port GPA1 to 0 (0V, off)
        sleep(1)
finally:
    wiringpi.digitalWrite(65, 0)  # sets port GPA1 to 0 (0V, off)
    wiringpi.pinMode(65, 0)  # sets GPIO GPA1 back to input Mode
    # GPB7 is already an input, so no need to change anything
示例#54
0
 def pullUp(self):
     wiringpi.pullUpDnControl(self.pin, wiringpi.PUD_UP)
示例#55
0
import wiringpi
import sys
from time import sleep
#board_type = sys.argv[-1]

button = 25
red_led = 24
yellow_led = 23
green_led = 22
led_ON  = 1
led_OFF = 0

# initialise all ports first
wiringpi.wiringPiSetupGpio()        # initialise wiringpi to use BCM_GPIO port numbers
wiringpi.pinMode(button, 0)         # set up button port for input
wiringpi.pullUpDnControl(button, wiringpi.PUD_UP)   # set button port as pullup
wiringpi.pinMode(red_led, 1)        # set up red LED port for output
wiringpi.pinMode(yellow_led, 1)     # set up yellow LED port for output    
wiringpi.pinMode(green_led, 1)      # set up green LED port for output
wiringpi.digitalWrite(red_led, led_OFF)     # make sure red led is off to start
wiringpi.digitalWrite(yellow_led, led_OFF)  # make sure yellow led is off to start
wiringpi.digitalWrite(green_led, led_OFF)   # make sure green led is off to start

def reset_ports():                          # resets the ports for a safe exit
    wiringpi.pullUpDnControl(22, wiringpi.PUD_OFF) #unset pullup on button port
    wiringpi.pinMode(button,0)              # set button port to input mode
    wiringpi.pinMode(red_led,0)             # set red led port to input mode
    wiringpi.pinMode(yellow_led,0)          # set yellow led port to input mode
    wiringpi.pinMode(green_led,0)           # set red led port to input mode

# wait for the button to be pressed
示例#56
0
def reset_ports():                      # resets the ports for a safe exit
    wiringpi.pinMode(22,0)              # set ports to input mode
    wiringpi.pinMode(24,0)
    wiringpi.pullUpDnControl(23, wiringpi.PUD_OFF) #unset pullup
示例#57
0
#!/usr/bin/env python2.7
# Python 2.7 version by Alex Eames of http://RasPi.TV 
# functionally equivalent to the Gertboard butled test 
# by Gert Jan van Loo & Myra VanInwegen
# Use at your own risk - I'm pretty sure the code is harmless, 
# but check it yourself.
import wiringpi

wiringpi.wiringPiSetupGpio()                # initialise wiringpi
wiringpi.pinMode(22, 0)                     # set up ports for input
wiringpi.pinMode(24, 0)
wiringpi.pullUpDnControl(23, wiringpi.PUD_UP)   # set port 23 pull-up 

def reset_ports():                      # resets the ports for a safe exit
    wiringpi.pinMode(22,0)              # set ports to input mode
    wiringpi.pinMode(24,0)

print "These are the connections you must make on the Gertboard for this test:"
print "GP23 in J2 --- B3 in J3"
print "GP22 in J2 --- B6 in J3"
print "U3-out-B3 pin 1 --- BUF6 in top header"
print "jumper on U4-in-B6"
raw_input("When ready hit enter.\n")

button_press = 0                          # set intial values for variables
previous_status = ''

try:
    while button_press < 20:  # read inputs constantly until 19 changes are made
        status_list = [wiringpi.digitalRead(23), wiringpi.digitalRead(22)]
        for i in range(0,2):
示例#58
0
def reset_ports():                          # resets the ports for a safe exit
    for i in range(23,26):
        wiringpi.pinMode(i,0)               # set ports to input mode
        wiringpi.pullUpDnControl(i, wiringpi.PUD_OFF) #unset pullups