Page 1 of 1

Monitor GPIO inputs

Posted: Sun May 31, 2020 3:16 pm
by SaturdaySam
Hi everybody - new here, so please be gentle!!

I have recently become interested in Raspberry Pi since retiring and I am gradually learning!

I am working on a project idea but unfortunately I am a little stumped.

I need to have 2 input pins on the GPIO constantly monitored so that when each pin goes high ( from external source) it provides a high output on a GPIO pin - each of the 2 input pins would activate a separate output pin. The 2 inputs pins would never be activated at the same time. This output has to stay high for 10 seconds and then go low. Once the output goes low then the whole process starts again.

It started off as quite a simple idea....but its turning into a monster!

thanks for your help

Sam

Re: Monitor GPIO inputs

Posted: Mon Jun 01, 2020 9:22 am
by pcmanbob
Hi.

So you have explained what you want to do but not what your problem is.

what code do you already have , which part of it is not working as you want ?

You have not even told us which programming language you are using , give use some thing to start from and you will find help more forthcoming.

Re: Monitor GPIO inputs

Posted: Mon Jun 01, 2020 9:55 am
by drgeoff
If that is the only functionality required then a RPi (any model) is gross overkill.

Re: Monitor GPIO inputs

Posted: Mon Jun 01, 2020 7:46 pm
by boyoh
This is a typical Digital Logic Exclusive OR circuit ,it can be constructed using transistors or a IC , A good circuit to learn on

A good basic electronics learning project on how to use Transistors....I've pointed you in the right direction, so get doing some research

What you will need 2 / 2n 2222 Transistors 2/ 10k Resistors 4k7 Resistors,, ( Suggest use breadboard )

A B / Out
---------------------------
L L / L
L H / H
H L / H
H H / L

Regards BoyOh

Re: Monitor GPIO inputs

Posted: Mon Jun 01, 2020 7:49 pm
by mahjongg
drgeoff wrote:
Mon Jun 01, 2020 9:55 am
If that is the only functionality required then a RPi (any model) is gross overkill.
even an arduino (any kind) would be overkill.

More importantly, what programming language are you using?

can you post what you have (between code /code tags...)

Re: Monitor GPIO inputs

Posted: Mon Jun 01, 2020 9:59 pm
by drgeoff
boyoh wrote:
Mon Jun 01, 2020 7:46 pm
This is a typical Digital Logic Exclusive OR circuit ,it can be constructed using transistors or a IC , A good circuit to learn on

A good basic electronics learning project on how to use Transistors....I've pointed you in the right direction, so get doing some research

What you will need 2 / 2n 2222 Transistors 2/ 10k Resistors 4k7 Resistors,, ( Suggest use breadboard )

A B I Out
---------------------------
L L I L
L H I H
H L I H
H H I L

Regards BoyOh
@Boyoh
1. The OP wrote that the two inputs would never be activated at the same time. That does not mean an exclusive OR circuit is required.

2. The OP wrote that the outputs change should change state for 10 seconds. How can you achieve that with only resistors and transistors?

Re: Monitor GPIO inputs

Posted: Mon Jun 01, 2020 10:05 pm
by PiGraham
mahjongg wrote:
Mon Jun 01, 2020 7:49 pm
drgeoff wrote:
Mon Jun 01, 2020 9:55 am
If that is the only functionality required then a RPi (any model) is gross overkill.
even an arduino (any kind) would be overkill.

More importantly, what programming language are you using?

can you post what you have (between code /code tags...)
A beginner has a Pi and is learning what can be done with it. Nothing wrong with that.

To the OP:

Any language would do, but Python and GPIOZero are favoured for beginners.

Look at tutorials for simple switch inputs and LED outputs.

See if you can see how to adapt a single push button example to read two inputs.

Have a go and post a follow up with your code if you get stuck.

Re: Monitor GPIO inputs

