ephestione
Posts: 15
Joined: Wed Aug 15, 2018 10:46 am

GPIO input current draw

Fri May 24, 2019 12:11 pm

I pondered whether to add to this other topic:
viewtopic.php?t=143632
but in the end the use case was different, the topic didn't reach a conclusive answer, and I would be resuscitating a very old thread.

So here it goes: if I use a switch/sensor to connect an input pin to the 3v3 line, and this switch is closed, how much current does the input pin draws from the 3v3 line while reporting a HIGH?

And this is the use case: I have a home alarm system, I re-used the old sensors, each to one input pin, PLUS a long loop tamper which goes in series to all the sensors (and soon a couple more sensors and some sirens). So, imagine a loopback from and to the raspi for each and every component for 1900sqft worth of areas, running on a small diameter wire, let's say 23AWG stranded copper, plus a short length of cat5 wire which doesn't really change much.
I have no idea of the total length of the loop coming back and forth for each component, but I can ballpark a total resistance, let's say 20Ohm assuming an exaggerated 300m total length.

Now, I am using the GPIO PHP library, with several watchdogs, and I keep getting weird readings on the tamper loop pin, that is, it reads LOW->HIGH transitions without any previous HIGH->LOW, and also it occasionally reads HIGH->LOW immediately followed by LOW->HIGH without any component having been really disconneted, to the point that I had to adjust the PHP code to compensate for these occurrencies (and adding several otherwise redundant and useless queries to the already slow SD-based database which I very much would like to avoid).

One of the things I thought, is that, being the loop tamper so long, the resistance might be too high, and the reading from the 3v3 line might get confused for a LOW.
Knowing the input pin current draw I might fancy a total voltage drop over the cable and decide if that's the case, or if I need to look elsewhere.

Brandon92
Posts: 768
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: GPIO input current draw

Fri May 24, 2019 1:15 pm

I think you find reading this information interesting.
https://www.digikey.com/en/articles/tec ... lectronics

This will cover how you can connect a switch over long wire to a digital input. With some examples.

User avatar
rpdom
Posts: 14065
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO input current draw

Fri May 24, 2019 1:35 pm

The GPIO is designed for very short connections. Current is normally in the microamp region.

With a long connection you will pick up all sorts of stray signals that could trigger the GPIOs.

I use an opto isolator when I have this situation. The button side of the opto can be driven from 5V and a resistor with a relatively high current. The other side will be powered from 3.3V and a pull up (or down) resistor and use a much lower current. Because the opto needs at least 3-5mA to trigger it the stray signals get ignored.
Signature is on holiday.

ephestione
Posts: 15
Joined: Wed Aug 15, 2018 10:46 am

Re: GPIO input current draw

Fri May 24, 2019 1:55 pm

Thank you, never thought such a long wire could act as an antenna... I mean, it runs in pairs, but those pairs are not twisted (they are shielded though), but whatever the situation, I could rather run the tamper loop with the same 12V used for the main power source of the system, and optocouple it with the input pin :)

Brandon92
Posts: 768
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: GPIO input current draw

Fri May 24, 2019 2:32 pm

ephestione wrote:
Fri May 24, 2019 1:55 pm
(they are shielded though),
Did you connect the shield at both ends, otherwise you could use a normal cable and it makes no difference.

And a higher voltage and more current will also help with some filtering (resistor + capacitor)

ephestione
Posts: 15
Joined: Wed Aug 15, 2018 10:46 am

Re: GPIO input current draw

Fri May 24, 2019 3:26 pm

Brandon92 wrote:
Fri May 24, 2019 2:32 pm
Did you connect the shield at both ends, otherwise you could use a normal cable and it makes no difference.

And a higher voltage and more current will also help with some filtering (resistor + capacitor)
huh... no, the shield is not connected anywhere, but my limited understanding is that shielding alone should act as a faraday cage and stop passive current from being generated, no?
My field of work has nothing to do with electronics... so I am going to google how to make a filter with resistor+capacitor :geek:

ephestione
Posts: 15
Joined: Wed Aug 15, 2018 10:46 am

Re: GPIO input current draw

