Hi to all
As English is not my Mother language and i am a self taught to programming i have issues to understand how to set up the address for multiple MCP23017 ic.
I am using the Adafruit-MCP23017-Arduino-Library for my project
The code below works fine as i used it to play with my setup (it is the default example from the library with some little changes in the pins number and how led will work)
// Controls an LED via an attached button.
// ok to include only the one needed
// both included here to make things simple for example
//#include <Adafruit_MCP23X08.h>
#include <Adafruit_MCP23X17.h>
#define LED_PIN 7 // MCP23XXX pin LED is attached to
#define BUTTON_PIN 8 // MCP23XXX pin button is attached to
// only used for SPI
//#define CS_PIN 6
// uncomment appropriate line
//Adafruit_MCP23X08 mcp;
Adafruit_MCP23X17 mcp;
void setup() {
Serial.begin(9600);
//while (!Serial);
Serial.println("MCP23xxx Combo Test!");
// uncomment appropriate mcp.begin
if (!mcp.begin_I2C()) {
//if (!mcp.begin_SPI(CS_PIN)) {
Serial.println("Error.");
while (1);
}
// configure LED pin for output
mcp.pinMode(LED_PIN, OUTPUT);
// configure button pin for input with pull up
mcp.pinMode(BUTTON_PIN, INPUT);
Serial.println("Looping...");
}
void loop() {
if (mcp.digitalRead(BUTTON_PIN) == HIGH) {
Serial.println("is HIGH");
mcp.digitalWrite(LED_PIN, HIGH);
}
else if (mcp.digitalRead(BUTTON_PIN) == LOW) {
Serial.println("is LOW");
mcp.digitalWrite(LED_PIN, LOW);
}
// mcp.digitalWrite(LED_PIN, !mcp.digitalRead(BUTTON_PIN));
}
The MCP23017 to the above example has the address setup to the 000 (i2c = 0x20) based on the table below
How to add a second MCP23017 (lets say to the chip address 001 (i2c = 0x21) ??
@caslor,
Combine the answers given by DrD and guix.
you need to tell each 23017 what it's address is, by setting jumpers on it (i.e. a hardware identity needs to be set);
you need to talk to the right address each time you talk to the 23017s(i.e. you need to talk to the right identity).
Work out both of those, and you should succeed.
C
When googling this topic you get alot of old code from when the library still used "mcp1.begin(0); mcp2.begin(1); mcp3.begin(2);" etc instead of "mcp1.begin_I2c(0x20);" and the example included on the libraries own github page doesn't even have an example showing the use of multiple chips, infact this HERE forum post is the only reference i found with the proper updated coding. Also why in the world would he google "MCP23017 using more than one arduino" when he needs to use multiple mcp23017 with a single arduino, dont put people down when you have no idea what your talking about.
Google is very robust so that's likely true. Still the first point I listed is far more relevant as to why the op couldn't just "google" and magically find the solution, I also went to the github library and requested that they add an example for using multiple mcp chips.