I am trying to use the MCP23017 expander chip with a Metro Mini by Adafruit (pinout below) and I can't get the microcontroller to connect reliably via I2C.
update
I connected the RESET pin to 5V and am getting some readings but then the device disconnects. It's random how many readings I get before it gets stuck, but it always gets stuck. Sometimes its during the instantiation of pinMode and other times its when the ports are being read. Why is it getting stuck and how can I keep it from happening?
Here's my code:
#include <Adafruit_MCP23X17.h>
#include <Wire.h>
#define btn 7
#define led 8
Adafruit_MCP23X17 mcp; //instantiate I/O expander
void setup() {
Wire.begin();
//I/O expander
Serial.begin(9600);
if(!mcp.begin_I2C()){
Serial.println("err");
while(1);
}
else{
Serial.println("connected");
}
for(int i=0; i<15; i++){
Serial.print(i);
mcp.pinMode(i, INPUT);
delay(100);
}
Serial.println("pins set");
//mcp.pinMode(btn, INPUT);
//mcp.pinMode(led, OUTPUT);
}
void loop() {
readBank();
}
void readBank(){
for(int i=0; i<6; i++){
Serial.print(i);
Serial.print(": ");
Serial.println(mcp.digitalRead(i));
delay(200);
}
}
The serial output with a bunch of resets looked like this before it got stuck again.
connected
012345678connected
012345678910111213connected
012345678connected
012345678910111213connected
012345678connected
0123456789connected
01234567891011connected
012345678910111213connected
0123456connected
01234567891011121314pins set
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1: 0
2: 0
3: 1
4: 1
5: 1
0: 1
1:
end of update
When I first connected it, I could get it to recognize a device sometimes for a few seconds but not long enough to test whether it was responding to any signals (button.) Now I can't get any connection at all. I've also tried using 4.7k pull ups on SDA and SCL, but no luck. I've checked the wiring about a million times and can't find any mistakes. The 5V and GND lines are connected across the breadboard (the image got cut off). I ran a scanner sketch and it says 0 devices found. What am I missing here?
-
\$\begingroup\$ Reset pin is does not appear to be connected \$\endgroup\$Mat– Mat2023年06月03日 21:28:59 +00:00Commented Jun 3, 2023 at 21:28
1 Answer 1
There may be many reasons.
Most likely ones is that the IO expander does not have the minimum required circuitry to work.
For example the address pins are unconnected so the address may be random.
Also the chip is powered by 5V. It usually means youn have to have a 5V I2C bus. Please make sure the Arduino uses 5V on I2C bus and there are pull-ups present. If the Arduino can't use 5V on I2C bus then switch to 3.3V, but the Arduino may be damaged from the 5V already.
Explore related questions
See similar questions with these tags.