我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用RPi.GPIO.BOARD。
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)
def start(): """ start running the ui. GPIO must only be loaded when it is stared, as the library is not available on the build computer. """ from RPi import GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) # use pin numbers as written on the board main_led.start() button_led.start() display.start() button.start() CallState.add_listener(on_call_state_change) main_led.queue(Startup()) button_led.queue(StartupButton()) display.show(10, 'Telewall')
def __init__(self, cs_pin, clock_pin, data_pin, units = "c", board = GPIO.BCM): '''Initialize Soft (Bitbang) SPI bus Parameters: - cs_pin: Chip Select (CS) / Slave Select (SS) pin (Any GPIO) - clock_pin: Clock (SCLK / SCK) pin (Any GPIO) - data_pin: Data input (SO / MOSI) pin (Any GPIO) - units: (optional) unit of measurement to return. ("c" (default) | "k" | "f") - board: (optional) pin numbering method as per RPi.GPIO library (GPIO.BCM (default) | GPIO.BOARD) ''' self.cs_pin = cs_pin self.clock_pin = clock_pin self.data_pin = data_pin self.units = units self.data = None self.board = board # Initialize needed GPIO GPIO.setmode(self.board) GPIO.setup(self.cs_pin, GPIO.OUT) GPIO.setup(self.clock_pin, GPIO.OUT) GPIO.setup(self.data_pin, GPIO.IN) # Pull chip select high to make chip inactive GPIO.output(self.cs_pin, GPIO.HIGH)
def _gpio_get_pin(self, pin): if (GPIO.getmode() == GPIO.BOARD and self.GPIOMode == 'BOARD') or (GPIO.getmode() == GPIO.BCM and self.GPIOMode == 'BCM'): return pin elif GPIO.getmode() == GPIO.BOARD and self.GPIOMode == 'BCM': return self._gpio_bcm_to_board(pin) elif GPIO.getmode() == GPIO.BCM and self.GPIOMode == 'BOARD': return self._gpio_board_to_bcm(pin) else: return 0
def get_settings_defaults(self): return dict( GPIOMode = 'BOARD', switchingMethod = 'GCODE', onoffGPIOPin = 0, invertonoffGPIOPin = False, onGCodeCommand = 'M80', offGCodeCommand = 'M81', onSysCommand = '', offSysCommand = '', enablePseudoOnOff = False, pseudoOnGCodeCommand = 'M80', pseudoOffGCodeCommand = 'M81', postOnDelay = 0.0, disconnectOnPowerOff = False, sensingMethod = 'INTERNAL', senseGPIOPin = 0, invertsenseGPIOPin = False, senseGPIOPinPUD = '', senseSystemCommand = '', autoOn = False, autoOnTriggerGCodeCommands = "G0,G1,G2,G3,G10,G11,G28,G29,G32,M104,M106,M109,M140,M190", enablePowerOffWarningDialog = True, powerOffWhenIdle = False, idleTimeout = 30, idleIgnoreCommands = 'M105', idleTimeoutWaitTemp = 50 )
def setup(self): """ setup GPIO pins and start GPIO PWM """ from RPLCD import CharLCD from RPi import GPIO as GPIO GPIO.setup(self.pin_contrast, GPIO.OUT) self.lcd = CharLCD(pin_rs=self.pin_rs, pin_rw=self.pin_rw, pin_e=self.pin_e, pins_data=self.pins_data, numbering_mode=GPIO.BOARD, cols=Display.COLUMNS, rows=Display.ROWS, dotsize=8) self.lcd.cursor_pos = (0, 0) # the contrast needs a curtain current, found value by try and error self.contrast = GPIO.PWM(self.pin_contrast, 1000) self.contrast.start(40)
def init(): gpio.setmode(GPIO.BOARD) GPIO.setup(Motor1A,GPIO.OUT) GPIO.setup(Motor1B,GPIO.OUT) GPIO.setup(Motor1E,GPIO.OUT) GPIO.setup(Motor2A,GPIO.OUT) GPIO.setup(Motor2B,GPIO.OUT) GPIO.setup(Motor2E,GPIO.OUT)
def _configure_gpio(self): if not self._hasGPIO: self._logger.error("RPi.GPIO is required.") return self._logger.info("Running RPi.GPIO version %s" % GPIO.VERSION) if GPIO.VERSION < "0.6": self._logger.error("RPi.GPIO version 0.6.0 or greater required.") GPIO.setwarnings(False) for pin in self._configuredGPIOPins: self._logger.debug("Cleaning up pin %s" % pin) try: GPIO.cleanup(self._gpio_get_pin(pin)) except (RuntimeError, ValueError) as e: self._logger.error(e) self._configuredGPIOPins = [] if GPIO.getmode() is None: if self.GPIOMode == 'BOARD': GPIO.setmode(GPIO.BOARD) elif self.GPIOMode == 'BCM': GPIO.setmode(GPIO.BCM) else: return if self.sensingMethod == 'GPIO': self._logger.info("Using GPIO sensing to determine PSU on/off state.") self._logger.info("Configuring GPIO for pin %s" % self.senseGPIOPin) if self.senseGPIOPinPUD == 'PULL_UP': pudsenseGPIOPin = GPIO.PUD_UP elif self.senseGPIOPinPUD == 'PULL_DOWN': pudsenseGPIOPin = GPIO.PUD_DOWN else: pudsenseGPIOPin = GPIO.PUD_OFF try: GPIO.setup(self._gpio_get_pin(self.senseGPIOPin), GPIO.IN, pull_up_down=pudsenseGPIOPin) self._configuredGPIOPins.append(self.senseGPIOPin) except (RuntimeError, ValueError) as e: self._logger.error(e) if self.switchingMethod == 'GPIO': self._logger.info("Using GPIO for On/Off") self._logger.info("Configuring GPIO for pin %s" % self.onoffGPIOPin) try: if not self.invertonoffGPIOPin: initial_pin_output=GPIO.LOW else: initial_pin_output=GPIO.HIGH GPIO.setup(self._gpio_get_pin(self.onoffGPIOPin), GPIO.OUT, initial=initial_pin_output) self._configuredGPIOPins.append(self.onoffGPIOPin) except (RuntimeError, ValueError) as e: self._logger.error(e)