Python RPi.GPIO 模块,setmode() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用RPi.GPIO.setmode()

项目:rainbow-hat    作者:pimoroni    | 项目源码 | 文件源码
def show():
    """Output the buffer"""
    global _gpio_setup

    if not _gpio_setup:
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup([DAT,CLK,CS],GPIO.OUT)
        _gpio_setup = True

    GPIO.output(CS, 0)
    _sof()

    for pixel in pixels:
        r, g, b, brightness = pixel
        _write_byte(0b11100000 | brightness)
        _write_byte(b)
        _write_byte(g)
        _write_byte(r)

    _eof()
    GPIO.output(CS, 1)
项目:raspi-photo-booth    作者:kriskbx    | 项目源码 | 文件源码
def setup():
    if os.path.isdir(ImagePath) == False:
        os.mkdir(ImagePath, 0777)

    try:
        GPIO.cleanup()
    finally:
        pass

    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(BeepPin, GPIO.OUT)
    GPIO.setup(LedPin, GPIO.OUT)
    GPIO.setup(ButtonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    ledOn()
    beepOn()
    time.sleep(0.1)
    ledOff()
    beepOff()

# Loop, wait for button press
项目:RaspberryPi-Robot    作者:timestocome    | 项目源码 | 文件源码
def __init__(self):

        gpio.setmode(gpio.BOARD)

        # set up  and init 
        self.trigger = 13
        self.echo = 11

        gpio.setup(self.trigger, gpio.OUT)
        gpio.setup(self.echo, gpio.IN)

        self.pulse_start = 0.
        self.pulse_end = 0.
        self.speed_of_sound = 343 * 100
        self.max_distance = 100
        self.min_distance = 1
项目:RaspberryPi-Robot    作者:timestocome    | 项目源码 | 文件源码
def __init__(self):

        print('init robot gpio')
        # set up hardware
        gpio.setmode(gpio.BOARD)        # use pin numbers not gpio numbers


        # wheels ( 4 wheel motors )
        self.reverse_left = 38
        self.reverse_right = 35
        self.forward_left = 40
        self.forward_right = 37

        gpio.setup(self.reverse_left, gpio.OUT)  
        gpio.setup(self.forward_left, gpio.OUT)  
        gpio.setup(self.forward_right, gpio.OUT) 
        gpio.setup(self.reverse_right, gpio.OUT) 

        self.wheel_pulse = 0.2
        #self.actions = ['forward', 'reverse', 'turn_left', 'turn_right', 'hard_left', 'hard_right']
        self.actions = ['forward', 'reverse', 'hard_left', 'hard_right']
项目:photobooth    作者:eoghan-c    | 项目源码 | 文件源码
def set_up_gpio(self):
        GPIO.setmode(GPIO.BCM)
        #GPIO.setup(camera_led_pin, GPIO.OUT, initial=False) # Set GPIO to output
        GPIO.setup(config.led_pin_select,GPIO.OUT) # The 'Select' button LED
        GPIO.setup(config.led_pin_left,GPIO.OUT) # The 'Left' button LED
        GPIO.setup(config.led_pin_right,GPIO.OUT) # The 'Right' button LED

        # Detect falling edge on all buttons
        GPIO.setup(config.button_pin_select, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(config.button_pin_left, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(config.button_pin_right, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(config.button_pin_exit, GPIO.IN, pull_up_down=GPIO.PUD_UP)

        # Drumminhands found it necessary to switch off LEDs initially
        GPIO.output(config.led_pin_select, False)
        GPIO.output(config.led_pin_left, False)
        GPIO.output(config.led_pin_right, False)
项目:nfcmusik    作者:ehansis    | 项目源码 | 文件源码
def __init__(self, dev='/dev/spidev0.0', speed=1000000, pin_rst=22, pin_ce=0):
        self.pin_rst = pin_rst
        self.pin_ce = pin_ce

        SPI.openSPI(device=dev, speed=speed)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(pin_rst, GPIO.OUT)
        GPIO.output(pin_rst, 1)
        if pin_ce != 0:
            GPIO.setup(pin_ce, GPIO.OUT)
            GPIO.output(pin_ce, 1)
        self.reset()
        self.dev_write(0x2A, 0x8D)
        self.dev_write(0x2B, 0x3E)
        self.dev_write(0x2D, 30)
        self.dev_write(0x2C, 0)
        self.dev_write(0x15, 0x40)
        self.dev_write(0x11, 0x3D)
        self.set_antenna(True)
项目:pi-thrum    作者:arosspope    | 项目源码 | 文件源码
def __GPIOInit(self):
        """
        Initialises the GPIO pins for the pi
        (tested on the Pi3 Model B+)
        """
        # Set mode PIN numbering to BCM, and define GPIO pin functions
        GPIO.setmode(GPIO.BCM)

        # Setup Function for input Pins
        inputBNTs = (self.__soundBNTs + self.__stepBNTs)
        inputBNTs.append(self.__playBNT)
        inputBNTs.append(self.__recBNT)

        for b in inputBNTs:
            GPIO.setup(b, GPIO.IN, pull_up_down=GPIO.PUD_UP)

        # Func for ouput Pins
        GPIO.setup(self.__LED, GPIO.OUT)
项目:waterflowers    作者:chaodalong    | 项目源码 | 文件源码
def send_gpio_order(param):
    """
    GPIO????
    type in(GPIO.IN) out(GPIO.OUT)
    value 1 GPIO.HIGH 0 GPIO.LOW
    :param param:
    :return:
    """
    print param
    channel, type, value = param
    try:
        import RPi.GPIO as GPIO
    except RuntimeError:
        print("????")
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)

    if type == 'in':
        GPIO.setup(channel, GPIO.IN)
        GPIO.input(channel, value)
    else:
        GPIO.setup(channel, GPIO.OUT)
        GPIO.output(channel, value)
项目:BH1750    作者:ElJulio    | 项目源码 | 文件源码
def init(self,bitrate,SDAPIN,SCLPIN):
        if(SDAPIN != SCLPIN):
            self.SCL = SCLPIN
            self.SDA = SDAPIN

        else:
            print "SDA = GPIO"+str(self.SDA)+"  SCL = GPIO"+str(self.SCL)

        #configer SCL as output
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(self.SCL, GPIO.OUT)
        GPIO.setup(self.SDA, GPIO.OUT)
        GPIO.output(self.SDA, GPIO.HIGH)
        GPIO.output(self.SCL, GPIO.HIGH)


        if bitrate == 100:
            self.int_clk = 0.0000025
        elif bitrate == 400:
            self.int_clk = 0.000000625
        elif bitrate == 1000:
            self.int_clk = 1
        elif bitrate == 3200:
            self.int_clk = 1
项目:SmartDoorControl    作者:xiaokaizh    | 项目源码 | 文件源码
def signalDoorBell():
    global doorBell
    global belli
    global bellSum
    global previousDoorBell
    global GPIO_doorBell
    global GPIO_bell
    if belli != 15:
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(GPIO_doorBell, GPIO.IN)
        bellSum = bellSum + GPIO.input(GPIO_doorBell)
        belli += 1
    else:
        belli = 0
        if bellSum >= 15:
            doorBell = 1
        else:
            doorBell = 0
        if doorBell != previousDoorBell:
            previousDoorBell = doorBell
            DeviceControl.doorBell(doorBell)
            print("Dang qian doorBell %s" % doorBell)
        bellSum = 0
项目:SmartDoorControl    作者:xiaokaizh    | 项目源码 | 文件源码
def signalshock():
        global shocki
        global shockSum
        global shock
        global GPIO_shock
        if shocki != 5:
            GPIO.setmode(GPIO.BOARD)
            GPIO.setup(GPIO_shock, GPIO.IN)
            shockSum = shockSum+GPIO.input(GPIO_shock)
            shocki += 1
        else:
            shocki = 0
            if shockSum >=2:
                shock = 1
            else:
                shock = 0
            global previousShock
            if shock != previousShock:
                previousShock = shock
                print("Dang qian shock %s" % shock)
            shockSum = 0
项目:SmartDoorControl    作者:xiaokaizh    | 项目源码 | 文件源码
def signaliR():
        global iRi
        global iRSum
        global iR
        global GPIO_iR
        if iRi != 5:
            GPIO.setmode(GPIO.BOARD)
            GPIO.setup(GPIO_iR, GPIO.IN)
            iRSum = iRSum+GPIO.input(GPIO_iR)
            iRi += 1
        else:
            iRi = 0
            if iRSum >= 2:
                iR = 1
            else:
                iR = 0
            global previousIR
            if iR != previousIR:
                previousIR = iR
                print("Dang qian IR %s"%iR)
            iRSum = 0
            IRStateMachine.stateJudge(iR)


# ??????
项目:burro    作者:yconst    | 项目源码 | 文件源码
def __init__(self, channel, invert=False):
        from navio import adafruit_pwm_servo_driver as pwm
        from navio import util
        import RPi.GPIO as GPIO
        util.check_apm()

        #Navio+ requires the GPIO line 27 to be set to low 
        #before the PCA9685 is accesed 
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(27, GPIO.OUT)
        GPIO.output(27,GPIO.LOW)

        #GPIO.cleanup()
        self.frequency = 60
        self.channel = channel
        self.invert = invert
        self.pwm = pwm.PWM()
        self.pwm.setPWMFreq(self.frequency)
项目:red-phone    作者:mixmasteru    | 项目源码 | 文件源码
def __init__(self, ready):
        Thread.__init__(self)
        self.ready = ready
        self.picked_up = False
        self.on = True
        self._ringer1 = 11
        self._ringer2 = 13
        self._button = 7

        GPIO.setmode(GPIO.BOARD)
        GPIO.setwarnings(False)
        GPIO.setup(self._ringer1, GPIO.OUT)
        GPIO.output(self._ringer1, GPIO.LOW)
        GPIO.setup(self._ringer2, GPIO.OUT)
        GPIO.output(self._ringer2, GPIO.LOW)
        GPIO.setup(self._button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

        self._last_state = 0
        self._last_ts = time.time()
        self._last_check = time.time()
        self._ring = 1
        self.max_ring_cnt = 2
项目:rpi-film-capture    作者:jphfilm    | 项目源码 | 文件源码
def __init__(self):
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.dir_pin, GPIO.OUT)
        GPIO.setup(self.pulse_pin, GPIO.OUT)
        GPIO.setup(self.ms1_pin, GPIO.OUT)
        GPIO.setup(self.ms2_pin, GPIO.OUT)
        GPIO.setup(self.sleep_pin, GPIO.OUT)
        GPIO.setup(self.reset_pin, GPIO.OUT)
        dir=False
        GPIO.output(self.dir_pin, dir)
        GPIO.output(self.pulse_pin, False)
        GPIO.output(self.ms1_pin, True)
        GPIO.output(self.ms2_pin, False)
        GPIO.output(self.sleep_pin, False)
        GPIO.output(self.reset_pin, True)
        self.p1 = GPIO.PWM(self.pulse_pin, self.pulse_freq)
项目:raspberry-gpio-emulator    作者:nosix    | 项目源码 | 文件源码
def main():
    import RPi.GPIO as GPIO

    try:
        print('UNKNOWN:%d' % GPIO.UNKNOWN)
        print('SERIAL:%d' % GPIO.SERIAL)
        print('SPI:%d' % GPIO.SPI)
        print('I2C:%d' % GPIO.I2C)
        print('HARD_PWM:%d' % GPIO.HARD_PWM)

        GPIO.setmode(GPIO.BOARD)

        GPIO.setup(3, GPIO.OUT)

        for pin in range(1, 41):
            try:
                print('%02d: %d' % (pin, GPIO.gpio_function(pin)))
            except ValueError as ex:
                print(ex)
    finally:
        GPIO.cleanup()
项目:raspberry-gpio-emulator    作者:nosix    | 项目源码 | 文件源码
def main():
    import RPi.GPIO as GPIO
    import time

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(12, GPIO.OUT)
    p = GPIO.PWM(12, 50)
    try:
        p.start(0)
        for dc in range(0, 101, 5):
            p.ChangeDutyCycle(dc)
            time.sleep(0.1)
        for dc in range(100, -1, -5):
            p.ChangeDutyCycle(dc)
            time.sleep(0.1)
    finally:
        p.stop()
        GPIO.cleanup()
项目:raspberry-gpio-emulator    作者:nosix    | 项目源码 | 文件源码
def main():
    import RPi.GPIO as GPIO
    import time

    try:
        GPIO.setmode(GPIO.BCM)

        GPIO.setwarnings(False)

        GPIO.setup(18, GPIO.OUT)
        GPIO.setup(27, GPIO.IN)

        while True:
            time.sleep(1)
    finally:
        GPIO.cleanup()
项目:raspberry-gpio-emulator    作者:nosix    | 项目源码 | 文件源码
def main():
    import RPi.GPIO as GPIO
    import time

    try:
        GPIO.setmode(GPIO.BCM)

        GPIO.setwarnings(False)

        GPIO.setup(18, GPIO.OUT)
        GPIO.setup(27, GPIO.IN)

        while True:
            time.sleep(1)
    finally:
        GPIO.cleanup()
项目:rl-rc-car    作者:harvitronix    | 项目源码 | 文件源码
def __init__(self, left_p=13, right_p=15, forward_p=12, backward_p=11,
                 apply_time=0.3, wait_time=0):
        self.left_p = left_p
        self.right_p = right_p
        self.forward_p = forward_p
        self.backward_p = backward_p
        self.apply_time = apply_time
        self.wait_time = wait_time

        print("Setting up GPIO pins.")
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.backward_p, GPIO.OUT)  # Backwards.
        GPIO.setup(self.forward_p, GPIO.OUT)  # Forwards.
        GPIO.setup(self.left_p, GPIO.OUT)  # Left.
        GPIO.setup(self.right_p, GPIO.OUT)  # Right.

        # Reset in case they're still on from before.
        GPIO.output(self.backward_p, 0)
        GPIO.output(self.forward_p, 0)
        GPIO.output(self.left_p, 0)
        GPIO.output(self.right_p, 0)
项目:pimaa    作者:outboxafrica    | 项目源码 | 文件源码
def __init__(self, data):
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        self.SPIMOSI = 23
        self.SPIMISO = 24
        self.SPICLK = 18
        self.SPICS = 25
        if "mosiPin" in data:
            self.SPIMOSI = data["mosiPin"]
        if "misoPin" in data:
            self.SPIMISO = data["misoPin"]
        if "clkPin" in data:
            self.SPICLK = data["clkPin"]
        if "csPin" in data:
            self.SPICS = data["csPin"] 
        GPIO.setup(self.SPIMOSI, GPIO.OUT)
        GPIO.setup(self.SPIMISO, GPIO.IN)
        GPIO.setup(self.SPICLK, GPIO.OUT)
        GPIO.setup(self.SPICS, GPIO.OUT)
        if MCP3008.sharedClass == None:
            MCP3008.sharedClass = self

    #read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
项目:SmartSlam    作者:Oneiroe    | 项目源码 | 文件源码
def wait_pir(DEBUG=False):
    """ Loops till PIR doesn't detect something"""
    # setting GPIO PINs
    with open(SETTINGS) as file:
        settings = json.load(file)

        logging.info('Setting GPIO PINS')
        GPIO.setmode(GPIO.BOARD)

        GPIO.setup(settings['pir_pin_board'], GPIO.IN)

    #####################
    # PIR cycle

    logging.info('Starting PIR waiting cycle...')

    if DEBUG:
        while input('insert 1 to start...') != '1':
            time.sleep(0.1)
    else:
        while GPIO.input(settings['pir_pin_board']) is not 1:
            time.sleep(0.1)

    logging.info('PIR detection')
    return
项目:kalliope    作者:kalliope-project    | 项目源码 | 文件源码
def __init__(self, rpi_settings=None, callback=None):
        """
        Class used to:
        - manage RPI GPIO
        - thread to catch mute button signal
        The object receive a rpi settings object which contains pin number to use on the Rpi
        When a signal is caught form the mute button, the callback method from the main controller is called
        :param rpi_settings: Settings object with GPIO pin number to use
        :type rpi_settings: RpiSettings
        :param callback: Callback function from the main controller to call when the mute button is pressed
        """
        super(RpiUtils, self).__init__()
        GPIO.setmode(GPIO.BCM)  # Use GPIO name
        GPIO.setwarnings(False)
        self.rpi_settings = rpi_settings
        self.callback = callback
        self.init_gpio(self.rpi_settings)
项目:rpi.rtc    作者:sourceperl    | 项目源码 | 文件源码
def __init__(self, clk_pin=11, data_pin=13, ce_pin=15):
        # init GPIO
        # no warnings
        GPIO.setwarnings(False)
        # use safer pin number (avoid GPIO renumber on each Pi release)
        GPIO.setmode(GPIO.BOARD)
        # set GPIO pins
        self._clk_pin = clk_pin
        self._data_pin = data_pin
        self._ce_pin = ce_pin
        # CLK and CE (sometime call RST) pin are always output
        GPIO.setup(self._clk_pin, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(self._ce_pin, GPIO.OUT, initial=GPIO.LOW)
        # turn off WP (write protect)
        self._start_tx()
        self._w_byte(0x8e)
        self._w_byte(0x00)
        self._end_tx()
        # charge mode is disabled
        self._start_tx()
        self._w_byte(0x90)
        self._w_byte(0x00)
        self._end_tx()
项目:aws-iot-python    作者:vjammar    | 项目源码 | 文件源码
def __init__(self, dev='/dev/spidev0.0', speed=1000000, pin_rst=22, pin_ce=0):
        self.pin_rst = pin_rst
        self.pin_ce = pin_ce

        SPI.openSPI(device=dev, speed=speed)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(pin_rst, GPIO.OUT)
        GPIO.output(pin_rst, 1)
        if pin_ce != 0:
            GPIO.setup(pin_ce, GPIO.OUT)
            GPIO.output(pin_ce, 1)
        self.reset()
        self.dev_write(0x2A, 0x8D)
        self.dev_write(0x2B, 0x3E)
        self.dev_write(0x2D, 30)
        self.dev_write(0x2C, 0)
        self.dev_write(0x15, 0x40)
        self.dev_write(0x11, 0x3D)
        self.set_antenna(True)
项目:Venenfinder    作者:Myrijam    | 项目源码 | 文件源码
def __init__(self,pinA,pinB,callback):
      self.pinA = pinA
      self.pinB = pinB
      #self.button = button
      self.callback = callback
      GPIO.setmode(GPIO.BCM)
      # The following lines enable the internal pull-up resistors
      # on version 2 (latest) boards
      GPIO.setwarnings(False)
      GPIO.setup(self.pinA, GPIO.IN, pull_up_down=GPIO.PUD_UP)
      GPIO.setup(self.pinB, GPIO.IN, pull_up_down=GPIO.PUD_UP)
      #GPIO.setup(self.button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
      # For version 1 (old) boards comment out the above four lines
      # and un-comment the following 3 lines
      #GPIO.setup(self.pinA, GPIO.IN)
      #GPIO.setup(self.pinB, GPIO.IN)
      #GPIO.setup(self.button, GPIO.IN)
      # Add event detection to the GPIO inputs
      GPIO.add_event_detect(self.pinA, GPIO.FALLING, callback=self.switch_event)
      GPIO.add_event_detect(self.pinB, GPIO.FALLING, callback=self.switch_event)
      #GPIO.add_event_detect(self.button, GPIO.BOTH, callback=self.button_event, bouncetime=200)
      return


# Call back routine called by switch events
项目:RFExplorer-for-Python    作者:RFExplorer    | 项目源码 | 文件源码
def ResetIOT_HW(cls, bMode):
        """Set Raspberry pi GPIO pins and reset RF Explorer device

        Parameters: 
            bMode -- True if the baudrate is set to 500000bps, False to 2400bps
        """
        try:
            import RPi.GPIO as GPIO

            #print("RPi info: " + str(GPIO.RPI_INFO)) #information about your RPi:
            #print("RPi.GPio version: " + GPIO.VERSION) #version of RPi.GPIO:
            GPIO.setwarnings(False)
            GPIO.setmode(GPIO.BOARD)    #refer to the pin numbers on the P1 header of the Raspberry Pi board
            GPIO.setup(12, GPIO.OUT)    #set /reset (pin 12) to output 
            GPIO.output(12, False)      #set /reset (pin 12) to LOW
            GPIO.setup(21, GPIO.OUT)    #set GPIO2 (pin 21) to output
            GPIO.output(21, bMode)      #set GPIO2 (pin 21) to HIGH (for 500Kbps)
            time.sleep(0.1)             #wait 100ms
            GPIO.output(12, True)       #set /reset to HIGH
            time.sleep(2.5)             #wait 2.5sec
            GPIO.setup(21, GPIO.IN)     #set GPIO2 to input
            GPIO.cleanup()              #clean up GPIO channels 

        except RuntimeError:
            print("Error importing RPi.GPIO!  This is probably because you need superuser privileges.  You can achieve this by using 'sudo' to run your script")
项目:OctoPrint-LEDStripControl    作者:google    | 项目源码 | 文件源码
def _setup_pin(self, pin):
        self._logger.debug(u"_setup_pin(%s)" % (pin,))
        if pin:
            p = None

            if self._pigpiod is None:
                self._pigpiod = pigpio.pi()

            if self._settings.get_boolean(['pigpiod']):
                if not self._pigpiod.connected:
                    self._logger.error(u"Unable to communicate with PiGPIOd")
                else:
                    p = PiGPIOpin(self._pigpiod, pin, self._logger)
            else:
                GPIO.setwarnings(False)
                GPIO.setmode(GPIO.BOARD)
                GPIO.setup(pin, GPIO.OUT)
                GPIO.output(pin, GPIO.HIGH)
                p = GPIO.PWM(pin, 100)
            p.start(100)
            return p
项目:SunFounder_PiCar    作者:sunfounder    | 项目源码 | 文件源码
def __init__(self, direction_channel, pwm=None, offset=True):
        '''Init a motor on giving dir. channel and PWM channel.'''
        if self._DEBUG:
            print self._DEBUG_INFO, "Debug on"
        self.direction_channel = direction_channel
        self._pwm = pwm
        self._offset = offset
        self.forward_offset = self._offset

        self.backward_offset = not self.forward_offset
        self._speed = 0

        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)

        if self._DEBUG:
            print self._DEBUG_INFO, 'setup motor direction channel at', direction_channel
            print self._DEBUG_INFO, 'setup motor pwm channel as', self._pwm.__name__
        GPIO.setup(self.direction_channel, GPIO.OUT)
项目:cuneyt    作者:HisarCS    | 项目源码 | 文件源码
def __init__(self, logger, d = 20, motor_setup = 0, motor_driver = 1,\
               pid = 1, reset = 1, r = 10):
    self.logger = logger
    GPIO.setmode(GPIO.BCM)
    self.GPIO = GPIO
    self.motor_controller = motor_setup
    self.motor_driver = motor_driver
    if motor_driver == gpio:
      self.driver = motor_drivers.ada_motor_driver(GPIO, logger)
    elif motor_driver == i2c:
      self.driver = motor_drivers.i2c_motor_driver(logger)
    if motor_setup == mecanum:
      self.controller = motor_controllers.mecanum(logger)
      if motor_driver == i2c:
        self.driver.init_module(pid,reset,4)
    elif motor_setup == differential:
      self.controller = motor_controllers.differential(d)
      if motor_driver == i2c:
        self.driver.init_module(pid,reset,2)

    #TODO: write motor_setup == omni
    #TODO: fix wiringpi
    #    wiringpi.wiringPiSetup()
    #    wiringpi.pinMode(1, 2)
项目:Bahavior-Based-Robot    作者:Marcgrippa    | 项目源码 | 文件源码
def setup(self):
        # Initialize class variables
        self.max_val = [-1, -1, -1, -1, -1, -1]
        self.min_val = [-1, -1, -1, -1, -1, -1]
        self.start_time = -1
        # Initialize value array to all negative values, which should never appear
        # as an actual result
        self.value = [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0]
        # A dictionary mapping each channel to the index it's value is located in
        # the value array
        self.sensor_indices = {29: 5, 36: 4, 37: 3, 31: 2, 32: 1, 33: 0}
        self.updated = False
        # For GPIO.BOARD
        self.sensor_inputs = [33, 32, 31, 37, 36, 29]  # Sensors from left to right

        # Set the mode to GPIO.BOARD
        GPIO.setmode(GPIO.BOARD)
项目:raspberry    作者:ykevin    | 项目源码 | 文件源码
def __init__(self, left_pin1, left_pin2, right_pin1, right_pin2, leftpwm_pin, rightpwm_pin):
        io.setmode(io.BCM)
        # Constant values
        self.PWM_MAX = 100
        # Here we configure the GPIO settings for the left and right motors spinning direction. 
        # It defines the four GPIO pins used as input on the L298 H-Bridge to set the motor mode (forward, reverse and stopp).
        self.leftmotor_in1_pin = left_pin1
        self.leftmotor_in2_pin = left_pin2
        self.rightmotor_in1_pin = right_pin1
        self.rightmotor_in2_pin = right_pin2
        self.leftmotorpwm_pin = leftpwm_pin
        self.rightmotorpwm_pin = rightpwm_pin
        self.SetupGPIO()
        self.leftmotorpwm = io.PWM(self.leftmotorpwm_pin,100)
        self.rightmotorpwm = io.PWM(self.rightmotorpwm_pin,100)
        self.InitPWM()
        # Disable warning from GPIO
        io.setwarnings(False)
项目:raspberry    作者:ykevin    | 项目源码 | 文件源码
def __init__(self, left_pin1, left_pin2, right_pin1, right_pin2, leftpwm_pin, rightpwm_pin):
        io.setmode(io.BCM)
        # Constant values
        self.PWM_MAX = 100
        # Here we configure the GPIO settings for the left and right motors spinning direction. 
        # It defines the four GPIO pins used as input on the L298 H-Bridge to set the motor mode (forward, reverse and stopp).
        self.leftmotor_in1_pin = left_pin1
        self.leftmotor_in2_pin = left_pin2
        self.rightmotor_in1_pin = right_pin1
        self.rightmotor_in2_pin = right_pin2
        self.leftmotorpwm_pin = leftpwm_pin
        self.rightmotorpwm_pin = rightpwm_pin
        self.SetupGPIO()
        self.leftmotorpwm = io.PWM(self.leftmotorpwm_pin,100)
        self.rightmotorpwm = io.PWM(self.rightmotorpwm_pin,100)
        self.InitPWM()
        # Disable warning from GPIO
        io.setwarnings(False)
项目:FoodBox_Hardware    作者:FatCatProject    | 项目源码 | 文件源码
def __init__(self, dout=4, pd_sck=18, gain=128, readBits=24, offset=-96096, scale=925):
        self.PD_SCK = pd_sck
        self.DOUT = dout
        self.readBits = readBits
        self.twosComplementOffset = 1 << readBits
        self.twosComplementCheck = self.twosComplementOffset >> 1

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.PD_SCK, GPIO.OUT)
        GPIO.setup(self.DOUT, GPIO.IN)

        self.GAIN = 0
        self.set_offset(offset)
        self.set_scale(scale)
        self.lastVal = 0

        self.set_gain(gain)
项目:DSHackathon    作者:DylanWalseth    | 项目源码 | 文件源码
def __init__(self):
        self.led_gpio_red = 17 # red
        self.led_gpio_green = 27 # green
        self.led_gpio_blue = 22 # blue
        self.r = 0.0
        self.g = 0.0
        self.b = 0.0
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.led_gpio_red, GPIO.OUT)
        GPIO.setup(self.led_gpio_green, GPIO.OUT)
        GPIO.setup(self.led_gpio_blue, GPIO.OUT)
        GPIO.output(self.led_gpio_red, True)
        GPIO.output(self.led_gpio_green, True)
        GPIO.output(self.led_gpio_blue, True)
        self.pwm_red = GPIO.PWM(self.led_gpio_red, 100)
        self.pwm_green = GPIO.PWM(self.led_gpio_green, 100)
        self.pwm_blue = GPIO.PWM(self.led_gpio_blue, 100)
        self.pwm_red.start(0)
        self.pwm_green.start(0)
        self.pwm_blue.start(0)
