74HC4067 MUX switches all output ports to low after port change

When i change the port on the mux, all other ports go to low. I can not imagen this is how it should work. How could i switch two or more devices/leds to ON if this is normal behaviour? Could anyone help me? I include my test scetch here. I have been seeking an answer for days's now. Maybe the mux is broken?
Everything seems to work (input, output, even touch) as long as i keep the output port selected. Changing the port on the mux, immediately switches the port to low.
Please help!

This is my vey simle program:
// EN op de mux is hardwired to ground.
// ESP used is: ESP32 WROOM
// Mux used is: 74HC4067 16 port

const byte P0=5;
const byte P1=18;
const byte P2=19;
const byte P3=21;
const byte Sig=4;

void SetMux(byte i){ //selects the port on the mux
digitalWrite(P0,bitRead(i,0));
digitalWrite(P1,bitRead(i,1));
digitalWrite(P2,bitRead(i,2));
digitalWrite(P3,bitRead(i,3));
}

void setup(){
pinMode(P0,OUTPUT);//set de 'port selector' pins to output mode
pinMode(P1,OUTPUT);
pinMode(P2,OUTPUT);
pinMode(P3,OUTPUT);
pinMode(Sig,OUTPUT);//zet de signaal pin in output mode
SetMux(15);//set mux to port 15. (ramdom choice, could be any port)
digitalWrite(Sig,HIGH); //set LED on. This works.
delay(2000); //wait a while
SetMux(10);//swich mux to new port (also ramdomly choosen)
//now led goos off. after changing port LED goes off.....
}

void loop() {
}

Thanks in advance.

That is how multiplexers work; it routes a signal to one of the outputs, it does not latch the output.. Sounds like you picked the wrong component.

Consider shift registers or I2C/SPI port expanders if you want to expand the number of outputs.

Please edit your post, select all code and apply code tags; next save your post. See How to get the best out of this forum

No they don't. They go open circuit. :sunglasses:

You use a shift register. 74HC595

Do read the instructions. :grin:

Ai, really? I will investigate shift registers then.
Can you also use these for input?
Thank you for the answer, i still can not imagen that a mux doest not latch the output, but i see it happen here so it must be true. Really... this limits the usage for me. I just need 16 (or more) extra ports so a mux sounded just what i needed. Truely a brainfart on my side then. I will go and see if these shift registers solve my port problem. Or do you have any other advice/device you could give me to set me on the right track?
Pieter

You can't use 74hc595 shift registers for extra inputs (although there is a way you can use them for scanning a row or matrix of buttons). But you can use a 74hc165 for extra inputs.

If you need a mix of inputs and outputs, you can use pcf8574 or mcp23008 (8 pins) or pcf8575 or mcp23017 (16 pins). These chips are clever, you can attach many of them to the same arduino pins (SDA, SCL) to give you a large number of pins which can be either inputs or outputs in any combination.

Yo man, thanks!!
I have been looking where i went wrong for a while, your answer put me on the right track. I have been looking at video's en reading about shift registers for the last 2 hours, and it looks loke that is exactly what i was looking for.
I had never heard of shift-registers. Thank you very much.
I will order some of them and start testing. (My project still has lots of time before it needs to be ready)
Realy, thanks very much!
Pieter

I avoided mentioning these primarily because I gathered the OP wanted to drive the LEDs HIGH, which the PCF8574/5 will not. It will however drive a LED cathode OK.

So you do not understand what a multiplexer does. :thinking:

It is a switch. It switches one pin to one other pin. When it switches to a different pin, it disconnects the first. That is exactly what a switch does. :roll_eyes:

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