def _init_connection(self):
self.bus = SMBus(self._port)
if self._i2c_expander == 'PCF8574':
c.msleep(50)
elif self._i2c_expander in ['MCP23008', 'MCP23017']:
# Variable for storing data and applying bitmasks and shifting.
self._mcp_data = 0
# Set iodir register value according to expander
# If using MCP23017 set which gpio bank to use, A or B
if self._i2c_expander == 'MCP23008':
IODIR = MCP23008_IODIR
self._mcp_gpio = MCP23008_GPIO
elif self._i2c_expander == 'MCP23017':
# Set gpio bank A or B
if self._expander_params['gpio_bank'] == 'A':
IODIR = MCP23017_IODIRA
self._mcp_gpio = MCP23017_GPIOA
elif self._expander_params['gpio_bank'] == 'B':
IODIR = MCP23017_IODIRB
self._mcp_gpio = MCP23017_GPIOB
# Set IO DIRection to output on all GPIOs (GP0-GP7)
self.bus.write_byte_data(self._address, IODIR, 0x00)
评论列表
文章目录