iliblabla
Posts: 3
Joined: Tue Mar 26, 2019 1:41 pm

Detecting a 24v Impulse via GPIO Pins

Mon Aug 19, 2019 2:36 pm

Hey Guys!
I would like to detect a 24v Signal with use of the GPIO Pins. How do I do this the best and simplest way?

I thought of using a Optocoupler to seperate the Pi from the high voltage and then use PI4Js GPIO state change listener to
detect the Signal of the Optcoupler whenever it gets activated by the 24v Signal.
Is this a way to do it or am I talking nonsense? :D

drgeoff
Posts: 9885
Joined: Wed Jan 25, 2012 6:39 pm

Re: Detecting a 24v Impulse via GPIO Pins

Mon Aug 19, 2019 4:40 pm

iliblabla wrote:
Mon Aug 19, 2019 2:36 pm
Hey Guys!
I would like to detect a 24v Signal with use of the GPIO Pins. How do I do this the best and simplest way?

I thought of using a Optocoupler to seperate the Pi from the high voltage and then use PI4Js GPIO state change listener to
detect the Signal of the Optcoupler whenever it gets activated by the 24v Signal.
Is this a way to do it or am I talking nonsense? :D
Yes that will work but I don't know where you can get a PI4J.

trejan
Posts: 709
Joined: Tue Jul 02, 2019 2:28 pm

Re: Detecting a 24v Impulse via GPIO Pins

Mon Aug 19, 2019 4:50 pm

iliblabla wrote:
Mon Aug 19, 2019 2:36 pm
I thought of using a Optocoupler to seperate the Pi from the high voltage and then use PI4Js GPIO state change listener to
detect the Signal of the Optcoupler whenever it gets activated by the 24v Signal.
Is this a way to do it or am I talking nonsense? :D
Yes. Optocoupler is the way to go.
drgeoff wrote:
Mon Aug 19, 2019 4:40 pm
Yes that will work but I don't know where you can get a PI4J.
They're talking about the Pi4J Java library and not a Raspberry Pi 4J.

iliblabla
Posts: 3
Joined: Tue Mar 26, 2019 1:41 pm

Re: Detecting a 24v Impulse via GPIO Pins

Wed Sep 04, 2019 10:48 am

Sorry for answering that late, I was quite distracted the last few weeks!
Alright, I try it then :)

User avatar
HermannSW
Posts: 1572
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Detecting a 24v Impulse via GPIO Pins

Wed Sep 04, 2019 11:13 am

Optocoupler provides electric separation, but at the price of some latency added.
In case latency is too high, a step-down converter might work (4.75-40V to 3.3V):
https://www.aliexpress.com/item/32787217667.html
A 1--6.3 two-resistor voltage divider might do the job as well (1--2 is for 5V->3.3V).
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12327
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Detecting a 24v Impulse via GPIO Pins

Wed Sep 04, 2019 1:38 pm

optocouplers work at the speed of light, they should not really introduce perceptible delays, but how much of a l real delay they introduce may depend on the model of isolator used.
In practice I don't foresee speed problems with opt-isolators, unless you need gigahertz speeds.

contrary to that step down converters work with switching frequencies in the tens or hundreds of kilohertz ranges, and so are susceptible to delays, and are unusable as "level converters" if you need reaction speeds above a few hundred herz.

The simplest solution (a resistor divider) might be the best unless you need isolation. but watch out for polarity inversions, as GPIO's also can be destroyed with negative voltages.

its also a good idea to protect against glitches by putting a small cap (100nF) across the GPIO and GND.

whatever solution you choose, always make sure your logical high doesn't go below 2.0V or above 4.0V (the latter will destroy your PI!)

User avatar
PeterO
Posts: 5066
Joined: Sun Jul 22, 2012 4:14 pm

Re: Detecting a 24v Impulse via GPIO Pins

Wed Sep 04, 2019 2:00 pm

mahjongg wrote:
Wed Sep 04, 2019 1:38 pm
optocouplers work at the speed of light, they should not really introduce perceptible delays, but it way depend on the model of isolator used.
In practice I don't foresee speed problems with opt-isolators, unless you need gigahertz speeds.
The simple opto-isolators with just a LED and phototransistor can introduce a delay of several microseconds.
If that order of delay is a problem in your application then make sure you check the data sheet for any device you consider to make sure the turn on and turn off times (note that they may not be the same) are short enough to not cause malfunctions.

As an aside, my personal favorite is the "Isocom H11L1 Schmitt Trigger Isolator" as it only needs 1mA of LED current, has active Schmitt Trigger to give clean output edges for slow input transitions, and works well with the 20V 2µS pulses I need to convert when building circuits that interface to the 1960's computer I look after.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

iliblabla
Posts: 3
Joined: Tue Mar 26, 2019 1:41 pm

Re: Detecting a 24v Impulse via GPIO Pins

Thu Sep 05, 2019 10:07 am

The delay isnt a problem for my use case :)

But it's getting a little bit weird here.
I have to Raspis and my program works only on one of them.

Here is how the setup looks like:
I am using a ARCELI PC817 for this.
The positive Pol is connected to the GPIO Pin 04 (5v DC power) and the negative Pol is connected to Pin 03, which my application is listening to.
So, when I connect my Raspi 1 to the optocoupler, I only get ~1,96v to begin with. When the optocoupler is "activated" it drops to 1,26v.
This I can detect with my Application.
Raspi2 nevertheless puts out 4,87v and when the optocoupler is connected, it only drops to 4,85v. This difference is too small to detect.

But why do they have different Outputs in Voltage? I checked the voltage on various Pins from the Raspi1 and it seems that nearly all of them have ~3 less then Raspi2. Even the ground Pins show me a negative voltage -3,18v.
Is Raspi1 defect or am I missing something?

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

Re: Detecting a 24v Impulse via GPIO Pins

Sun Sep 08, 2019 8:27 pm

The first thing is the pi gpio is 3.3v and is not 5v tolerant.

Connecting 5v to a gpio input will damage you pi and eventually kill it.

It sounds like you have your opto isolator incorrectly connected.

As for the strange voltages are you sure you are measuring them correctly as the pi has no negative voltages on board so how can you be getting -3v

And how are you measuring this on the ground !

Edit........ from your explanation above this is how you opto isolator should be connected to the pi.

Image
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Automation, sensing and robotics”