Python RPi.GPIO.OUT Examples

The following are 30 code examples of RPi.GPIO.OUT(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module RPi.GPIO , or try the search function .
Example #1
Source File: buzzer.py    From SecPi with GNU General Public License v3.0 7 votes vote down vote up
def __init__(self, id, params):
		super(Buzzer, self).__init__(id, params)
		try:
			self.duration = int(params["duration"])
			self.gpio_pin = int(params["gpio_pin"])
		except KeyError as ke: # if config parameters are missing in file
			logging.error("Buzzer: Wasn't able to initialize the device, it seems there is a config parameter missing: %s" % ke)
			self.corrupted = True
			return
		except ValueError as ve: # if a parameter can't be parsed as int
			logging.error("Buzzer: Wasn't able to initialize the device, please check your configuration: %s" % ve)
			self.corrupted = True
			return

		try:
			GPIO.setmode(GPIO.BCM)
			GPIO.setup(self.gpio_pin, GPIO.OUT)
		except ValueError as ve: # GPIO pin number is not in valid range
			logging.error("Buzzer: The given pin number is not in a valid range: %s" % ve)
			self.corrupted = True
			return
		logging.debug("Buzzer: Audio device initialized") 
Example #2
Source File: __init__.py    From phat-beat with MIT License 7 votes vote down vote up
def setup():
    global _is_setup

    if _is_setup:
        return True

    atexit.register(_exit)

    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup([DAT, CLK], GPIO.OUT)
    GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    for button in BUTTONS:
        GPIO.add_event_detect(button, GPIO.FALLING, callback=_handle_button, bouncetime=200)

    _is_setup = True 
Example #3
Source File: AMSpi.py    From AMSpi with MIT License 6 votes vote down vote up
def set_74HC595_pins(self, DIR_LATCH, DIR_CLK, DIR_SER):
        """
        Set PINs used on Raspberry Pi to connect with 74HC595 module on
        Arduino Motor Shield

        :param int DIR_LATCH: LATCH PIN number
        :param int DIR_CLK: CLK PIN number
        :param int DIR_SER: SER  PIN number
        """
        self._DIR_LATCH = DIR_LATCH
        self._DIR_CLK = DIR_CLK
        self._DIR_SER = DIR_SER

        GPIO.setup(self._DIR_LATCH, GPIO.OUT)
        GPIO.setup(self._DIR_CLK, GPIO.OUT)
        GPIO.setup(self._DIR_SER, GPIO.OUT) 
Example #4
Source File: apa102.py    From rainbow-hat with MIT License 6 votes vote down vote up
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) 
Example #5
Source File: buzzer.py    From rainbow-hat with MIT License 6 votes vote down vote up
def note(frequency, duration=1.0):
    """Play a single note.

    :param frequency: Musical frequency in hertz
    :param duration: Optional duration in seconds, use None to sustain note

    """
    global _timeout

    setup()

    if frequency <= 0:
        raise ValueError("Frequency must be > 0")

    if duration is not None and duration <= 0:
        raise ValueError("Duration must be > 0")

    clear_timeout()

    pwm.ChangeFrequency(frequency)
    GPIO.setup(BUZZER, GPIO.OUT)

    if duration is not None and duration > 0:
        _timeout = Timer(duration, stop)
        _timeout.start() 
Example #6
Source File: mymodem.py    From genmon with GNU General Public License v2.0 6 votes vote down vote up
def InitHardware(self):

        # NOTE: This function assumes the underlying hardware is the LTE Cat 1 Pi Hat
        # http://wiki.seeedstudio.com/LTE_Cat_1_Pi_HAT/

        try:
            self.power_pin = 29
            self.reset_pin = 31
            GPIO.setmode(GPIO.BOARD)
            GPIO.setwarnings(False)
            GPIO.setup(self.power_pin, GPIO.OUT) # Setup module power pin
            GPIO.setup(self.reset_pin, GPIO.OUT) # Setup module reset pin
            GPIO.output(self.power_pin, False)
            GPIO.output(self.reset_pin, False)

            return self.PowerUp()
        except Exception as e1:
            self.LogErrorLine("Error in LTEPiHat:InitHardware: " + str(e1))
            return False
    #------------------LTEPiHat::PowerDown------------------------------------- 
