Mcp23017 unable to read values?

mcp23017 does not modify read values ?

i have switches to connect mcp-pins i.e 0 to 2 with ground = LOW-Level
i guess, with input_pullup they are connected to VCC = HIGH-Level per default

But modifyfing the switch-status Nothing changes, always event-values are 1 !

//-mcp23xxx_wLCD_test_input2.ino for Nano
//- Status : 30.09.2025
//- Release : 1.0
//-Should show Values read from 3 pins of mc23017
//-Input is done by electric switches to ground
#include <Wire.h>
//- ergaenzt durch LCD-Anzeige zur Adressklaerung
#include <Adafruit_MCP23X17.h>

#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>

hd44780_I2Cexp lcd = hd44780_I2Cexp(0x27, 16, 2);

Adafruit_MCP23X17 mcp;

// LCD geometry
const uint8_t LCD_COLS = 16;
const uint8_t LCD_ROWS = 2;

uint8_t lcd_status = 0;
String message = "";

int input_pins[3] = { 0,1,2 };
int event_values[3] = { 0, 0, 0 };


void setup() {
  Serial.begin(9600);

  lcd_status = lcd.begin(LCD_COLS, LCD_ROWS);
  //Serial.println("LCD-Status : " + String(lcd_status));
  if (lcd_status)  // non zero status means it was unsuccessful
  {
    // begin() failed so blink error code using the onboard LED if possible
    //hd44780::fatalError(status); // does not return
  }

  message = "mcp23xxx_wLCD_test_input2 Nano 1.0";
  Serial.println(message);
  lcd.clear();
  lcd.lineWrap();
  lcd.print(message);
  delay(1000);

  //while (!Serial);
  //Serial.println("mcp23xxx_wLCD_test_input2 Nano 1.0");

  if (!mcp.begin_I2C(0x58))
  //if (!mcp.begin_I2C(0x23))
  {
    Serial.println("MCP-Error.");
    lcd.clear();
    lcd.print("MCP-Error.");
    while (1)
      ;
  }
  lcd.clear();
  lcd.print("MCP ok !");

  for (int i = 0; i < 3; i++) {
    mcp.pinMode(input_pins[i], INPUT_PULLUP);
  }

  message = "Setup ready";
  Serial.println(message);
  lcd.clear();
  lcd.print(message);
  delay(3000);
}

void loop() {

  for (int i = 0; i < 3; i++) {
    event_values[i] = mcp.digitalRead(input_pins[i]);
    lcd.clear();
    lcd.print("i : " + String(i) + " Event-Val : " + String(event_values[i]));
    delay(1000);
  }
}


Dont see what could be wrong…please help !

p.s.: in the example which comes with the mcp.library no info is found,

where the button is connted to electrically..:thinking:

How to wire a button when a GPIO pin has a pullup resistor is explained in tutorials like https://docs.arduino.cc/tutorials/generic/digital-input-pullup/

So in the case of your MCP23017, the e.g. upper side of your button (connected across the breadboard) goes to GND, while the lower side of the button goes to GP0 of the MCP23017.

When you take a wire from GP0 to GND, is it recognized as 0?

ive just tested it..nothing changes..

Do you use a breakout board for the MCP23017 or do you use the raw chip? How is everything wired up between the Arduino (which arduino?) and the MCP23017?

Don't see what could be wrong either, but I suspect wiring, which we also can't see. A clear, well lit, in focus picture of your wiring would go a long way to rectifying that.

its a breakout-board and connetion to arduino nano is i2c, have tested

with scanner which recognized mcp at 0x58 and lcd at 0x27

what seems to be ok so far..

Which pins on the chip are you using as 0,1,2?

Take a look at this pin addressing table

https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library?tab=readme-ov-file#pin-addressing

How is this possible? The 8-bit I2C address of an MCP23017 can only be, at maximum, from the datasheet

be the binary value 01001110 which would be 0x4e. If all A2, A1 and A0 pins are GND of the MCP23017, which they should by default, it should appear at address 0x20. (The Adafruit library agrees with my default address)

I suspect your GPIO expander for the LCD is appearing under 2 I2C addresses and your MCP23017 is not connected corerctly at all.

Can you disconnect the LCD, have only the MCP23017 connected and run the I2C scanner again? Does it see any devices?

at moment thats pins PA0,1,2

thanks for the pins table !

what should i use : PIN-ID or Pin# ?

Always Pin ID.

so pins adresses are ok,

but i’ll check i2c-issues..

dont proceed now..go to bed and check tommorow, sorry !

mnany thanks and have good night all together..