Mux Shield Floating at startup

Hi,

I'm using two Mux Shields II from Mathew Labs. MuxShield II - Sparkfun

The first one is directly plugged in on top of the Arduino Mega2560. The second one is connected via other pin connections. The length of this cable is +/- 5m.
Connection Pins

Pin MuxShield Pin Arduino Mux1 Pin Arduino Mux2
S0 2 22
S1 4 23
S2 6 24
S3 7 25
OUTMD 8 26
I01 A0 A3
I02 A1 A4
I03 A2 A5

When I startup the Mega 2560 the relay connected to the 2nd Mux Shield are getting on and of for a few seconds, which results in a bad startup of model train which is connected.

Also when I start the serial monitor on the connected PC, I got the same fenomen.

The first mux shield doesn't have this behaviour at startup.

Is there a way to avoid this ?
I think it's because the used pins are floating at startup and initializing. But why is it disturbing the 2nd Mux Shield and not the first.

Can sombody explain why the 2nd mux is floating at initialization ?

MuxShieldII Mayhew Labs.JPG

Please read this:-
How to use this forum
It will help you ask questions here.

First we need clickable links to the product you have bought.
Then we need a schematic of how you have wired this up to the Arduino. Just pen and paper will do, please do not post a Fritzing piece of crap.

Finally we need a full program that shows your problem, not a snippet. Because:- http://snippets-r-us.com/
So write something minimal that shows you problem.

Here the code I use

#include <MuxShield.h>

//Initialize the Mux Shield
//MuxShield::MuxShield(int S0, int S1, int S2, int S3, int OUTMD, int IOS1, int IOS2, int IOS3, int IO1, int IO2, int IO3)
MuxShield muxshield2 ( 22, 23, 24, 25, 26, 50, 51, 52, A3, A4, A5);
MuxShield muxshield1 (  2,  4,  6,  7,  8, 10, 11, 12, A0, A1, A2);

boolean bzBV[36];
boolean reedSP[36];
boolean bvStop[36];
boolean sein[36];

int poort = false;
int bvState = false;

//boolean bv10 = false;
boolean bv14 = false;
boolean bv20 = false;
boolean bv23 = false;
boolean bv24 = false;
boolean bv24c = false;
boolean bv26 = false;
boolean bv29a = false;
boolean bv29b = false;

// Boolean per stop baanvak: true = rood/stoppen, false = groen/rijden

boolean bv10Rood = true;
boolean bv11Rood = true;
boolean bv14Rood = true;
boolean bv20Rood = true;
boolean bv21Rood = true;
boolean bv23Rood = true;
boolean bv24Rood = true;
boolean bv31Rood = true;
boolean bv32Rood = true;
boolean bvSchaduwRood = true;
boolean bvW16Rood = true;
boolean vrijgave = false;
int vrijgave_spoor[3] {0, 0, 0 };

// Bij reset van arduino, valt de relais af en zou de trein plots rijden,
// vandaar dat !bvxxStop naar de poort gestuurd wordt

boolean ws10L = false;
boolean ws10R = false;
boolean ws11L = false;
boolean ws11R = false;

// boolean voor andere relais
boolean rangeerLinksUit = false; // RLUIT-J9
boolean rangeerRechtsIn = false; // RRIN-J9
boolean rw01 = false;   // RW1-1
boolean rw04 = false;   // RW4-1
boolean rw05 = false;   // RW5-1
boolean rw08 = false;   // RW8-1
boolean rw15 = false;   // RW15-1
boolean rw16 = false;   // RW16-1
boolean rw39 = false;   // RW38-1
boolean rw43 = false;   // RW43-1
boolean rw10 = false;   // RW10-1
boolean rw11 = false;   // RW11-1

