MCP23017 pullup code for arduino

Hi, i use this code to activate the internal resistor of the MCP23017.
after my first test, it seems that this code (the IDE did not find it as an error) did not works as all my output of the MCP2 (got two mcp on I2C bus) are activated. They are in fact LOW because the 16 channel relays goes all actived. This card is active low input.

#include <Adafruit_MCP23X17.h>
#include <Arduino.h>
//#include <ESP8266WiFi.h>

Adafruit_MCP23X17 mcp1;
Adafruit_MCP23X17 mcp2;
  mcp2.begin_I2C(0x21);
  mcp2.pinMode(pin_led7a, INPUT_PULLUP);
  mcp2.pinMode(pin_led7a, OUTPUT);
  mcp2.pinMode(pin_led7b, INPUT_PULLUP);
  mcp2.pinMode(pin_led7b, OUTPUT);

do this code is correct ?

  • Try the above:

are you asking about pullups on the I2C bus or MCP23017 input pins?

  • the bus should have 4.7k pull-up resistors on both SCL and SDA
  • the GPPUA/B registers configure the pull-ups on pins (pg 22)

are you asking about pullups on the I2C bus or MCP23017 input pins?

In fact, i need to be sure that on power up the mcp23017, all the output to be HIGH (not activated).
The 16 channel relay connected to those output are "active low".
So actually, on power up all the output are low so ALL the relays are activated and can damage the coil connected to those relays contact.

Which way do i use to get this ?

  • all I/O pins by default come up as floating inputs, you don't want 2 devices driving a pin possibly cuasing a short, 1 HIGH and 1 LOW.
  • i'm surprised that a floating input pin leaks sufficient current to pull an Input on your relay board either HIGH or LOW
  • if the code is not fast enough to configure and set the pins LOW, you'll need external pull-ups.

which relay board are you using? does it have pull-up/down resistors?

I'll make test with code (without power on my coil) to see if relay comes inactive fast enough.

Be back..

According to this post in your other topic the problem was solved

So now it isn't working again?

@trainluc
In your previous topic you were using the GPIO pins of the Mega to drive the inputs to the relay module. In this topic you are driving the relay module inputs with MCP23017 I/O expanders and have a problem similar to before, correct? You would like the MCP23017 outputs to be HIGH when the sketch starts.

Yes and no
The problem is similar in the fact that my output as to be HIGH on the i/o expender.
The other topic was about the arduino itself. IT's fixed and now working as need.

The new topic it is about the expender only. Yes the output if my 2nd mcp need to be HIGH on powerup.

Got it.

Are you going to post a schematic diagram of your circuit or are we going to spend >100 posts solving this problem too?

Good news for you Emilyjane. the simple suggestion of LarryD have soluce my problem.
so it is now close case.

mcp2.begin_I2C(0x21);
  mcp2.digitalWrite(pin_led7a, HIGH);
  mcp2.pinMode(pin_led7a, OUTPUT);
  mcp2.digitalWrite(pin_led7b, HIGH);
  mcp2.pinMode(pin_led7b, OUTPUT);

this code works ecactly as i need