Closed derianlebreton closed 2 years ago
MCP23017/MCP23008 have 7-bit I2C address decoding, with 4 bits fixed.
When you set A0, A1 and A2 to 0, your address is 0x20. So use this:
mcp0.begin(0x20);
Yep, what @bergernetch said. See datasheet for details.
If uncertain, can do an I2C scan to determine addresses: https://learn.adafruit.com/scanning-i2c-addresses/arduino
Closing, can reopen if still an issue with correct addressing.
Arduino board: QTPY
Arduino IDE version: 1.8.16
List the steps to reproduce the problem below (if possible attach a sketch or copy the sketch code in too):
1x QTPY microcontroller, providing 3.3V and GND 1x mcp23017 at I2C address 0x00 (pins A0, A1, A2 connected to GND) mcp 23017 ~reset line pulled to 3.3V via 100kΩ 0.1 uF and 10uF caps on 3.3V 2.2kΩ pull-ups to 3.3V on SCK and SCL pins from QTPY One mcp23017 IO pin pulled high to make sure I'm really reading it
When I run the following sketch, this device works as anticipated:
I get output like this:
Reading mcp0 port: 32
Which corresponds to the one wire I have pulling a pin high. However, this is not suitable for me as I need multiple mcp23017s on the I2C bus for my project. If I try to provide an I2C address in mcp0.begin_I2C(), I only get bogus data:
Reading mcp0 port: 255
I have tried 0x00, (uint8_t)0, and 0, but they all show the same broken behavior.
After reverting the library to version 1.3 and using the following code, it works as expected: