How in the world do you get the MCP23S17 to work with the Arduino?

Thread Starter

317andrew317

Joined Jan 11, 2016
3
I have spent countless days trying to get this thing to work. For anyone that has gotten it to work, what libraries are you using? I found two MCP23S1.h libraries. One is by dreamcat4 and the other by Cort Buffington. The dreamcat4 one is old and requires an outdated Spi.h library which cannot be found on the internet. Mr. Buffington's is newer, but just flat out does not work for me. There is literally nothing on the internet on how to get these dang things to work. All I want to do it light up one led, how hard can this be? I tied A0-A2 to ground so my address is 000, I tied reset to 5V, and the serial pins to the respective ones on the Arduino. It has 16 I/O pins and all I want to do is light up one led! I have never gotten this chip to work since I bought it, I've used shift registers but not these guys. It would also be really helpful to see someone's code on how to light up just one led with this chip and what library you are using. Any help would be deeply appreciated!
 

Thread Starter

317andrew317

Joined Jan 11, 2016
3
Here is some code I wrote using Cort Buffington's MCP23S17.h library:

#include <SPI.h>
#include <MCP23S17.h>

MCP iochip(0);

void setup() {
iochip.pinMode(1, LOW);
iochip.pinMode(9, LOW);
}


void loop() {
iochip.digitalWrite(1, HIGH);
iochip.digitalWrite(9, HIGH);
delay(1000);
iochip.digitalWrite(1, LOW);
iochip.digitalWrite(9, LOW);
delay(1000);
}

I wrote it as simple as possible, but yet it still doesn't work? It's unfathomable why this is happening.
 

dmorey85

Joined Jul 22, 2015
3
Hi Andrew,

I am in the same situation with as you seem to be, could you please help me out I am at my wits end, I have a project that requires more ports as digital write so need the MCP. Could you please message me with your final code and maybe your circuit digram so that I could see the connections (double check mine are correct).

Thanks

Dave
 
Here is some code I wrote using Cort Buffington's MCP23S17.h library:

#include <SPI.h>
#include <MCP23S17.h>

MCP iochip(0);

void setup() {
iochip.pinMode(1, LOW);
iochip.pinMode(9, LOW);
}


void loop() {
iochip.digitalWrite(1, HIGH);
iochip.digitalWrite(9, HIGH);
delay(1000);
iochip.digitalWrite(1, LOW);
iochip.digitalWrite(9, LOW);
delay(1000);
}

I wrote it as simple as possible, but yet it still doesn't work? It's unfathomable why this is happening.
 
I have spent countless days trying to get this thing to work. For anyone that has gotten it to work, what libraries are you using? I found two MCP23S1.h libraries. One is by dreamcat4 and the other by Cort Buffington. The dreamcat4 one is old and requires an outdated Spi.h library which cannot be found on the internet. Mr. Buffington's is newer, but just flat out does not work for me. There is literally nothing on the internet on how to get these dang things to work. All I want to do it light up one led, how hard can this be? I tied A0-A2 to ground so my address is 000, I tied reset to 5V, and the serial pins to the respective ones on the Arduino. It has 16 I/O pins and all I want to do is light up one led! I have never gotten this chip to work since I bought it, I've used shift registers but not these guys. It would also be really helpful to see someone's code on how to light up just one led with this chip and what library you are using. Any help would be deeply appreciated!
Hi Andrew, first of all, let me say that this library does work despite the errors in the Arduino documentation. There are two omissions in your code, the first being the pin number of the SPI SS pin which is normally pin 10. The line MCP iochip(0) should in fact be MCP iochip(0,10);
If you redefine the SS pin using #define SS 9 for example you should set that in the line MCP iochip(0,9); The second omission is the line: iochip.begin(); which starts the arduino communicating with the MCP23S17.
Finally, and this is an error in the documentation, the lines
iochip.pinMode(1, LOW);
iochip.pinMode(9, LOW);

should in fact be :

iochip.pinMode(1, OUTPUT);
iochip.pinMode(9, OUTPUT);

Your final code should look like this.
#include <SPI.h>
#include <MCP23S17.h>

MCP iochip(0,10);

void setup() {
iochip.begin();
iochip.pinMode(1, OUTPUT);
iochip.pinMode(9, OUTPUT);
}
void loop() {
iochip.digitalWrite(1, HIGH);
iochip.digitalWrite(9, HIGH);
delay(1000);
iochip.digitalWrite(1, LOW);
iochip.digitalWrite(9, LOW);
delay(1000);
}
A final word of warning that using iochip.digitalWrite(value) to write a 16-bit word doesn't work. Instead use iochip.wordWrite(value).

Good luck
Jasper
 
Top