// the setup function runs once when you press reset or power the board
void setup() {

  Serial.begin(9600);
  Serial.println("Hello World!");

  muxshield1.setMode(1, DIGITAL_IN_PULLUP);
  muxshield1.setMode(2, DIGITAL_IN);
  muxshield1.setMode(3, DIGITAL_OUT);

  muxshield2.setMode(1, DIGITAL_IN);
  muxshield2.setMode(2, DIGITAL_IN);
  muxshield2.setMode(3, DIGITAL_OUT);
  
  int i;
  for (i = 0; i < 16; i++) {
    muxshield1.digitalWriteMS(3, i, HIGH);
    muxshield2.digitalWriteMS(3, i, HIGH);
  }


}
// the loop function runs over and over again forever
void loop() {

  bzBV[1] =  muxshield1.digitalReadMS(2, 0);
  bzBV[2] =  muxshield1.digitalReadMS(2, 1);
  bzBV[3] =  muxshield1.digitalReadMS(2, 2);
  bzBV[4] =  muxshield1.digitalReadMS(2, 3);
  bzBV[11] =  muxshield1.digitalReadMS(2, 5);
  bzBV[12] =  muxshield1.digitalReadMS(2, 6);
  bv20 =  muxshield1.digitalReadMS(2, 8);
  bzBV[21] =  muxshield1.digitalReadMS(2, 7);
  bzBV[22] =  muxshield1.digitalReadMS(2, 9);
  bv24 =  muxshield1.digitalReadMS(2, 11);
  bv29a =  muxshield1.digitalReadMS(2, 15);
  bv29b =  muxshield1.digitalReadMS(2, 14);
  bzBV[30] =  muxshield1.digitalReadMS(2, 12);
  bzBV[31] =  muxshield1.digitalReadMS(2, 10);

  rw01 = muxshield1.digitalReadMS(1, 5);
  rw04 = muxshield1.digitalReadMS(1, 6);
  rw05 = muxshield1.digitalReadMS(1, 3);
  rangeerLinksUit = muxshield1.digitalReadMS(1, 1);
  rangeerRechtsIn = muxshield1.digitalReadMS(1, 0);
  if (!reedSP[1]) {
    reedSP[1] = muxshield1.digitalReadMS(1, 4);
  }
  if (!reedSP[2]) {
    reedSP[2] = muxshield1.digitalReadMS(1, 2);
  }
  if (!reedSP[3]) {
    reedSP[3] = muxshield1.digitalReadMS(1, 8);
  }
  if (!reedSP[4]) {
    reedSP[4] = muxshield1.digitalReadMS(1, 7);
  }


  bzBV[15] =  muxshield2.digitalReadMS(2, 0);
  bzBV[16] =  muxshield2.digitalReadMS(2, 1);
  bzBV[17] =  muxshield2.digitalReadMS(2, 2);
  bzBV[24] =  muxshield2.digitalReadMS(2, 3);
  bzBV[25] =  muxshield2.digitalReadMS(2, 4);
  bv26 =  muxshield2.digitalReadMS(2, 5);
  bv14 =  muxshield2.digitalReadMS(2, 6);
  bzBV[27] =  muxshield2.digitalReadMS(2, 7);
  bzBV[33] =  muxshield2.digitalReadMS(2, 8);
  bzBV[34] =  muxshield2.digitalReadMS(2, 9);
  bzBV[32] =  muxshield2.digitalReadMS(2, 10);
  bzBV[35] =  muxshield2.digitalReadMS(2, 11);
  bzBV[19] =  muxshield2.digitalReadMS(2, 12);
  bzBV[18] =  muxshield2.digitalReadMS(2, 13);
  rw10 =  muxshield2.digitalReadMS(2, 15);
  rw11 =  muxshield2.digitalReadMS(2, 14);


  rw08 = muxshield2.digitalReadMS(1, 5);
  rw15 = muxshield2.digitalReadMS(1, 1);
  rw16 = muxshield2.digitalReadMS(1, 2); 
  rw39 = muxshield2.digitalReadMS(1, 3);
  rw43 = muxshield2.digitalReadMS(1, 4); 
  
  setRelaisBaanVak(1, 0, !bvStop[1]);
  setRelaisBaanVak(1, 1, !bvStop[2]);
  setRelaisBaanVak(1, 2, !bvStop[3]);
  setRelaisBaanVak(1, 3, !bvStop[4]);
  setRelaisBaanVak(1, 4, !bvStop[11]);
  setRelaisBaanVak(1, 5, !bvStop[12]);
  setRelaisBaanVak(1, 6, !bvStop[24]);
  setRelaisBaanVak(1, 7, !bvStop[30]);
  setRelaisBaanVak(1, 8, !bvStop[29]);
  setRelaisBaanVak(1, 9, sein[1]);
  setRelaisBaanVak(1, 10, sein[2]);
  setRelaisBaanVak(1, 11, sein[3]);
  setRelaisBaanVak(1, 12, sein[4]);
  setRelaisBaanVak(1, 13, sein[11]);
  setRelaisBaanVak(1, 14, sein[12]);

  setRelaisBaanVak(2, 0, !bvStop[15]);
  setRelaisBaanVak(2, 1, !bvStop[16]);
  setRelaisBaanVak(2, 2, !bvStop[17]);
  setRelaisBaanVak(2, 3, !bvStop[18]);
  setRelaisBaanVak(2, 4, !bvStop[19]);
  setRelaisBaanVak(2, 5, !bvStop[25]);
  setRelaisBaanVak(2, 6, !bvStop[27]);
  setRelaisBaanVak(2, 8, !bvStop[32]);
  setRelaisBaanVak(2, 9, !bvStop[33]);
  setRelaisBaanVak(2, 10, !bvStop[34]);
  setRelaisBaanVak(2, 11, !bvStop[35]);
  setRelaisBaanVak(2, 12, ws10L);
  setRelaisBaanVak(2, 13, ws10R);
  setRelaisBaanVak(2, 14, ws11L);
  setRelaisBaanVak(2, 15, ws11R);

 }