Fri May 24, 2019 3:33 pm

ephestione wrote:
Fri May 24, 2019 3:26 pm
I am going to google how to make a filter with resistor+capacitor :geek:
For future readers' reference, a simple low pass filter consists of a resistor between Vcc-in and Vcc-out, bein the Gnd common, a capacitor between the Vcc-out and Gnd. How to size said resistor and capacitor is out of my comprehension, even after doing some reading, so I think I will pass on implementing such filter :P

Brandon92
Posts: 768
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: GPIO input current draw

Fri May 24, 2019 3:40 pm

ephestione wrote:
Fri May 24, 2019 3:33 pm
ephestione wrote:
Fri May 24, 2019 3:26 pm
I am going to google how to make a filter with resistor+capacitor :geek:
For future readers' reference, a simple low pass filter consists of a resistor between Vcc-in and Vcc-out, bein the Gnd common, a capacitor between the Vcc-out and Gnd. How to size said resistor and capacitor is out of my comprehension, even after doing some reading, so I think I will pass on implementing such filter :P
See the link I have posted above. There is also a low past filter in it. And is not so hard to understand with they explanation.

I will come back to the shield explanation.

ephestione
Posts: 15
Joined: Wed Aug 15, 2018 10:46 am

Re: GPIO input current draw

Fri May 24, 2019 3:41 pm

ephestione wrote:
Fri May 24, 2019 3:33 pm
How to size said resistor and capacitor is out of my comprehension, even after doing some reading
On second thought, with this calculator:
http://www.learningaboutelectronics.com ... hp#answer1
it appears that using components which I already have, 10kOhm resistor and 10uF capacitor, I get a nice 1.6Hz cutoff frequency, while with a 1KOhm resistor I get 16Hz. But I think I'll go with 1KOhm and 47uF at 3Hz

dl324
Posts: 107
Joined: Mon May 06, 2019 7:33 pm
Location: Pacific Northwest, USA

Re: GPIO input current draw

Fri May 24, 2019 5:02 pm

ephestione wrote:
Fri May 24, 2019 1:55 pm
never thought such a long wire could act as an antenna...
It doesn't take much wire to have an adverse antenna effect. I was experimenting with GPIOs on a Pi0. When I measured pins that weren't being driven, I picked line frequency. Of course, it was me coupling the signal to the short wire used for a probe...

dl324
Posts: 107
Joined: Mon May 06, 2019 7:33 pm
Location: Pacific Northwest, USA

Re: GPIO input current draw

Fri May 24, 2019 5:06 pm

ephestione wrote:
Fri May 24, 2019 3:26 pm
but my limited understanding is that shielding alone should act as a faraday cage and stop passive current from being generated, no?
It needs to be grounded. All the unconnected shield does is create an equal potential (ideally) at all points of the cage. That equal potential won't be ground if it isn't grounded.

ephestione
Posts: 15
Joined: Wed Aug 15, 2018 10:46 am

Re: GPIO input current draw

Sun Jun 02, 2019 1:24 pm

rpdom wrote:
Fri May 24, 2019 1:35 pm
I use an opto isolator when I have this situation. The button side of the opto can be driven from 5V and a resistor with a relatively high current. The other side will be powered from 3.3V and a pull up (or down) resistor and use a much lower current. Because the opto needs at least 3-5mA to trigger it the stray signals get ignored.
I was finally getting my hands on my supply of LTV847 but then I realized that my design implemented common ground between led and phototransistor, so the "isolator" part of the optocoupler was pretty much useless.
Since we're talking 5V or tops 12V to drive a 3.3V input, wouldn't a simple transistor be safe enough?

ephestione
Posts: 15
Joined: Wed Aug 15, 2018 10:46 am

Re: GPIO input current draw

Sun Jun 02, 2019 1:38 pm

Or rather I'm seeing 3v3 zener's being the hype for that purpose.

Or rather again, I just put a 10uF capacitor across the most sensitive input which is the tamper loop, I get a nice small delay before the siren sounds when I open the tamper loop so I should be set without the hassle of setting up optocouplers.

Return to “Interfacing (DSI, CSI, I2C, etc.)”