Posted: Mon Jun 01, 2020 10:26 pm
by jbudd
Assuming you want to do this with your Raspberry Pi and not a handful of transistors or logic gates, an arduino...

You could use Node-Red. The program might look something like this
Untitled 1.jpg
Untitled 1.jpg (42.5 KiB) Viewed 869 times
A gpio input node on the left.
A switch node to detect low - high transitions.
A delay node to ignore any more transitions for 10 seconds.
A trigger node to send high for 10 seconds, then low.
A gpio output node on the right.

Re: Monitor GPIO inputs

Posted: Tue Jun 02, 2020 9:53 am
by PiGraham
Doccumentation for GPIOZero gives examples of button inputs and LED outputs programmed in Python:

https://gpiozero.readthedocs.io/en/stab ... input.html

https://gpiozero.readthedocs.io/en/stab ... utput.html

The LED class even has a Blink method you could use to do the on for 10 seconds bit.


This project should be easy to adapt. Button input, LED output, program in Scratch

https://projects.raspberrypi.org/en/pro ... scratch-pi

Re: Monitor GPIO inputs

Posted: Tue Jun 02, 2020 2:45 pm
by boyoh
SaturdaySam wrote:
Sun May 31, 2020 3:16 pm
Hi everybody - new here, so please be gentle!!

I have recently become interested in Raspberry Pi since retiring and I am gradually learning!

I am working on a project idea but unfortunately I am a little stumped.

I need to have 2 input pins on the GPIO constantly monitored so that when each pin goes high ( from external source) it provides a high output on a GPIO pin - each of the 2 input pins would activate a separate output pin. The 2 inputs pins would never be activated at the same time. This output has to stay high for 10 seconds and then go low. Once the output goes low then the whole process starts again.

It started off as quite a simple idea....but its turning into a monster!

thanks for your help

Sam

From BoyOh You said you have just retired , It will great to know if your interest with the Raspberry Pi is to learn about
electronics and circuit building as hobby , The Pi is a good starting point , It is nice to be able to build
your own circuits and be able to see them work , so starting from the bottom is a good way to learn.
You will get a lot of good advice from the Forum. Interfacing with the Raspberry Pi, is not all coding
that you need to know, Circuits will only work when thy are built right. and when yo know how to test
if thy don't work


Regards BoyOh 88yrs Retired Electrical / Electronic Technician ..

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 10:43 am
by boyoh
drgeoff wrote:
Mon Jun 01, 2020 9:59 pm
boyoh wrote:
Mon Jun 01, 2020 7:46 pm
This is a typical Digital Logic Exclusive OR circuit ,it can be constructed using transistors or a IC , A good circuit to learn on

A good basic electronics learning project on how to use Transistors....I've pointed you in the right direction, so get doing some research

What you will need 2 / 2n 2222 Transistors 2/ 10k Resistors 4k7 Resistors,, ( Suggest use breadboard )

A B I Out
---------------------------
L L I L
L H I H
H L I H
H H I L

Regards BoyOh
@Boyoh
1. The OP wrote that the two inputs would never be activated at the same time. That does not mean an exclusive OR circuit is required.

2. The OP wrote that the outputs change should change state for 10 seconds. How can you achieve that with only resistors and transistors?

For the attention of ( drgeoff )
I all ways look forward to your comments on my posts , I find them very VERBABLE but non constructive . A alternative circuit
from you would be nice to see, I think the OP would like you to sort the problem for him

Regards BoyOh

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 12:39 pm
by PiGraham
boyoh wrote:
Wed Jun 03, 2020 10:43 am
I think the OP would like you to sort the problem for him