void setRelaisBaanVak(int mux, int relais, int relaisState) {
  if (mux == 1) {
    if (relaisState) {
      muxshield1.digitalWriteMS(3, relais, LOW);
    } else {
      muxshield1.digitalWriteMS(3, relais, HIGH);
    }
  }
  if (mux == 2) {
    if (relaisState) {
      muxshield2.digitalWriteMS(3, relais, LOW);
    } else {
      muxshield2.digitalWriteMS(3, relais, HIGH);
    }
  }
  //delay(writeDelay);
}

Hi Mike,

I added a link to the shield in mine first message
I added a table with the pin connections
I attached the picture of the mux shield
I added the complete program in a second message.

So if you can find out why the 2nd Muxshield has a strange behaviour at startup

Kind regards

Marc

Hi,

I just tested a little bit more to solve my issue as desribed above.

The MuxShieldII has 3 banks of 16 I/O.
For the shield 2 bank 0 and Bank 1 are digital inputs

MuxShield muxshield2 ( 22, 23, 24, 25, 26, A3, A4, A5);

 muxshield2.setMode(1, DIGITAL_IN);
 muxshield2.setMode(2, DIGITAL_IN);
 muxshield2.setMode(3, DIGITAL_OUT);

Only Bank3 is Output.

When I unplug the A5 pin from the Arduino Mega, I have the same fenomen as when the Arduino is rebooting.
Is it correct that pin A5 is floating at that moment.

Can I resolve this by a PullDown resistor?

Who can help me, what I should do ?

Glad you got it going.

Can I resolve this by a PullDown resistor?

Yes that is the standard way with outputs. A 10K pull down should do it.

Where should I put the resistor?

There are a lot of designs, and I used it already for digital input, but not for digital output.
Is the schema the same?

Where should I put the resistor?

A pull down resistor, by definition, goes from the output to ground.