项目:SDRC    作者:yazeedalrubyli    | 项目源码 | 文件源码
def __init__(self):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setwarnings(False)

        GPIO.setup(self.MotorFront1, GPIO.OUT)
        GPIO.setup(self.MotorFront2, GPIO.OUT)
        GPIO.setup(self.MotorFront, GPIO.OUT)
        GPIO.output(self.MotorFront, 0)

        GPIO.setup(self.MotorBack1, GPIO.OUT)
        GPIO.setup(self.MotorBack2, GPIO.OUT)
        GPIO.setup(self.MotorBack, GPIO.OUT)
        GPIO.output(self.MotorBack, 0)
        self.BackPWM = GPIO.PWM(self.MotorBack,100)
        self.BackPWM.start(0)
        self.BackPWM.ChangeDutyCycle(0)

        self.direction = 0
项目:10-4-a-robot    作者:gruener-campus-malchow    | 项目源码 | 文件源码
def rotate_motor(duration,sleeptime):
   import RPi.GPIO as GPIO
   #import time

   servoPIN = 17
   GPIO.setmode(GPIO.BCM)
   GPIO.setup(servoPIN, GPIO.OUT)

   p = GPIO.PWM(servoPIN, 500) # GPIO 18 als PWM mit 50Hz
   p.start(2.5) # Initialisierung
   try:

      while duration > 0:
        p.ChangeDutyCycle(1)
    print 'motor running'+str(duration)
        time.sleep(sleeptime)
        duration -= 1
      p.stop()
      GPIO.cleanup()
   except KeyboardInterrupt:
      p.stop()
      GPIO.cleanup()
