Read multiple digital input from one digital output.

Gandalf
Posts: 6
Joined: Mon Jan 17, 2022 8:49 pm

Read multiple digital input from one digital output.

Postby Gandalf » Mon Sep 26, 2022 1:43 am

Hello.

I need to read the state of 8 switches (just on or off state). In order to use as few pins as possible I want to use only one output pin and use it for multiple input pins. Is this possible?

Regards.

ESP_Sprite
Posts: 8884
Joined: Thu Nov 26, 2015 4:08 am

Re: Read multiple digital input from one digital output.

Postby ESP_Sprite » Mon Sep 26, 2022 2:32 am

...why'd you need an out pin to read switches anyway? Inputs pins should be enough.

The solution that likely uses least pins is to use an I2C port expander, that's only two pins.

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Read multiple digital input from one digital output.

Postby ESP_igrr » Wed Sep 28, 2022 8:35 pm

Another approach I've seen being used for this is to attach switches to a resistor ladder and use an ADC input to measure the output voltage.
That said, this approach works better for a small number of switches, and typically requires a calibration step for each device.
http://www.ignorantofthings.com/2018/07 ... istor.html

Gandalf
Posts: 6
Joined: Mon Jan 17, 2022 8:49 pm

Re: Read multiple digital input from one digital output.

Postby Gandalf » Fri Sep 30, 2022 2:16 am

ESP_Sprite wrote:
Mon Sep 26, 2022 2:32 am
...why'd you need an out pin to read switches anyway? Inputs pins should be enough.

The solution that likely uses least pins is to use an I2C port expander, that's only two pins.
Thanks for your answer. Yes indeed I will use an I2C port expander.

I need to know when a normally open switch is on or off. So I connect one end of the switch to a pin that is high all the time, the other side of the switch is connected to a pin (pulled-down) that I'm going to be monitoring, if I detect high on that second pin it means that the switch was activated.

I need to do this for 8 switches, so my question is if all 8 input pins can detect the high state of a single output pin or is it necessary for each input pin to receive the high signal from an individual output pin?

My question is whether the "strength" of a single output signal is enough to detect its high state on all eight input pins when all switches are on at the same time.

Regards.

ESP_Sprite
Posts: 8884
Joined: Thu Nov 26, 2015 4:08 am

Re: Read multiple digital input from one digital output.

Postby ESP_Sprite » Sat Oct 01, 2022 2:03 am

So if you want to use an output that is high (=3.3V) all the time, why not simply connect to the 3.3V power supply line instead?

User avatar
mbratch
Posts: 294
Joined: Fri Jun 11, 2021 1:51 pm

Re: Read multiple digital input from one digital output.

Postby mbratch » Sat Oct 01, 2022 5:54 pm

Gandalf wrote:
Fri Sep 30, 2022 2:16 am
I need to do this for 8 switches, so my question is if all 8 input pins can detect the high state of a single output pin or is it necessary for each input pin to receive the high signal from an individual output pin?

My question is whether the "strength" of a single output signal is enough to detect its high state on all eight input pins when all switches are on at the same time.
I am just taking this question totally at face value, not knowing exactly what your design is in general that would require this kind of setup, but the answer is, "yes" the strength of the single output is enough to be detected on 8 inputs. Just use a resistor on each input whose value is large enough such that eight in parallel won't draw too much current from the output.

But... it would be really helpful to know what you're trying to achieve overall since that could affect the answer.

Gandalf
Posts: 6
Joined: Mon Jan 17, 2022 8:49 pm

Re: Read multiple digital input from one digital output.

Postby Gandalf » Mon Oct 03, 2022 5:08 pm

ESP_Sprite wrote:
Sat Oct 01, 2022 2:03 am
So if you want to use an output that is high (=3.3V) all the time, why not simply connect to the 3.3V power supply line instead?
I hadn't thought of that, I think it's a very good idea.

Thanks a lot.

Gandalf
Posts: 6
Joined: Mon Jan 17, 2022 8:49 pm

Re: Read multiple digital input from one digital output.

Postby Gandalf » Mon Oct 03, 2022 5:41 pm

mbratch wrote:
Sat Oct 01, 2022 5:54 pm
Gandalf wrote:
Fri Sep 30, 2022 2:16 am
I need to do this for 8 switches, so my question is if all 8 input pins can detect the high state of a single output pin or is it necessary for each input pin to receive the high signal from an individual output pin?

My question is whether the "strength" of a single output signal is enough to detect its high state on all eight input pins when all switches are on at the same time.
I am just taking this question totally at face value, not knowing exactly what your design is in general that would require this kind of setup, but the answer is, "yes" the strength of the single output is enough to be detected on 8 inputs. Just use a resistor on each input whose value is large enough such that eight in parallel won't draw too much current from the output.

But... it would be really helpful to know what you're trying to achieve overall since that could affect the answer.

Hello, thanks for your answer.