Example #7
Source File: controller.py    From ran-django-template with GNU General Public License v3.0 6 votes vote down vote up
def readUltrasonicSensor():
    GPIO.setup(TRIGGER_PIN, GPIO.OUT)
    GPIO.setup(SENSOR_PIN, GPIO.IN)
    GPIO.output(TRIGGER_PIN, GPIO.LOW)
    time.sleep(0.3)
    GPIO.output(TRIGGER_PIN, True)
    time.sleep(0.00001)
    GPIO.output(TRIGGER_PIN, False)
    while GPIO.input(SENSOR_PIN) == 0:
        signaloff = time.time()
    while GPIO.input(SENSOR_PIN) == 1:
        signalon = time.time()
    timepassed = signalon - signaloff
    distance = timepassed * 17000
    if distance < threshold:
        return 1
    else:
        return 0 
Example #8
Source File: buzzer.py    From rainbow-hat with MIT License 6 votes vote down vote up
def setup():
    """Setup piezo buzzer."""
    global _is_setup, pwm

    if _is_setup:
        return

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

    # Set up the PWM and then set the pin to input
    # to prevent the signal from being output.
    # Since starting/stopping PWM causes a segfault,
    # this is the only way to manage the buzzer.

    pwm = GPIO.PWM(BUZZER, 1)
    GPIO.setup(BUZZER, GPIO.IN)
    pwm.start(50)

    _is_setup = True 
Example #9
Source File: sakshat.py    From SAKS-SDK with GNU General Public License v2.0 6 votes vote down vote up
def saks_gpio_init(self):
        #print 'saks_gpio_init'
        GPIO.setwarnings(False)
        GPIO.cleanup()
        GPIO.setmode(GPIO.BCM)

        GPIO.setup(PINS.BUZZER, GPIO.OUT)
        GPIO.output(PINS.BUZZER, GPIO.HIGH)

        for p in [PINS.IC_TM1637_DI, PINS.IC_TM1637_CLK, PINS.IC_74HC595_DS, PINS.IC_74HC595_SHCP, PINS.IC_74HC595_STCP]:
            GPIO.setup(p, GPIO.OUT)
            GPIO.output(p, GPIO.LOW)

        for p in [PINS.BUZZER, PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]:
            GPIO.setup(p, GPIO.OUT)
            GPIO.output(p, GPIO.HIGH)

        for p in [PINS.TACT_RIGHT, PINS.TACT_LEFT, PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2]:
            GPIO.setup(p, GPIO.IN, pull_up_down = GPIO.PUD_UP) 
Example #10
Source File: control.py    From rpi-film-capture with MIT License 6 votes vote down vote up
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) 
Example #11
Source File: co2_t110.py    From BerePi with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def init_process():
	print " "
	print "MSG - [S100, T110 CO2 Sensor Driver on RASPI2, Please check log file : ", LOG_PATH
	print "MSG - now starting to read SERIAL PORT"
	print " "
	# HW setup, GPIO
	GPIO.setwarnings(False)
	GPIO.cleanup()
	GPIO.setmode(GPIO.BCM)
	GPIO.setup(18, GPIO.OUT)
	GPIO.setup(23, GPIO.OUT)
	GPIO.setup(24, GPIO.OUT)
	GPIO.setup(25, GPIO.OUT)
	logger.info(' *start* GPIO all set, trying to open serial port, SW starting ')
	rledAllOn()

######################################################################
# START Here. Main
######################################################################

