Six Multiplexers behaving in an odd way?

Hello,

I have a teensy project, which needs more inputs. I am new to fritzing, but I tried to build my current breadboard-situation for you guys to check. :slight_smile:
I have currently six CD74HC4051E chips. When I run my code, the serial monitor shows 1 when the button is not pressed, and 0 when it is. This is only the case, for the last two multiplexers. When I connect the button to one of the first four multiplexers (starting from the left) the serial monitor shows 0 when the button is not pressed and also 0 when it is. Can somebody help me?

Thanks in advance!

int pin_Out_S0 = 0;
int pin_Out_S1 = 1;
int pin_Out_S2 = 2;

int buttonState[48];

void buttonsAbfragen (int , int);

int bit1 = 0;
int bit2 = 0;
int bit3 = 0;


void setup() {
  //Select-Pins
  pinMode(pin_Out_S0, OUTPUT);
  pinMode(pin_Out_S1, OUTPUT);
  pinMode(pin_Out_S2, OUTPUT);

  Serial.begin(9600);
}


void loop() {

  for (int i = 0; i <= 7; i++)
  {
    bit1 = bitRead(i, 0);
    bit2 = bitRead(i, 1);
    bit3 = bitRead(i, 2);

    digitalWrite(pin_Out_S0, bit1);
    digitalWrite(pin_Out_S1, bit2);
    digitalWrite(pin_Out_S2, bit3);

    buttonsAbfragen(i, 14); // Mux 1
    buttonsAbfragen(i + 8, 15); // Mux 2
    buttonsAbfragen(i + 16, 16);// Mux 3
    buttonsAbfragen(i + 24, 17);// Mux 4
    buttonsAbfragen(i + 32, 18);// Mux 5
    buttonsAbfragen(i + 40, 19);// Mux 6

  }

  Serial.println();
}

void buttonsAbfragen (int zaehler, int digitalPin)
{
  buttonState[zaehler] = digitalRead(digitalPin);
 // delayMicroseconds(50);
  Serial.print (buttonState[zaehler]);
  Serial.print(",");
}

The fritzing thing is useless, draw a schematic. KiCad is free for the download and does a great job on schematic capture and you can go all the way to a pcb if you like. As far as your problem it could be either hardware or software, cannot tell at this point.

Your input pins are floating. Where are the pull-up resistors?

Pieter

Hi,

Thank you for your answers. I never drew a schematic before but I will try in the next days. I changed the code now and used INPUT_PULLUP (I am also using the first two multiplexers for 16 LEDs wich work fine), but nothing changed in the serial monitor. The multiplexers connected to Pin 18 and 19 work fine, but the ones connected to 8 and 17 do not.

Thanks again in advance!

int pin_Out_S0 = 0;
int pin_Out_S1 = 1;
int pin_Out_S2 = 2;

int buttonState[32];

int bit1 = 0;
int bit2 = 0;
int bit3 = 0;


void setup() {

  //Select-Pins
  pinMode(pin_Out_S0, OUTPUT);
  pinMode(pin_Out_S1, OUTPUT);
  pinMode(pin_Out_S2, OUTPUT);
  
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(8, INPUT_PULLUP);
  pinMode(17, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  pinMode(19, INPUT_PULLUP);
  

  Serial.begin(9600);
}


void loop() {


  for (int i {0}; i < 8; ++i)
  {
    bit1 = bitRead(i, 0);
    bit2 = bitRead(i, 1);
    bit3 = bitRead(i, 2);

    digitalWrite(pin_Out_S0, bit1);
    digitalWrite(pin_Out_S1, bit2);
    digitalWrite(pin_Out_S2, bit3);

   // digitalWrite(14, HIGH);
  //  digitalWrite(15, HIGH);
    buttonState[i] = digitalRead(8);
    buttonState[i + 8] = digitalRead(17);
    buttonState[i + 16] = digitalRead(18);
    buttonState[i + 24] = digitalRead(19);
    delay(200);
  }

  for (int i {0}; i < 32; ++i)
  {
    Serial.print(i);
    Serial.print(":");
    Serial.print(buttonState[i]);
    Serial.print("  ");
  }

  Serial.println();

}

Your Fritzing diagram is really unclear (why are you using red wires for both 3.3V and ground, plugging 3.3V into the blue rail of the breadboard and ground into the red one?), but it looks like your button is connected to 3.3V. It should be connected to ground.

Okay, waiting for the schematic... also, you need pull up resistors on the mux inputs, or connect them to something.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.