Re: Read switch with MCP23017
adafruit_support_rick wrote:You have to configure the pin as input:
the power on state for the i/o direction registers is 0xff - all inputs. also the constructor for the mcp230xx class sets those bits.
- Code: Select all | TOGGLE FULL SIZE
def __init__(self, address, num_gpios=8, busnum=-1, debug=False):
assert 0 < num_gpios < 17, "Number of GPIOs must be between 1 and 16"
self.i2c = Adafruit_I2C(address, busnum, debug)
self.num_gpios = num_gpios
self.pullups = 0
# Set default pin values -- all inputs with pull-ups disabled.
# Current OLAT (output) value is polled, not set.
if num_gpios <= 8:
self.direction = 0xFF
self.i2c.write8(self.MCP23008_GPPU , self.pullups)
self.outputvalue = self.i2c.readU8(self.MCP23008_OLAT)
self.direction = 0xFFFF
self.i2c.write16(self.MCP23017_GPPUA , self.pullups)
self.outputvalue = self.i2c.readU16(self.MCP23017_OLATA)
i tried giving that advise myself, once, and got shot down.
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly