MCP23017 Library Port

Can someone help me or guide me as to how to port the Adafruit_MCP23017 library to Spark Core:

Thanks in advance!

@Carsten4207, this library is almost Spark ready! It just needs some minor massaging. I can do that in a few minutes for you. Did you want the examples ported as well? :smile:

1 Like

That’d be awesome! Thank you very much!!!

@Carsten4207, I ported the library, compiled it and published it on the web IDE. I will leave it up to you to test. Don’t forget that the Spark requires pull-up resistors on the I2C lines to work correctly. Usually, 4.7K ohm resistors connected to 3.3V are fine. Let me know how it goes :smile:

1 Like

It works!

Is it possible for us users to contribute to the libraries? I would like to update the comments so they reflect to the Spark Core!

Thanks again! Send me your Paypal and I’ll send you some $$ for the help!


1 Like

@Carsten4207, let me what comments to add and I will update. As for the $$, this is what this community is all about - helping each other :wink:


Just in the example the comments say the i2c bus is on Analog 3/4. Should be D0/D1. No big deal though.

Thanks again! Really appreciate it.


1 Like

@Carsten4207, I updated the comments in the examples as requested :smile:

1 Like


I am using the mcp23017 library for a project and am trying to get the button example working before I move on. I have connected the pull-ups, reset resistor, A0-A2, and Vdd and Vss as instructed. I am scoping the I2C lines and getting nothing. Any thoughts?

And for more debugging clues if I completely disconnect the mcp23017, the I2C lines from the spark core work. Once I connect the lines to the port expander they are held low…

@chad_bean, any chance you can share a wiring diagram, table or schematic? I need to understand how everything is hooked up. :smile:

I’m using the 2 green jumpers as my switch to ground. Later last night I hooked up SDA and SCL from this breadboard to an uno and it worked first try, so i doubt its the mcp23017 hook-up configuration, it seems to be the core.

Even though I am using the button example the I2C pins DO and D1 don’t have any output (hooked up to the I/O expander or not). Just to make sure that the physical pins on the uC weren’t blown I ran a blinky variation to show that they can both still be used as inputs and outputs.

I’ve also been through the library pretty thoroughly and it seems fine especially since it works for others. Is there any way I could have corrupted some middleware on the spark to cause it not to work with wire? seems absurd but this is an extremely simple task that I can’t come up with an explanation for.

Thanks for the reply btw!

@chad_bean, can you share your app code so we can see if there is any issue?

All I have changed from the button example is pin 13 to D7.

Adafruit_MCP23017 mcp;
void setup() {  
  mcp.begin();      // use default address 0
  mcp.pinMode(0, INPUT);
  mcp.pullUp(0, HIGH);  // turn on a 100K pullup internally
  pinMode(D7, OUTPUT);

void loop() {
  // The LED will 'echo' the button
  digitalWrite(D7, digitalRead(0));

@chad_bean, you are missing one tiny bit that you may have accidentally deleted when you changed D7. The line in loop() should read:

digitalWrite(D7, mcp.digitalRead(0));

You are missing the “mcp.” part! :smile:

1 Like

Oops i did get rid of that on accident at some point, but I was testing w/ mcp.digitalRead(0) before and even now that I’ve fixed it still nothing :confused:

@chad_bean, try tying the RST line directly to Vdd (3.3v) instead of through a resistor. Also, if you have an LED, test to see if you can output to a pin like @Carsten4207 did.

Still nothing… Does “factory resetting” the core do anything but erase wifi credentials and firmware? The I2C lines still aren’t even trying to communicate. After MCU reset the SDA line stays low and SCL pulls up to 3.3V, then they just stay static.

@chad_bean, factory reset will also replace the firmware with the Tinker app. It is possible your MCP23017 is not working. Do you have an Arduino board you could test it with?