项目:10-4-a-robot    作者:gruener-campus-malchow    | 项目源码 | 文件源码
def rotate_motor(duration,sleeptime):
   import RPi.GPIO as GPIO
   #import time

   servoPIN = 17
   GPIO.setmode(GPIO.BCM)
   GPIO.setup(servoPIN, GPIO.OUT)

   p = GPIO.PWM(servoPIN, 500) # GPIO 18 als PWM mit 50Hz
   p.start(2.5) # Initialisierung
   try:

      while duration > 0:
        p.ChangeDutyCycle(1)
    print 'motor running'+str(duration)
        time.sleep(sleeptime)
        duration -= 1
      p.stop()
      GPIO.cleanup()
   except KeyboardInterrupt:
      p.stop()
      GPIO.cleanup()
项目:Webradio_v2    作者:Acer54    | 项目源码 | 文件源码
def __initGPIOs(self):
        #setup GPIO using Board numbering (pins, not GPIOs)
        GPIO.setwarnings(False)
        GPIO.cleanup()
        GPIO.setmode(GPIO.BOARD)

        #setup defined pins and event_detectors or outputs and initial states (initial is always 0, low)
        for pin in pins_in_use:
            if pins_in_use[pin][0] == GPIO.IN:
                if pin == 5:
                    GPIO.setup(pin, pins_in_use[pin][0], pull_up_down=GPIO.PUD_UP)
                else:
                    GPIO.setup(pin, pins_in_use[pin][0])
                GPIO.add_event_detect(pin, pins_in_use[pin][1], callback=self.shoutItOut, bouncetime=100)
                self.gpio_states.update({pin: 1})
            elif pins_in_use[pin][0] == GPIO.OUT:
                GPIO.setup(pin, pins_in_use[pin][0], initial=0)
