Python Adafruit_GPIO.OUT Examples
The following are 13
code examples of Adafruit_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
Adafruit_GPIO
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: PCD8544.py From Adafruit_Nokia_LCD with MIT License | 6 votes |
def __init__(self, dc, rst, sclk=None, din=None, cs=None, gpio=None, spi=None): self._sclk = sclk self._din = din self._dc = dc self._cs = cs self._rst = rst self._gpio = gpio self._spi = spi # Default to detecting platform GPIO. if self._gpio is None: self._gpio = GPIO.get_platform_gpio() if self._rst is not None: self._gpio.setup(self._rst, GPIO.OUT) # Default to bit bang SPI. if self._spi is None: self._spi = SPI.BitBang(self._gpio, self._sclk, self._din, None, self._cs) # Set pin outputs. self._gpio.setup(self._dc, GPIO.OUT) # Initialize buffer to Adafruit logo. self._buffer = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0x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3F, 0xF9, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7E, 0x3F, 0x3F, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
Example #2
Source File: Adafruit_CharLCD.py From Adafruit_Python_CharLCD with MIT License | 6 votes |
def __init__(self, address=0x20, busnum=I2C.get_default_bus(), cols=16, lines=2): """Initialize the character LCD plate. Can optionally specify a separate I2C address or bus number, but the defaults should suffice for most needs. Can also optionally specify the number of columns and lines on the LCD (default is 16x2). """ # Configure MCP23017 device. self._mcp = MCP.MCP23017(address=address, busnum=busnum) # Set LCD R/W pin to low for writing only. self._mcp.setup(LCD_PLATE_RW, GPIO.OUT) self._mcp.output(LCD_PLATE_RW, GPIO.LOW) # Set buttons as inputs with pull-ups enabled. for button in (SELECT, RIGHT, DOWN, UP, LEFT): self._mcp.setup(button, GPIO.IN) self._mcp.pullup(button, True) # Initialize LCD (with no PWM support). super(Adafruit_CharLCDPlate, self).__init__(LCD_PLATE_RS, LCD_PLATE_EN, LCD_PLATE_D4, LCD_PLATE_D5, LCD_PLATE_D6, LCD_PLATE_D7, cols, lines, LCD_PLATE_RED, LCD_PLATE_GREEN, LCD_PLATE_BLUE, enable_pwm=False, gpio=self._mcp)
Example #3
Source File: main.py From attify-badge with MIT License | 6 votes |
def GPIO_handler(self,pin): self.FTDI_setup() pin_combo={0:self.comboBox_d0,1:self.comboBox_d1,2:self.comboBox_d2,3:self.comboBox_d3,4:self.comboBox_d4,5:self.comboBox_d5,6:self.comboBox_d6,7:self.comboBox_d7} pin_check={0:self.checkBox_d0,1:self.checkBox_d1,2:self.checkBox_d2,3:self.checkBox_d3,4:self.checkBox_d4,5:self.checkBox_d5,6:self.checkBox_d6,7:self.checkBox_d7} mode=pin_check[pin].isChecked() if(str(pin_combo[pin].currentText())=="Input"): self.ft232h.setup(pin,GPIO.IN) print("[*] Pin "+str(pin)+" set as Input") elif(str(pin_combo[pin].currentText())=="Output"): print("[*] Pin "+str(pin)+" set as Output") self.ft232h.setup(pin,GPIO.OUT) if(mode): print("[*] Pin "+str(pin)+" : HIGH ") self.statusbar.showMessage(" GPIO | Pin "+str(pin)+" : HIGH ",500) self.ft232h.output(pin, GPIO.HIGH) else: self.ft232h.output(pin, GPIO.LOW) self.statusbar.showMessage(" GPIO | Pin "+str(pin)+" : LOW ",500) print("[*] Pin "+str(pin)+" : LOW ")
Example #4
Source File: ILI9341.py From Adafruit_Python_ILI9341 with MIT License | 5 votes |
def __init__(self, dc, spi, rst=None, gpio=None, width=ILI9341_TFTWIDTH, height=ILI9341_TFTHEIGHT): """Create an instance of the display using SPI communication. Must provide the GPIO pin number for the D/C pin and the SPI driver. Can optionally provide the GPIO pin number for the reset pin as the rst parameter. """ self._dc = dc self._rst = rst self._spi = spi self._gpio = gpio self.width = width self.height = height if self._gpio is None: self._gpio = GPIO.get_platform_gpio() # Set DC as output. self._gpio.setup(dc, GPIO.OUT) # Setup reset as output (if provided). if rst is not None: self._gpio.setup(rst, GPIO.OUT) # Set SPI to mode 0, MSB first. spi.set_mode(0) spi.set_bit_order(SPI.MSBFIRST) spi.set_clock_hz(64000000) # Create an image buffer. self.buffer = Image.new('RGB', (width, height))
Example #5
Source File: PCF8574.py From Adafruit_Python_GPIO with MIT License | 5 votes |
def setup_pins(self, pins): if False in [y for x,y in [(self._validate_pin(pin),mode in (IN,OUT)) for pin,mode in pins.items()]]: raise ValueError('Invalid MODE, IN or OUT') for pin,mode in pins.items(): self.iodir = self._bit2(self.iodir, pin, mode) self._write_pins()
Example #6
Source File: MCP230xx.py From Adafruit_Python_GPIO with MIT License | 5 votes |
def setup(self, pin, value): """Set the input or output mode for a specified pin. Mode should be either GPIO.OUT or GPIO.IN. """ self._validate_pin(pin) # Set bit to 1 for input or 0 for output. if value == GPIO.IN: self.iodir[int(pin/8)] |= 1 << (int(pin%8)) elif value == GPIO.OUT: self.iodir[int(pin/8)] &= ~(1 << (int(pin%8))) else: raise ValueError('Unexpected value. Must be GPIO.IN or GPIO.OUT.') self.write_iodir()
Example #7
Source File: SPI.py From Adafruit_Python_GPIO with MIT License | 5 votes |
def __init__(self, gpio, sclk, mosi=None, miso=None, ss=None): """Initialize bit bang (or software) based SPI. Must provide a BaseGPIO class, the SPI clock, and optionally MOSI, MISO, and SS (slave select) pin numbers. If MOSI is set to None then writes will be disabled and fail with an error, likewise for MISO reads will be disabled. If SS is set to None then SS will not be asserted high/low by the library when transfering data. """ self._gpio = gpio self._sclk = sclk self._mosi = mosi self._miso = miso self._ss = ss # Set pins as outputs/inputs. gpio.setup(sclk, GPIO.OUT) if mosi is not None: gpio.setup(mosi, GPIO.OUT) if miso is not None: gpio.setup(miso, GPIO.IN) if ss is not None: gpio.setup(ss, GPIO.OUT) # Assert SS high to start with device communication off. gpio.set_high(ss) # Assume mode 0. self.set_mode(0) # Assume most significant bit first order. self.set_bit_order(MSBFIRST)
Example #8
Source File: test_GPIO.py From Adafruit_Python_GPIO with MIT License | 5 votes |
def test_setup(self): rpi_gpio = Mock() adapter = GPIO.RPiGPIOAdapter(rpi_gpio) adapter.setup(1, GPIO.OUT) rpi_gpio.setup.assert_called_with(1, rpi_gpio.OUT, pull_up_down=rpi_gpio.PUD_OFF) adapter.setup(1, GPIO.IN) rpi_gpio.setup.assert_called_with(1, rpi_gpio.IN, pull_up_down=rpi_gpio.PUD_OFF) adapter.setup(1, GPIO.IN, GPIO.PUD_DOWN) rpi_gpio.setup.assert_called_with(1, rpi_gpio.IN, pull_up_down=rpi_gpio.PUD_DOWN) adapter.setup(1, GPIO.IN, GPIO.PUD_UP) rpi_gpio.setup.assert_called_with(1, rpi_gpio.IN, pull_up_down=rpi_gpio.PUD_UP)
Example #9
Source File: test_GPIO.py From Adafruit_Python_GPIO with MIT License | 5 votes |
def test_setup(self): bbio_gpio = Mock() adapter = GPIO.AdafruitBBIOAdapter(bbio_gpio) adapter.setup(1, GPIO.OUT) bbio_gpio.setup.assert_called_with(1, bbio_gpio.OUT, pull_up_down=bbio_gpio.PUD_OFF) adapter.setup(1, GPIO.IN) bbio_gpio.setup.assert_called_with(1, bbio_gpio.IN, pull_up_down=bbio_gpio.PUD_OFF) adapter.setup(1, GPIO.IN, GPIO.PUD_DOWN) bbio_gpio.setup.assert_called_with(1, bbio_gpio.IN, pull_up_down=bbio_gpio.PUD_DOWN) adapter.setup(1, GPIO.IN, GPIO.PUD_UP) bbio_gpio.setup.assert_called_with(1, bbio_gpio.IN, pull_up_down=bbio_gpio.PUD_UP)
Example #10
Source File: PN532.py From Adafruit_Python_PN532 with MIT License | 5 votes |
def __init__(self, cs, sclk=None, mosi=None, miso=None, gpio=None, spi=None): """Create an instance of the PN532 class using either software SPI (if the sclk, mosi, and miso pins are specified) or hardware SPI if a spi parameter is passed. The cs pin must be a digital GPIO pin. Optionally specify a GPIO controller to override the default that uses the board's GPIO pins. """ # Default to platform GPIO if not provided. self._gpio = gpio if self._gpio is None: self._gpio = GPIO.get_platform_gpio() # Initialize CS line. self._cs = cs self._gpio.setup(self._cs, GPIO.OUT) self._gpio.set_high(self._cs) # Setup SPI provider. if spi is not None: logger.debug('Using hardware SPI.') # Handle using hardware SPI. self._spi = spi self._spi.set_clock_hz(1000000) else: logger.debug('Using software SPI') # Handle using software SPI. Note that the CS/SS pin is not used # as it will be manually controlled by this library for better # timing. self._spi = SPI.BitBang(self._gpio, sclk, mosi, miso) # Set SPI mode and LSB first bit order. self._spi.set_mode(0) self._spi.set_bit_order(SPI.LSBFIRST)
Example #11
Source File: main.py From attify-badge with MIT License | 5 votes |
def GPIO_setup(self): if(self.gpio_init==0): print("[*] Setting up GPIO pins") #setting everything as out #because leaving then un- #initialized confuses the #Input Monitor self.ft232h.setup(0, GPIO.OUT) self.ft232h.setup(1, GPIO.OUT) self.ft232h.setup(2, GPIO.OUT) self.ft232h.setup(3, GPIO.OUT) self.ft232h.setup(4, GPIO.OUT) self.ft232h.setup(5, GPIO.OUT) self.ft232h.setup(6, GPIO.OUT) self.ft232h.setup(7, GPIO.OUT)
Example #12
Source File: Adafruit_CharLCD.py From Adafruit_Python_CharLCD with MIT License | 4 votes |
def __init__(self, rs, en, d4, d5, d6, d7, cols, lines, red, green, blue, gpio=GPIO.get_platform_gpio(), invert_polarity=True, enable_pwm=False, pwm=PWM.get_platform_pwm(), initial_color=(1.0, 1.0, 1.0)): """Initialize the LCD with RGB backlight. RS, EN, and D4...D7 parameters should be the pins connected to the LCD RS, clock enable, and data line 4 through 7 connections. The LCD will be used in its 4-bit mode so these 6 lines are the only ones required to use the LCD. You must also pass in the number of columns and lines on the LCD. The red, green, and blue parameters define the pins which are connected to the appropriate backlight LEDs. The invert_polarity parameter is a boolean that controls if the LEDs are on with a LOW or HIGH signal. By default invert_polarity is True, i.e. the backlight LEDs are on with a low signal. If you want to enable PWM on the backlight LEDs (for finer control of colors) and the hardware supports PWM on the provided pins, set enable_pwm to True. Finally you can set an explicit initial backlight color with the initial_color parameter. The default initial color is white (all LEDs lit). You can optionally pass in an explicit GPIO class, for example if you want to use an MCP230xx GPIO extender. If you don't pass in an GPIO instance, the default GPIO for the running platform will be used. """ super(Adafruit_RGBCharLCD, self).__init__(rs, en, d4, d5, d6, d7, cols, lines, enable_pwm=enable_pwm, backlight=None, invert_polarity=invert_polarity, gpio=gpio, pwm=pwm) self._red = red self._green = green self._blue = blue # Setup backlight pins. if enable_pwm: # Determine initial backlight duty cycles. rdc, gdc, bdc = self._rgb_to_duty_cycle(initial_color) pwm.start(red, rdc) pwm.start(green, gdc) pwm.start(blue, bdc) else: gpio.setup(red, GPIO.OUT) gpio.setup(green, GPIO.OUT) gpio.setup(blue, GPIO.OUT) self._gpio.output_pins(self._rgb_to_pins(initial_color))
Example #13
Source File: SSD1306.py From Adafruit_Python_SSD1306 with MIT License | 4 votes |
def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None, gpio=None, spi=None, i2c_bus=None, i2c_address=SSD1306_I2C_ADDRESS, i2c=None): self._log = logging.getLogger('Adafruit_SSD1306.SSD1306Base') self._spi = None self._i2c = None self.width = width self.height = height self._pages = height//8 self._buffer = [0]*(width*self._pages) # Default to platform GPIO if not provided. self._gpio = gpio if self._gpio is None: self._gpio = GPIO.get_platform_gpio() # Setup reset pin. self._rst = rst if not self._rst is None: self._gpio.setup(self._rst, GPIO.OUT) # Handle hardware SPI if spi is not None: self._log.debug('Using hardware SPI') self._spi = spi self._spi.set_clock_hz(8000000) # Handle software SPI elif sclk is not None and din is not None and cs is not None: self._log.debug('Using software SPI') self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs) # Handle hardware I2C elif i2c is not None: self._log.debug('Using hardware I2C with custom I2C provider.') self._i2c = i2c.get_i2c_device(i2c_address) else: self._log.debug('Using hardware I2C with platform I2C provider.') import Adafruit_GPIO.I2C as I2C if i2c_bus is None: self._i2c = I2C.get_i2c_device(i2c_address) else: self._i2c = I2C.get_i2c_device(i2c_address, busnum=i2c_bus) # Initialize DC pin if using SPI. if self._spi is not None: if dc is None: raise ValueError('DC pin must be provided when using SPI.') self._dc = dc self._gpio.setup(self._dc, GPIO.OUT)