Regards BoyOh
1. SaturdaySam (the OP) want to learn about Raspberry Pi. He may also enjoy learning about electronics but the most constructive response is how to do this with a Raspberry Pi.
2. I don't think he "would like you to sort the problem for him". He wants guidance in using a Pi to do this so he can learn
3. Don't forget the 10 second requirement.
4. keep cool and constructive.
5. if you prefer an electronics solution to fit the requirements two NPN transistors into the trigger pin of a 555 timer configured for 10 second monostable pulse would do it. Either input going high would trigger a 10s high pulse out.

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 2:25 pm
by drgeoff
PiGraham wrote:
Wed Jun 03, 2020 12:39 pm
5. if you prefer an electronics solution to fit the requirements two NPN transistors into the trigger pin of a 555 timer configured for 10 second monostable pulse would do it. Either input going high would trigger a 10s high pulse out.
Afraid that doesn't meet the originally stated requirement either. Remember "each of the 2 input pins would activate a separate output pin."

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 3:45 pm
by boyoh
PiGraham wrote:
Wed Jun 03, 2020 12:39 pm
boyoh wrote:
Wed Jun 03, 2020 10:43 am
I think the OP would like you to sort the problem for him

Regards BoyOh
1. SaturdaySam (the OP) want to learn about Raspberry Pi. He may also enjoy learning about electronics but the most constructive response is how to do this with a Raspberry Pi.
2. I don't think he "would like you to sort the problem for him". He wants guidance in using a Pi to do this so he can learn
3. Don't forget the 10 second requirement.
4. keep cool and constructive.
5. if you prefer an electronics solution to fit the requirements two NPN transistors into the trigger pin of a 555 timer configured for 10 second monostable pulse would do it. Either input going high would trigger a 10s high pulse out.

Yes your circuit would do the job fine , the 555 timer a good idea , The OP said both IN/Puts must NOT be high ( 1 ) at the same time
So the two transistor bases must be OR Exclusive OR ( b1) OR ( b2) But not both at the same time
This is basic transistor LOGIC. ( TTL ) Long before the Raspberry Pi was ever thought of But I'm 88yrs so may be old fashion
in these days No computer so no buttons to press and ask how to do this and do that in my learning days The best Magazines
in them days was called EVERY DAY ELECTRONICS My loft is full of them You could buy a pack of 555s for a pound