项目:Webradio_v2    作者:Acer54    | 项目源码 | 文件源码
def __init__(self,pinA,pinB,button,callback, parent):
        self.pinA = pinA
        self.pinB = pinB
        self.button = button
        self.callback = callback
        self.parent = parent
        if self.pinA is not None and self.pinB is not None:
            GPIO.setmode(GPIO.BOARD)

            GPIO.setwarnings(False)
            GPIO.setup(self.pinA, GPIO.IN)
            GPIO.setup(self.pinB, GPIO.IN)
            GPIO.add_event_detect(self.pinA, GPIO.FALLING,
            callback=self.switch_event)
            GPIO.add_event_detect(self.pinB, GPIO.FALLING,
            callback=self.switch_event)

        if self.button is not None:
            GPIO.setup(self.button, GPIO.IN)
            GPIO.add_event_detect(self.button, GPIO.BOTH,
            callback=self.button_event, bouncetime=200)

        return
        # Call back routine called by switch events
项目:kiota    作者:Morteo    | 项目源码 | 文件源码
def __init__(self, no, dir=IN):
        self.gpio_no = no
        print("GPIO ########## self.gpio_no, dir={}, {}".format(self.gpio_no, dir))
        GPIO.setmode(GPIO.BCM)
        #GPIO.setmode(GPIO.BOARD)

        if dir==Pin.IN:
          GPIO.setup(self.gpio_no, GPIO.IN)
          print("GPIO >>>>>>>>>>>>>>>>>>>>>>>>>>> IN")
        else:
          GPIO.setup(self.gpio_no, GPIO.OUT)
          print("GPIO <<<<<<<<<<<<<<<<<<<<<<<<<< OUT")
