dragginNCrds
Posts: 7
Joined: Mon Jul 06, 2020 4:15 am

setting up multiple inputs and outputs

Mon Jul 06, 2020 4:23 am

So im trying to see if this is possible and someone suggested a Pi.. i have 8 inputs that need to control 8 outputs. but the kicker is that i need them to control multiple outputs dependent upon inputs activated.

Example:

INPUT 1-8 OUTPUT 1-8

INPUT 1 would activate OUTPUT 1&4
INPUT 2 would activate OUTPUT 1&2

BUT

if INPUT 1&2 pushed together would only activate OUTPUT 1

it goes down the line back and fourth for a combination of all INPUTS and OUTPUTS for 1-8 but if i can figure out this simply i can configure the rest

the most activations at one time would be 2 INPUTS and up to 3 OUTPUTS at the same time..

if this is possible please help and let me know. and ill order the stuff i need to make this happen

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: setting up multiple inputs and outputs

Mon Jul 06, 2020 8:51 am

Yes should be possible with a python script reading button presses and setting outputs accordingly.
When Input 1 pressed, check input 2; if 2 not pressed, output 1 & 4 else output 1

Similarly for othe inputs. This script can be tested on a pi without buying any other hardware. Install raspi-gpio. Run the script and in a separate Terminal, use raspi-gpio set to set the inputs you want high or low, then read the state of the output pins using raspi-gpio get

pcmanbob
Posts: 9298
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: setting up multiple inputs and outputs

Mon Jul 06, 2020 8:55 am

Hi.

You have not said which programming language you want to use , but you could do it with python an a number of if statements.

something like this ( not real code )

Code: Select all


if input1 == 1:
    if input2 ==1:
        output2
    
    elif input3 ==1:
        output3
    
    elif input4 ==1:
        output4

    else:
        output1
        output4
        
        
if input2 == 1:
    if input3 ==1:
        output2
        output4
    
    elif input4 ==1:
        output3
        output4

    else:
        output1
        output2
        
of course the actual logic of it all will depend on all the possible combinations of input and output.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

dragginNCrds
Posts: 7
Joined: Mon Jul 06, 2020 4:15 am

Re: setting up multiple inputs and outputs

Mon Jul 06, 2020 11:53 am

I’m not sure which language is best or easiest to do what I’m wanting.

jbudd
Posts: 1358
Joined: Mon Dec 16, 2013 10:23 am

Re: setting up multiple inputs and outputs

Mon Jul 06, 2020 3:54 pm

If you are absolutely certain you only have to allow for 2 simultaneous inputs then you just need a table something like this

The columns are the first button pressed, the rows are the second (if it exists) and the values in the table are the outputs to set in each case.
I have filled in the examples you gave: just button1, just button 2 and buttons 1 and 2 together.

Code: Select all

	1	2	3	4	5	6	7	8
0	1,4	1,2

1		1

2	1

3

4

5

6

7

8
You could implement it as a 3 dimensional array (might be called a table, a structure or other names depending on the language you pick)

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: setting up multiple inputs and outputs

Mon Jul 06, 2020 3:56 pm

Python is the easiest to do it in.

dragginNCrds
Posts: 7
Joined: Mon Jul 06, 2020 4:15 am

Re: setting up multiple inputs and outputs

Mon Jul 06, 2020 4:01 pm

It is realistically 2 groups. 4in 4 out per group. They would only see at maximum 2 inputs at one time per group but at a maximum of 3 outputs per 2inputs

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: setting up multiple inputs and outputs

Mon Jul 06, 2020 4:08 pm

Python with gpiozero library.

dragginNCrds
Posts: 7
Joined: Mon Jul 06, 2020 4:15 am

Re: setting up multiple inputs and outputs

Mon Jul 06, 2020 4:14 pm

So what do I need to purchase to do this

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: setting up multiple inputs and outputs

Mon Jul 06, 2020 4:40 pm

Buy a 2GB pi and official power supply, then get the python code working without buying any buttons/switches/LEDs as in my earlier post, then look at what you want the outputs to “drive” - LED, relay, MOSFET, motor etc. That will determine what needs to be bought.
You may need a usb keyboard and mouse for the pi if you don’t already have those.

emma1997
Posts: 774
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: setting up multiple inputs and outputs

Tue Jul 07, 2020 12:25 am

dragginNCrds wrote:
Mon Jul 06, 2020 4:23 am
if INPUT 1&2 pushed together would only activate OUTPUT 1
Not being a Python expert and not having gone through all the examples with a fine tooth comb, without proper race condition and/or debounce issues taken into consideration, I doubt any of them will work for this part. For instance it's necessary to check inputs again some fixed time after any change to see if any others have been activated.

Also a lot depends on the type of inputs. Are they from human actions or are they from logic with synchronizes leading edges. In any case more than simple pie-in-the-sky Boolean expressions will probably be required. Unless false outputs, short as they may be, are ok.

dragginNCrds
Posts: 7
Joined: Mon Jul 06, 2020 4:15 am

Re: setting up multiple inputs and outputs

Tue Jul 07, 2020 2:22 am

It’s human inputs. I have 2 sets of 4 in 4 out. At most I would have 2 in and 3 out being toggled.

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: setting up multiple inputs and outputs

Tue Jul 07, 2020 7:18 am

Yes once the basic code is working it can be adjusted for switch debounce etc.

emma1997
Posts: 774
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: setting up multiple inputs and outputs

Wed Jul 08, 2020 11:29 pm

It's not just debounce per se but more a race condition to prevent triggering on the 1st input even if the intent was to recognize both simultaneously. If OP don't mind incorrect output for brief periods it shouldn't be a problem.

Just last week I had to implement a 'detect 1st then delay and read again to be sure no others' on a set top box project. It was a way to get 6 different functions out of 3 tact buttons. Without the extra code it fails miserably. Another project last year needed similar treatment but in that case a mission critical situation could have resulted in bodily harm. So a lot depends on how important it is to have 100% valid output state.

dragginNCrds
Posts: 7
Joined: Mon Jul 06, 2020 4:15 am

Re: setting up multiple inputs and outputs

Fri Jul 10, 2020 2:49 am

I could have a millisecond of hang over. It’s not a critical situation. It realistically can be broken down to a 2 in 3 out situation. Just 2 times. If one is pushed 2 outputs activate. If two inputs activate one output basically falls off and the other stays activated. Basically if both inputs are activated they would be activated at the exact same time.

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: setting up multiple inputs and outputs

Fri Jul 10, 2020 8:13 am

Ok have you got a pi now?

dragginNCrds
Posts: 7
Joined: Mon Jul 06, 2020 4:15 am

Re: setting up multiple inputs and outputs

Fri Jul 10, 2020 12:06 pm

Have a buddy that’s going to give me one to try it on just have to get it from him

Return to “Beginners”