I need to show, remotely, the status of an industrial panel. So, in my web application (dashboard) I have buttons and switches icons for each physical button and switch on the panel. When a button or switch changes its state, on the panel, the esp send an mqtt message with the status change to be reflected on the dashboard. For those switches whose possible status are On or Off I thought to use the normally open or normally close free terminals on the respective contactors.
On one of the two NO free terminal of a contactor I will connect the alway On pin, on the other free terminal of the contactor I will connect a pin that will be constantly monitored in the ESP, so when the switch closes, I will receive the high signal on the monitored pin and send the respective mqtt message to my cloud application (dashboard).

I hope I have explained well what I want to achieve, if not, I can expand my description.

If I managed to explain my solution well, I would like to know your opinions or possible improvements to my idea.

Best regards.

User avatar
mbratch
Posts: 294
Joined: Fri Jun 11, 2021 1:51 pm

Re: Read multiple digital input from one digital output.

Postby mbratch » Tue Oct 04, 2022 6:48 pm

Gandalf wrote:
Mon Oct 03, 2022 5:41 pm
I need to show, remotely, the status of an industrial panel. So, in my web application (dashboard) I have buttons and switches icons for each physical button and switch on the panel. When a button or switch changes its state, on the panel, the esp send an mqtt message with the status change to be reflected on the dashboard. For those switches whose possible status are On or Off I thought to use the normally open or normally close free terminals on the respective contactors.
On one of the two NO free terminal of a contactor I will connect the alway On pin, on the other free terminal of the contactor I will connect a pin that will be constantly monitored in the ESP, so when the switch closes, I will receive the high signal on the monitored pin and send the respective mqtt message to my cloud application (dashboard).
Thanks for explaining, that's very helpful!

I still have a question: why is it needed that 8 gpio inputs on your ESP32 need to be connected with one contact on the panel? Maybe I still misunderstand your setup (you indicated in an earlier post, "...my question is if all 8 input pins can detect the high state of a single output pin")

But in general, from the ESP32 perspective, each GPIO just needs to see 0 ~ 3.3v, and will give you 1 or 0 depending upon 3.3v logic threshold specs. So however you wire your panel outputs to ESP32 inputs, you must ensure that. Secondly, you need to ensure that the maximum current sink specs of each gpio is not exceeded. You seem to be asking whether the panel can source enough current. Not much current is required, so I would suspect that it could. Do you know how much current your panel contact can source?

Gandalf
Posts: 6
Joined: Mon Jan 17, 2022 8:49 pm

Re: Read multiple digital input from one digital output.

Postby Gandalf » Wed Oct 05, 2022 3:05 am

mbratch wrote:
Tue Oct 04, 2022 6:48 pm
Gandalf wrote:
Mon Oct 03, 2022 5:41 pm
I need to show, remotely, the status of an industrial panel. So, in my web application (dashboard) I have buttons and switches icons for each physical button and switch on the panel. When a button or switch changes its state, on the panel, the esp send an mqtt message with the status change to be reflected on the dashboard. For those switches whose possible status are On or Off I thought to use the normally open or normally close free terminals on the respective contactors.
On one of the two NO free terminal of a contactor I will connect the alway On pin, on the other free terminal of the contactor I will connect a pin that will be constantly monitored in the ESP, so when the switch closes, I will receive the high signal on the monitored pin and send the respective mqtt message to my cloud application (dashboard).
Thanks for explaining, that's very helpful!

I still have a question: why is it needed that 8 gpio inputs on your ESP32 need to be connected with one contact on the panel? Maybe I still misunderstand your setup (you indicated in an earlier post, "...my question is if all 8 input pins can detect the high state of a single output pin")

But in general, from the ESP32 perspective, each GPIO just needs to see 0 ~ 3.3v, and will give you 1 or 0 depending upon 3.3v logic threshold specs. So however you wire your panel outputs to ESP32 inputs, you must ensure that. Secondly, you need to ensure that the maximum current sink specs of each gpio is not exceeded. You seem to be asking whether the panel can source enough current. Not much current is required, so I would suspect that it could. Do you know how much current your panel contact can source?
esp-contactor.png
esp-contactor.png (55.07 KiB) Viewed 3203 times

In the image above, the esp does not control the contactors, it only detects their status.

The contactors can be activated individually or all at once.

The three switches of each contactor are always activated together.

The terminals where the output and inputs are connected to the esp do not have any type of load (they do not have voltage), those terminals will only work as a switch for the esp.

Regardless of the validity of the pins in the image (in the real implementation I will use a port extender MCP23017) :

Pin 18 is my output (always on) orange lines.

Pin 15 (input) detects if the above contactor is active or not.

Pin 14 (input) detects if the contactor in the center is active or not.

Pin 13 (input) detects if the bottom contactor is active or not.

In my actual implementation, there are 8 contactors. All eight contactors can be active at the same time or only 1 or two or none.

If all eight contactors are active, then pin 18 is supplying the high signal to all eight input pins.

Any suggestions would be welcome.

Best regards.

Who is online

Users browsing this forum: No registered users and 81 guests