项目:rpi-can-logger    作者:JonnoFTW    | 项目源码 | 文件源码
def setup_GPIO():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.OUT)
    GPIO.setup(37, GPIO.OUT)
    GPIO.setup(35, GPIO.IN)
项目:rpi-can-logger    作者:JonnoFTW    | 项目源码 | 文件源码
def setup_GPIO():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.OUT)
    GPIO.setup(37, GPIO.OUT)
项目:coliform-project    作者:uprm-research-resto    | 项目源码 | 文件源码
def startup(self):  # funciton that starts th GPIO board and pin required
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.channel, GPIO.OUT)
        self.pwm = GPIO.PWM(self.channel, self.frequency)
        self.pwm.start(self.frequency)
项目:StratoBalloon    作者:delattreb    | 项目源码 | 文件源码
def setmodeboard(self):
        if self.importlib is not None:
            GPIO.setmode(GPIO.BOARD)
项目:StratoBalloon    作者:delattreb    | 项目源码 | 文件源码
def setmodebcm(self):
        if self.importlib is not None:
            GPIO.setmode(GPIO.BCM)
项目:voctomix-outcasts    作者:CarlFK    | 项目源码 | 文件源码
def reset_led(self):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setwarnings(False)
        for gpio in self.gpios:
            gpio = int(gpio)
            GPIO.setup(gpio, GPIO.OUT)
            GPIO.output(gpio, GPIO.HIGH)
项目:RaspberryPi-Robot    作者:timestocome    | 项目源码 | 文件源码
def __init__(self):

        gpio.setmode(gpio.BOARD)

        # set up  and init 
        self.trigger = 11
        self.echo = 13

        gpio.setup(self.trigger, gpio.OUT)
        gpio.setup(self.echo, gpio.IN)

        self.pulse_start = 0.
        self.pulse_end = 0.
        self.speed_of_sound = 343 * 100
        self.car_length = 1
项目:susi_linux    作者:fossasia    | 项目源码 | 文件源码
def __init__(self):
        super().__init__()
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
项目:Rpi-envMonitor    作者:conanwhf    | 项目源码 | 文件源码
def _GPIO_Power_Regist(pins):
    GPIO.setmode(GPIO.BOARD)
    GPIO.setwarnings(False)
    GPIO.setup( pins , GPIO.OUT)
    return