# set logger file 
Example #12
Source File: rccar.py    From rl-rc-car with MIT License 6 votes vote down vote up
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) 
Example #13
Source File: drive.py    From SDRC with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #14
Source File: rpi_gpio.py    From pcaspy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def write(self, reason, value):
        status = True

        if reason == 'OUT':
            GPIO.output(PIN_OUT, value)
        elif reason == 'TRIG':
            GPIO.output(PIN_OUT, GPIO.HIGH)
            time.sleep(0.1)
            GPIO.output(PIN_OUT, GPIO.LOW)
            value = 0
        elif reason == 'PWM':
            if value == 0:
                self.pwm.stop()
            else:
                self.pwm.start(self.getParam('DC'))
        elif reason == 'DC':
            self.pwm.ChangeDutyCycle(value)
        elif reason == 'FREQ':
            self.pwm.ChangeFrequency(value)
        else:
            status = False

        if status:
            self.setParam(reason, value)
        return status 
Example #15
Source File: tm1637.py    From raspberrypi-examples with MIT License 6 votes vote down vote up
def writeByte(self, data):
        for i in range(0, 8):
            IO.output(self.__Clkpin, IO.LOW)
            if(data & 0x01):
                IO.output(self.__Datapin, IO.HIGH)
            else:
                IO.output(self.__Datapin, IO.LOW)
            data = data >> 1
            IO.output(self.__Clkpin, IO.HIGH)

        # wait for ACK
        IO.output(self.__Clkpin, IO.LOW)
        IO.output(self.__Datapin, IO.HIGH)
        IO.output(self.__Clkpin, IO.HIGH)
        IO.setup(self.__Datapin, IO.IN)

        while(IO.input(self.__Datapin)):
            sleep(0.001)
            if(IO.input(self.__Datapin)):
                IO.setup(self.__Datapin, IO.OUT)
                IO.output(self.__Datapin, IO.LOW)
                IO.setup(self.__Datapin, IO.IN)
        IO.setup(self.__Datapin, IO.OUT) 
Example #16
Source File: GPIOq.py    From atlas-python with MIT License 5 votes vote down vote up
def softPWMCreate(pin):
		global pwms
		destroyPWMIfNeeded(pin)
		GPIO.setup(pin, GPIO.OUT)
		GPIO.output(pin, GPIO.LOW)
		pwms[pin] = GPIO.PWM(pin, 100)
		pwms[pin].start(0) 
Example #17
Source File: hx711.py    From pydPiper with MIT License 5 votes vote down vote up
def __init__(self, dout, pd_sck, gain=128):
        self.PD_SCK = pd_sck
        self.DOUT = dout

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

        self.GAIN = 0
        self.REFERENCE_UNIT = 1  # The value returned by the hx711 that corresponds to your reference unit AFTER dividing by the SCALE.
        
        self.OFFSET = 1
        self.lastVal = long(0)

        self.LSByte = [2, -1, -1]
        self.MSByte = [0, 3, 1]
        
        self.MSBit = [0, 8, 1]
        self.LSBit = [7, -1, -1]

        self.byte_range_values = self.LSByte
        self.bit_range_values = self.MSBit

        self.set_gain(gain)

        time.sleep(1) 
Example #18
Source File: co2led.py    From BerePi with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def linit():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(bled, GPIO.OUT)
    GPIO.setup(gled, GPIO.OUT)
    GPIO.setup(rled, GPIO.OUT)

