mcp23017_smbus.py
# ! /usr/bin/python3
# -*- coding: utf-8 -*-
#
# mcp23017_smbus.py
#
# May/29/2017
#
# ----------------------------------------------------------------
import sys
import smbus
#
# ----------------------------------------------------------------
sys.stderr.write("*** start ***\n")
CHANNEL = 1
ICADDR = 0x20
REG_IODIR = 0x00
REG_GPIOB = 0x13
#
bus = smbus.SMBus(CHANNEL)
bus.write_byte_data(ICADDR, REG_IODIR, 0xff)
#
bus.write_byte_data(ICADDR, 0x0d, 0xff)
#
value = bus.read_byte_data (ICADDR,REG_GPIOB)
sys.stderr.write("value = %x\n" % value)
#
sys.stderr.write("*** end ***\n")
# ----------------------------------------------------------------