Base 1 / Base 2 [ Out Put
H / H [ L
L / H [ H
H / L [ H
L / L [ L

Regards BoyOh

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 4:26 pm
by PiGraham
boyoh wrote:
Wed Jun 03, 2020 3:45 pm
The OP said both IN/Puts must NOT be high ( 1 ) at the same time
So the two transistor bases must be OR Exclusive OR ( b1) OR ( b2) But not both at the same time
This is basic transistor LOGIC. ( TTL ) Long before the Raspberry Pi was ever thought of But I'm 88yrs so may be old fashion
in these days No computer so no buttons to press and ask how to do this and do that in my learning days The best Magazines
in them days was called EVERY DAY ELECTRONICS My loft is full of them You could buy a pack of 555s for a pound

Base 1 / Base 2 [ Out Put
H / H [ L
L / H [ H
H / L [ H
L / L [ L

Regards BoyOh
No, this is what the OP said:
SaturdaySam wrote:
Sun May 31, 2020 3:16 pm
I need to have 2 input pins on the GPIO constantly monitored so that when each pin goes high ( from external source) it provides a high output on a GPIO pin - each of the 2 input pins would activate a separate output pin. The 2 inputs pins would never be activated at the same time. This output has to stay high for 10 seconds and then go low. Once the output goes low then the whole process starts again.
"The inputs would never be activated at the same time". Not "the inputs might be active at the same time but I don't want that to act as a trigger"
No XOR needed. Just an OR and a Monostable needed.

But the question is about learning how to do something with Pi gpio so we are digressing.

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 4:30 pm
by PiGraham
boyoh wrote:
Wed Jun 03, 2020 3:45 pm
The best Magazines
in them days was called EVERY DAY ELECTRONICS My loft is full of them You could buy a pack of 555s for a pound
:D don't get me started on that (not this topic anyway). Wireless World?

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 6:00 pm
by rpdom
PiGraham wrote:
Wed Jun 03, 2020 4:30 pm
boyoh wrote:
Wed Jun 03, 2020 3:45 pm
The best Magazines
in them days was called EVERY DAY ELECTRONICS My loft is full of them You could buy a pack of 555s for a pound
:D don't get me started on that (not this topic anyway). Wireless World?
It was Practical Electronics for me.

I wonder how big a "pack" of 555s was? I can buy 10 for 99p on ebay now, or 100 for £2.70!

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 6:19 pm
by drgeoff
PiGraham wrote:
Wed Jun 03, 2020 4:26 pm
No XOR needed. Just an OR and a Monostable needed.
1. The OP wrote nothing that requires an OR function.

2. The OP wrote "each of the 2 input pins would activate a separate output pin." The "separate" in that makes it unambiguous that there is more than one output.

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 7:14 pm
by JohnsUPS
From the OP's description, it was said that the two inputs would never be high at the same time, but with two separate monostable circuits, this is a non-issue.

I would tackle this with a CD4538 dual monostable. Fewer parts than a 555 for just a 10 second delay circuit.
Also, depending on just what is being switched, there are time delay relays (fixed and adjustable) which might do the trick.
Also, how precise does this 10 second delay need to be?

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 7:16 pm
by PiGraham
drgeoff wrote:
Wed Jun 03, 2020 6:19 pm
PiGraham wrote:
Wed Jun 03, 2020 4:26 pm
No XOR needed. Just an OR and a Monostable needed.
1. The OP wrote nothing that requires an OR function.

2. The OP wrote "each of the 2 input pins would activate a separate output pin." The "separate" in that makes it unambiguous that there is more than one output.
You are half right, and I was half wrong - there is no OR function (definitely no XOR either).

Nothing ambiguous about it. Two outputs:
SaturdaySam wrote:
Sun May 31, 2020 3:16 pm
I need to have 2 input pins on the GPIO constantly monitored so that when each pin goes high ( from external source) it provides a high output on a GPIO pin - each of the 2 input pins would activate a separate output pin. The 2 inputs pins would never be activated at the same time. This output has to stay high for 10 seconds and then go low. Once the output goes low then the whole process starts again.
Two independent bits of in-out logic.

The only detail not given is whether the 10 second monostables should retrigger if the input pulses high again while the output is active.

Re: Monitor GPIO inputs

Posted: Wed Jun 03, 2020 7:22 pm
by PiGraham
JohnsUPS wrote:
Wed Jun 03, 2020 7:14 pm
From the OP's description, it was said that the two inputs would never be high at the same time, but with two separate monostable circuits, this is a non-issue.

I would tackle this with a CD4538 dual monostable. Fewer parts than a 555 for just a 10 second delay circuit.
Also, depending on just what is being switched, there are time delay relays (fixed and adjustable) which might do the trick.
Also, how precise does this 10 second delay need to be?
It's a non issue if you use independent circuits, but it could be a relevant detail for a software implementation that Sam is asking about.
If it is guaranteed the each channel will never overlap activation of the other channel you could do simple polling both inputs and when either one went high you could turn on the relevant output and wait for 10 seconds before looping back to the start.

Without that detail the implementation should keep responsive to the other input while the first channel is active, and vice versa. That is easy to do using state change callbacks, although there are various ways to do it. Just avoid blocking the program while an output is active.

Re: Monitor GPIO inputs

Posted: Mon Jun 08, 2020 3:07 pm
by boyoh
This is just an Idea of how it might be don , using more circuit control electronics to replace the Selector switch
for more auto control Push switches are momentary Bothe GPIOs set to Latch for 10 seconds Diodes to stop feed back

Just a Idea Regards BoyOh

Re: Monitor GPIO inputs

Posted: Mon Jun 08, 2020 6:10 pm
by drgeoff
@boyoh

Which part of "each of the 2 input pins would activate a separate output pin." in the opening post do you not understand?