本文整理汇总了Python中RPi.GPIO.BCM属性的典型用法代码示例。如果您正苦于以下问题:Python GPIO.BCM属性的具体用法?Python GPIO.BCM怎么用?Python GPIO.BCM使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类RPi.GPIO
的用法示例。
在下文中一共展示了GPIO.BCM属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
def main():
"""Calculate the distance of an object in centimeters using a HCSR04 sensor
and a Raspberry Pi"""
# Use GPIO.BOARD values instead of BCM
trig_pin = 11
echo_pin = 13
gpio_mode = GPIO.BOARD # library uses GPIO.BCM by default
# Default values
# unit = 'metric'
# temperature = 20
# Create a distance reading with the hcsr04 sensor module
# using GPIO.BOARD pin values.
value = sensor.Measurement(trig_pin, echo_pin, gpio_mode=gpio_mode)
raw_measurement = value.raw_distance()
# Calculate the distance in centimeters
print("The Distance = {} centimeters".format(round(raw_measurement, 1)))
示例2: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
def __init__(self, address=0x40):
"""
init object with i2c address, default is 0x40 for ServoPi board
:param address: device i2c address, defaults to 0x40
:type address: int, optional
"""
self.__address = address
self.__bus = self.__get_smbus()
self.__write(self.__MODE1, self.__mode1_default)
self.__write(self.__MODE2, self.__mode2_default)
GPIO.setwarnings(False)
mode = GPIO.getmode() # check if the GPIO mode has been set
if (mode == 10): # Mode set to GPIO.BOARD
self.__oe_pin = 7
elif (mode == 11): # Mode set to GPIO.BCM
self.__oe_pin = 4
else: # Mode not set
GPIO.setmode(GPIO.BOARD)
self.__oe_pin = 7
GPIO.setup(self.__oe_pin, GPIO.OUT)
示例3: initButtons
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
def initButtons():
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(9, GPIO.IN, pull_up_down=GPIO.PUD_UP)
示例4: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
def __init__(self, numbering_mode=GPIO.BCM, pin_rs = None, pin_rw = None, pin_e = None, pins_data = None, pin_backlight = None, backlight_mode = 'active_low', backlight_enabled = True):
self.type = 'gpio'
self.numbering_mode = numbering_mode
self.pin_rs = pin_rs
self.pin_rw = pin_rw
self.pin_e = pin_e
self.pins_data = pins_data
self.pin_backlight = pin_backlight
self.backlight_mode = backlight_mode
self.backlight_enabled = backlight_enabled
示例5: _gpio_get_pin
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
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
示例6: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
def __init__(self, pin_rs=27, pin_e=22, pins_db=[25, 24, 23, 18], GPIO = None):
# Emulate the old behavior of using RPi.GPIO if we haven't been given
# an explicit GPIO interface to use
if not GPIO:
import RPi.GPIO as GPIO
self.GPIO = GPIO
self.pin_rs = pin_rs
self.pin_e = pin_e
self.pins_db = pins_db
self.used_gpio = self.pins_db[:]
self.used_gpio.append(pin_e)
self.used_gpio.append(pin_rs)
self.GPIO.setwarnings(False)
self.GPIO.setmode(GPIO.BCM)
self.GPIO.setup(self.pin_e, GPIO.OUT)
self.GPIO.setup(self.pin_rs, GPIO.OUT)
for pin in self.pins_db:
self.GPIO.setup(pin, GPIO.OUT)
self.write4bits(0x33) # initialization
self.write4bits(0x32) # initialization
self.write4bits(0x28) # 2 line 5x7 matrix
self.write4bits(0x0C) # turn cursor off 0x0E to enable cursor
self.write4bits(0x06) # shift cursor right
self.displaycontrol = self.LCD_DISPLAYON | self.LCD_CURSOROFF | self.LCD_BLINKOFF
self.displayfunction = self.LCD_4BITMODE | self.LCD_1LINE | self.LCD_5x8DOTS
self.displayfunction |= self.LCD_2LINE
""" Initialize to default text direction (for romance languages) """
self.displaymode = self.LCD_ENTRYLEFT | self.LCD_ENTRYSHIFTDECREMENT
self.write4bits(self.LCD_ENTRYMODESET | self.displaymode) # set the entry mode
self.clear()
示例7: setup_gpio
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
def setup_gpio(self):
try:
current_mode = GPIO.getmode()
set_mode = GPIO.BOARD if self._settings.get(["use_board_pin_number"]) else GPIO.BCM
if current_mode is None:
outputs = list(filter(
lambda item: item['output_type'] == 'regular' or item['output_type'] == 'pwm' or item[
'output_type'] == 'temp_hum_control' or item['output_type'] == 'neopixel_direct',
self.rpi_outputs))
inputs = list(filter(lambda item: item['input_type'] == 'gpio', self.rpi_inputs))
gpios = outputs + inputs
if gpios:
GPIO.setmode(set_mode)
tempstr = "BOARD" if set_mode == GPIO.BOARD else "BCM"
self._logger.info("Setting GPIO mode to %s", tempstr)
elif current_mode != set_mode:
GPIO.setmode(current_mode)
tempstr = "BOARD" if current_mode == GPIO.BOARD else "BCM"
self._settings.set(["use_board_pin_number"], True if current_mode == GPIO.BOARD else False)
warn_msg = "GPIO mode was configured before, GPIO mode will be forced to use: " + tempstr + " as pin numbers. Please update GPIO accordingly!"
self._logger.info(warn_msg)
self._plugin_manager.send_plugin_message(self._identifier,
dict(is_msg=True, msg=warn_msg, msg_type="error"))
GPIO.setwarnings(False)
except Exception as ex:
self.log_error(ex)
示例8: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
def __init__(
self, trig_pin, echo_pin, temperature=20, unit="metric", gpio_mode=GPIO.BCM
):
self.trig_pin = trig_pin
self.echo_pin = echo_pin
self.temperature = temperature
self.unit = unit
self.gpio_mode = gpio_mode
self.pi = math.pi
示例9: test_basic_distance_bcm
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
def test_basic_distance_bcm():
"""Test that float returned with default, positive and negative temps"""
GPIO.setmode(GPIO.BCM)
x = Measurement
basic_reading = x.basic_distance(TRIG_PIN, ECHO_PIN)
basic_reading2 = x.basic_distance(TRIG_PIN, ECHO_PIN, celsius=10)
basic_reading3 = x.basic_distance(TRIG_PIN, ECHO_PIN, celsius=0)
basic_reading4 = x.basic_distance(TRIG_PIN, ECHO_PIN, celsius=-100)
assert type(basic_reading) == float
assert type(basic_reading2) == float
assert type(basic_reading3) == float
assert type(basic_reading4) == float
GPIO.cleanup((TRIG_PIN, ECHO_PIN))
示例10: _configure_gpio
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BCM [as 别名]
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)