# below assuming that you are using LEDs PCB board with GND 
Example #19
Source File: epdif.py    From epd-library-python with GNU General Public License v3.0 5 votes vote down vote up
def epd_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(DC_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    GPIO.setup(BUSY_PIN, GPIO.IN)

    SPI.max_speed_hz = 2000000
    SPI.mode = 0b00
    return 0

### END OF FILE ### 
Example #20
Source File: GPIOq.py    From atlas-python with MIT License 5 votes vote down vote up
def softPWMCreate(pin):
		global pwms
		destroyPWMIfNeeded(pin)
		GPIO.setup(pin, GPIO.OUT)
		GPIO.output(pin, GPIO.LOW)
		pwms[pin] = GPIO.PWM(pin, 100)
		pwms[pin].start(0) 
Example #21
Source File: epdif.py    From epd-library-python with GNU General Public License v3.0 5 votes vote down vote up
def epd_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(DC_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    GPIO.setup(BUSY_PIN, GPIO.IN)
    SPI.max_speed_hz = 2000000
    SPI.mode = 0b00
    return 0

### END OF FILE ### 
Example #22
Source File: epdif.py    From epd-library-python with GNU General Public License v3.0 5 votes vote down vote up
def epd_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(DC_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    GPIO.setup(BUSY_PIN, GPIO.IN)
    SPI.max_speed_hz = 2000000
    SPI.mode = 0b00
    return 0

### END OF FILE ### 
Example #23
Source File: epdif.py    From epd-library-python with GNU General Public License v3.0 5 votes vote down vote up
def epd_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(DC_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    GPIO.setup(BUSY_PIN, GPIO.IN)
    SPI.max_speed_hz = 2000000
    SPI.mode = 0b00
    return 0

### END OF FILE ### 
Example #24
Source File: epdif.py    From epd-library-python with GNU General Public License v3.0 5 votes vote down vote up
def epd_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(DC_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    GPIO.setup(BUSY_PIN, GPIO.IN)
    SPI.max_speed_hz = 2000000
    SPI.mode = 0b00
    return 0

### END OF FILE ### 
Example #25
Source File: epdif.py    From epd-library-python with GNU General Public License v3.0 5 votes vote down vote up
def epd_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(DC_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    GPIO.setup(BUSY_PIN, GPIO.IN)
    SPI.max_speed_hz = 2000000
    SPI.mode = 0b00
    return 0

### END OF FILE ### 
Example #26
Source File: epdif.py    From epd-library-python with GNU General Public License v3.0 5 votes vote down vote up
def epd_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(DC_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    GPIO.setup(BUSY_PIN, GPIO.IN)
    SPI.max_speed_hz = 2000000
    SPI.mode = 0b00
    return 0

### FILE END ### 
Example #27
Source File: epdif.py    From epd-library-python with GNU General Public License v3.0 5 votes vote down vote up
def epd_init():
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(RST_PIN, GPIO.OUT)
    GPIO.setup(DC_PIN, GPIO.OUT)
    GPIO.setup(CS_PIN, GPIO.OUT)
    GPIO.setup(BUSY_PIN, GPIO.IN)
    SPI.max_speed_hz = 2000000
    SPI.mode = 0b00
    return 0

### END OF FILE ### 
Example #28
Source File: ledinit.py    From BerePi with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def init() :
    # HW setup, GPIO
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(bled, GPIO.OUT)
    GPIO.setup(gled, GPIO.OUT)
    GPIO.setup(rled, GPIO.OUT)
    ledall_on()
    time.sleep(0.3)
    ledall_off()
    # please check the HW connection between LEDs and CPU
    # if you using GND on the LED HW, GPIO.output(bled, True) will show LED ON 
Example #29
Source File: co2led.py    From BerePi with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def linit():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(bled, GPIO.OUT)
    GPIO.setup(gled, GPIO.OUT)
    GPIO.setup(rled, GPIO.OUT)

# below assuming that you are using LEDs PCB board with GND 
Example #30
Source File: led-bar.py    From raspberrypi-examples with MIT License 5 votes vote down vote up
def setup():
	GPIO.setwarnings(False)
	GPIO.setmode(GPIO.BCM)
	GPIO.setup(pd, GPIO.OUT)
	GPIO.setup(pc, GPIO.OUT)
	GPIO.output(pd,0)
	GPIO.output(pc,0)
	#sendData(CmdMode)
	for i in range(1,13):
		sendData(OFF)
	latchData()