gpio – Control multiple push buttons on a raspberry pi using an mcp23017 over C++
Having followed various tutorials on the web (i.e. 1,2), I have made the following connections:

To enhance clarity, I post another picture depicting the connections on the mpc23017 using a cropped frame from the official datasheet.

Even though wiringPi has been abandoned by the author, I am using this wiringPi – which is fairly maintained by the community. My code is as follows:
#include
#include
#include
int main (){
wiringPiSetupGpio();
mcp23017Setup(100, 0x20); //$ sudo i2cdetect -y 1 gives the address 20.
for (int i = 0; i < 16; ++i){
pinMode(100 + i, INPUT);
}
while( true ){
for (int i = 0; i < 16; ++i){
int sig = digitalRead(100 + i);
std::cout<
… but I am getting irrelevant output.
...
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
...
Therefore, if I may ask,
- Do you think the connections are correct? (Especially those on the A0,A1,A2,RESET pins)
- Or do you think the error lies on the code?
Other than that, what could be possibly wrong?
Read more here: Source link
