Multiples MCP23017


Hi guys
I’m using 2 MCP23017, I have read some topics for the use of multiple MCP23017 and in one of them says just to identify the second unit with a different address number from the first one, and that should do the job.
I tried this, and got the problem that even though I assign chip one as (0), default address, and chip 2 with a (1) whenever I turn on a digital output of mcp1, the same output is turn on, on mcp2.

Am I doing something wrong?

Here’s the example code I made for it

#include <Adafruit_MCP23017.h>
#include <Wire.h>

Adafruit_MCP23017 mcp1;
Adafruit_MCP23017 mcp2;

void setup()
    pinMode(A4, INPUT);
    pinMode(A5, INPUT);
    mcp1.begin(0); //default address
    mcp2.begin(1); //different address
    for(int i = 0; i <= 15; i++)
        mcp1.pinMode(i, OUTPUT);
        mcp2.pinMode(i, OUTPUT);
    for(int i = 0; i <= 15; i++)
        mcp1.digitalWrite(i, LOW);
        mcp2.digitalWrite(i, LOW);

void loop() 
    if(digitalRead(A4) == HIGH)
        mcp1.digitalWrite(0, HIGH);
    if(digitalRead(A5) == HIGH)
        mcp2.digitalWrite(0, HIGH);
        mcp1.digitalWrite(0, LOW);
        mcp2.digitalWrite(0, LOW);   


@dsn101, the “address” in question is actually the an offset of the base I2C address of the MCP23017 device you are configuring. If you are using an MCP23017 breakout, these boards will usually have solder or other jumpers to configure the board’s address “offset” from the base addres of 0x20. The MCP23017 has three address bits meaning you can have up to eight of these devices on the I2C bus. You need to set the address jumpers for the second MCP23017 address to 1. :wink:


Sorry guys, already figure it out, I put pin 15 of the second MCP to voltage and keep pint 15 of the first one to ground.
What I understand is that, leaving the pins 15-17 will generate a default address(000), while putting one of them to voltage will set an address.


Thank you peekay123!!
Thank you for taking the time to answer me. I did find out reading a couple of arduino forums and the datasheet of the mcp about the address pin. I thought that I post the answer a couple of hours ago, but seems like I forgot to hit “reply” on my own post. Anyway, thank you!


Are you using the bare sensor or a breakout?
Usually breakouts don’t behave that way. The usually have pull-down/-up resistors on board any the user is only required to cut or solder a jumper to avoid the need for extra wiring between the board and the controler. Wiring the address lines to the controler would only make (limited) sense if you’d want to change the address dynamically.


Sorry, I was using the bare IC, not a breakout.
Thank you for your help.