本文整理汇总了Python中Adafruit_GPIO.I2C.get_default_bus方法的典型用法代码示例。如果您正苦于以下问题:Python I2C.get_default_bus方法的具体用法?Python I2C.get_default_bus怎么用?Python I2C.get_default_bus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_GPIO.I2C
的用法示例。
在下文中一共展示了I2C.get_default_bus方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None,
gpio=None, spi=None, i2c_bus=I2C.get_default_bus(), i2c_address=SSD1306_I2C_ADDRESS):
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 gpio is not None else GPIO.get_platform_gpio()
# Setup reset pin.
self._rst = rst
self._gpio.setup(self._rst, GPIO.OUT)
# Handle hardware SPI
if spi is not None:
self._log.debug('Using hardware SPI')
self._spi = spi
# 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_bus is not None:
self._log.debug('Using hardware I2C')
self._i2c = I2C.Device(i2c_address, i2c_bus)
else:
raise ValueError('Unable to determine if using SPI or I2C.')
# 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)
示例2: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def __init__(self, address=MCP9808_I2CADDR_DEFAULT, busnum=I2C.get_default_bus()):
"""Initialize MCP9808 device on the specified I2C address and bus number.
Address defaults to 0x18 and bus number defaults to the appropriate bus
for the hardware.
"""
self._logger = logging.getLogger('Adafruit_MCP9808.MCP9808')
self._device = I2C.Device(address, busnum)
示例3: _configure_logging
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def _configure_logging(self):
logging.basicConfig(level=logging.WARNING,
format='%(asctime)-15s %(levelname)-5s %(message)s')
# TODO put log configuration in a (yaml) config file
# The basic config doesn't hold through tests
radio_logger = logging.getLogger("RPiNWR")
radio_logger.setLevel(logging.DEBUG)
radio_log_handler = logging.FileHandler("radio.log", encoding='utf-8')
radio_log_handler.setFormatter(logging.Formatter(fmt='%(asctime)-15s %(levelname)-5s %(message)s', datefmt=""))
radio_log_handler.setLevel(logging.DEBUG)
radio_logger.addHandler(radio_log_handler)
message_logger = logging.getLogger("RPiNWR.same.message")
message_logger.setLevel(logging.DEBUG)
message_log_handler = logging.FileHandler("messages.log", encoding='utf-8')
message_log_handler.setFormatter(logging.Formatter(datefmt=""))
message_log_handler.setLevel(logging.DEBUG) # DEBUG=test, INFO=watches & emergencies, WARN=warnings
message_logger.addHandler(message_log_handler)
# Since this is logging lots of things, best to not also log every time we check for status
try:
import Adafruit_GPIO.I2C as i2c
i2cLogger = logging.getLogger('Adafruit_I2C.Device.Bus.{0}.Address.{1:#0X}'
.format(i2c.get_default_bus(), 0x11))
except ImportError:
i2cLogger = logging.getLogger(
'Adafruit_I2C.Device.Bus') # a little less specific, but probably just as good
i2cLogger.addFilter(Radio.exclude_routine_status_checks)
示例4: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def __init__(self, mode=BMP280_STANDARD, address=BMP280_I2CADDR,
busnum=I2C.get_default_bus()):
self._logger = logging.getLogger('Adafruit_BMP.BMP280')
# Check that mode is valid.
if mode not in [BMP280_ULTRALOWPOWER, BMP280_STANDARD, BMP280_HIGHRES, BMP280_ULTRAHIGHRES]:
raise ValueError('Unexpected mode value {0}. Set mode to one of BMP280_ULTRALOWPOWER, BMP280_STANDARD, BMP280_HIGHRES, or BMP280_ULTRAHIGHRES'.format(mode))
self._mode = mode
# Create I2C device.
self._device = I2C.Device(address, busnum)
# Load calibration values.
self._load_calibration()
示例5: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def __init__(self, address=SI1145_ADDR, busnum=I2C.get_default_bus()):
self._logger = logging.getLogger('SI1145')
# Create I2C device.
self._device = I2C.Device(address, busnum)
#reset device
self._reset()
# Load calibration values.
self._load_calibration()
示例6: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
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 the MCP23008 device.
self._mcp = MCP.MCP23008(address=address, busnum=busnum)
# Initialize LCD (with no PWM support).
super(Adafruit_CharLCDBackpack, self).__init__(LCD_BACKPACK_RS, LCD_BACKPACK_EN,
LCD_BACKPACK_D4, LCD_BACKPACK_D5, LCD_BACKPACK_D6, LCD_BACKPACK_D7,
cols, lines, LCD_BACKPACK_LITE, enable_pwm=False, gpio=self._mcp)
示例7: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def __init__(self, mode=TMP007_CFG_16SAMPLE, address=TMP007_I2CADDR,
busnum=I2C.get_default_bus()):
self._logger = logging.getLogger('TMP007')
# Check that mode is valid.
if mode not in [TMP007_CFG_1SAMPLE, TMP007_CFG_2SAMPLE, TMP007_CFG_4SAMPLE, TMP007_CFG_8SAMPLE, TMP007_CFG_16SAMPLE]:
raise ValueError('Unexpected mode value {0}. Set mode to one of TMP007_CFG_1SAMPLE, TMP007_CFG_2SAMPLE, TMP007_CFG_4SAMPLE, TMP007_CFG_8SAMPLE or TMP007_CFG_16SAMPLE'.format(mode))
self._mode = mode
# Create I2C device.
self._device = I2C.Device(address, busnum)
# Load calibration values.
self._load_calibration()
示例8: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def __init__(self, address=SI1145_ADDR, busnum=I2C.get_default_bus()):
''' (default [I2C address of SI1145=0x60], [I2C bus number])
intitalizes to default mode (UV,Vis,IR and Prox 1)
enables all interupts and starts in autonomous mode'''
self._logger = logging.getLogger('SI1145')
# Create I2C device.
self._device = I2C.Device(address, busnum)
#reset device
self._reset()
# Load calibration values, default settings, enables interupts
# and starts in autonomous mode.
self._load_setup()
示例9: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def __init__(self, mode=BMP085_STANDARD, address=BMP085_I2CADDR,
busnum=I2C.get_default_bus()):
self._logger = logging.getLogger('Adafruit_BMP.BMP085')
# Check that mode is valid.
if mode not in [BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, BMP085_ULTRAHIGHRES]:
raise ValueError('Unexpected mode value {0}. Set mode to one of BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, or BMP085_ULTRAHIGHRES'.format(mode))
self._mode = mode
# Create I2C device.
self._device = I2C.Device(address, busnum)
#(chip_id, version) = bus.read_i2c_block_data(addr, 0xD0, 2)
chip_id = self._device.readU8(0xD0)
version = self._device.readU8(0xD0 + 1)
self._logger.debug('Chip Id: {0} Version: {1}'.format(chip_id, version))
# Load calibration values.
self._load_calibration()
self._compute_polynomials()
self.temperature=None
示例10: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
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)
示例11: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def __init__(self, addr, desc='I2C Sensor', busnum=None):
"""
Parameters
-----------
addr : int
i2c sensor address. Can be specified as (for example) 0x10
desc : string
Human-readable description to identify this sensor
busnum : int or None
The number of the I2C device to connect to. For example,
to connect to /dev/i2c-0, put 0. To connect to the default
bus, put None.
"""
self._address = addr
self._description = desc
# Open the bus
if busnum == None:
busnum = I2C.get_default_bus()
self._bus = smbus.SMBus(busnum)
示例12: test_beaglebone_black
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def test_beaglebone_black(self):
I2C = safe_import_i2c()
bus = I2C.get_default_bus()
self.assertEqual(bus, 1)
示例13: test_raspberry_pi_rev2
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def test_raspberry_pi_rev2(self):
I2C = safe_import_i2c()
bus = I2C.get_default_bus()
self.assertEqual(bus, 1)
示例14: __init__
# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_default_bus [as 别名]
def __init__(self, address=DEFAULT_ADDRESS, busnum=I2C.get_default_bus()):
"""Create an HT16K33 driver for devie on the specified I2C address
(defaults to 0x70) and I2C bus (defaults to platform specific bus).
"""
self._i2c = I2C.Device(address, busnum)
self.buffer = bytearray([0]*16)