Hello!
I have recently bought 6 MCP23017 pin expanders. They use the I2C bus, which I am not familiar with. I have only wired an MPU6050, and that worked fine, so I thought that I had the confidence to buy a second set of I2C devices.
After a few days of trying to get these pin expanders working on an Arduino Mega, I cannot seem to reach my goal. Specifically, my goal is to print a set of 1's and 0's while a button is being pressed and released using the MCP23017's internal pullup resistors. All that occurs is I get a string of 0's even though a button is supposed to return 1 while not being pressed in this configuration. Lighting up an LED also does nothing. It remains dark.
I have wired the pushbutton so that the left leg is connected to a 10k ohm resistor and the right leg is connected to pin 1 of the MCP23017 (GPB0).
I have connected pin 12 of the chip (SCL) to pin 21 on the Arduino Mega, and pin 13 of the MCP (SDA) to 20 of the Mega.
The MCP's pin 9 (VDD) was connected to 5v, and pin 10 (VSS) was connected to GND.
Pins 15, 16, and 17 (A0, A1, A2) were connected together and then wired to GND.
I have tried to link a photo of my wiring in this post, and I hope that it will show all of the deltails that I have described above with more ease.
(Please note that, though not shown in the image, there are small wires connecting A0, A1, and A2)
My code is as follows:
//----------------------------------------------
#include <Wire.h>
#include <Adafruit_MCP23017.h>
Adafruit_MCP23017 mcp;
void setup() {
Serial.begin(9600);
Wire.begin();
mcp.begin();
mcp.pinMode(0,INPUT_PULLUP);
}
void loop() {
Serial.println(mcp.digitalRead(0));
}
//----------------------------------------------
Based on looking around on varoius different electronics websites, pin 1 is addressed as "0" in the code because of its formal name: "GPB0"
In addition to everything stated before, I would like to note that I have also tried wiring an LED with a 220 ohm, and then later, a 10k ohm resistor.
I am hoping that this is just a simple error on my part, and it is most likely the case. I really like the SPI bus, so I guess that I2C just isn't a thing I am good at. Hopefully, your response could change that.
Thank you for any thoughts or suggestions you may have!





