MCP23017 and arduino-mcp23017 lib

Hi,

Using "arduino-mcp23017" library (GitHub - blemasle/arduino-mcp23017: Complete support of MCP23017)

I can't seem to make it to detect +5v on input (pulling to ground with a button yes, but with 5v no)

Library says pull-up is enabled by default.

  mcp.portMode(MCP23017Port::B, 0b11111111); 
  mcp.writeRegister(MCP23017Register::IPOL_B, 0xFF);
  mcp.writeRegister(MCP23017Register::GPIO_B, 0x0);

Should I use other library and which one?

Thanks,
B

Sounds like a wiring problem, e.g. lack of common ground.

Please post a schematic of your project (hand drawn is fine), and the complete code that demonstrates the problem.

1 Like

Well... it is wiring problem, and it's not

It works fine when I put 10k resistor between MCP's pin 1 and ground...

My understanding was that MCP has a pull up resistor built in and I don't know how to enable it (which can actually be a problem)

Not useful to detect "5V". To turn pullups off make sure that register GPPU (0x06) is set to zero (which is the power up default).

If you want help, post the requested information.

need to set the GPPUA register as well

It's fun reading data sheets and getting all down on the chip, but the purpose of the library is to relieve the user from the need to understand the underlying details of the chip.

The library used provides reasonable analogs for digitalRead(), digitslWrite() and pinMode(), with the only significant difference being that the library defaults to internal pull-ups enabled.

With a real pull-up added, or not (internal still enabled) an open pin will read HIGH, that pin with 5 volts on it will read HIGH, and that pin presented with 0 volts will read LOW, if the grounding is stronger than the pull-up. A switch (shortest circuit) will be strong enough.

If you want pulled down pins, just set the pin mode off using pinMode() and wire a pulldown resistor between the pin and ground as usual.

a7

Hi, @borquee

What model Arduino are you using?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia: