Author Topic: Current flowing away from ground?  (Read 4030 times)

0 Members and 1 Guest are viewing this topic.

Offline cryptykTopic starter

  • Contributor
  • Posts: 21
Current flowing away from ground?
« on: April 10, 2015, 02:36:31 pm »
Hi,
I'm really new to this and I'm playing around with the attached circuit on my breadboard.  I'm using a Raspberry Pi and the GPIO pins.  For some reason, when I turn on the output pin for the LED, it triggers the input pin for one of the switches.  The only way I imagine this could happen is if current from the LED was flowing away from ground and back into the switch's output pin, but I'm sure that's not right. 
Here's the setup (from the left on the diagram)
R2 is a 1k resistor
R3 is a 10k pulldown resistor
The left GPIO pin is set to input, and to trigger on "falling"

Same setup for the center switch, but a different GPIO pin.

The LED has a 56ohm resistor, and the GPIO pin is set to output.

Any thoughts on why lighting up the LED results in a "falling" state on the input PIN for the center switch?

Thanks!!!
Ryan
 

Offline cryptykTopic starter

  • Contributor
  • Posts: 21
Re: Current flowing away from ground?
« Reply #1 on: April 10, 2015, 02:48:44 pm »
It's on a 3.3v GPIO output pin.
 

Offline elgonzo

  • Supporter
  • ****
  • Posts: 688
  • Country: 00
Re: Current flowing away from ground?
« Reply #2 on: April 10, 2015, 02:51:51 pm »
It's on a 3.3v GPIO output pin.
Ahh, okay. Your schematic is a bit confusing. The double chevrons do indicate GPIO pins of the Raspberry Pi, right?

(Tip: Label connections to I/O pins and draw them only in a horizontal manner, unless you are starved of space on your schematic. In your schematic here, the way you have drawn them could easily be confused with power supply or ground connection when glancing over the schematic...)

Does the same also happen with the pin responsible with the GPIO pin reading the S1 switch, or is only the GPIO pin for S2 affected?
To me it sounds either like a wiring error on your breadboard, or some programming error/bug in whatever you coded on your Raspberry Pi...
« Last Edit: April 10, 2015, 03:03:12 pm by elgonzo »
 

Offline bobcat

  • Regular Contributor
  • *
  • Posts: 94
  • Country: us
Re: Current flowing away from ground?
« Reply #3 on: April 10, 2015, 03:00:44 pm »
Your LED is pulling about 32ma through a common ground with the switches.
Try putting a separate ground connection to the led.
Also check the high level output current capability on your MCU pins. You may to make that active low.
 

Offline cryptykTopic starter

  • Contributor
  • Posts: 21
Re: Current flowing away from ground?
« Reply #4 on: April 10, 2015, 04:35:05 pm »
Awesome.  Thank you guys!
I updated the schematic (attached).  I'd love feedback on it because I want to learn how to communicate my design more clearly.

It only seems to affect the GPIO12 input.

I don't think it's a software problem.  If I unplug the LED, or I comment out the one line responsible for setting GPIO4 high, everything else works.  It very well might be a wiring error - I'll go back and look at the breadboard tonight.

I'll also try to use a separate ground pin for the LED. 

To educate myself, is it even possible that 3.3v current is leaving the LED and "leaking" through the 10k resistor and triggering the GPIO12 pin enough to cause the Rpi to think it's "falling"?

Thanks!
Ryan
« Last Edit: April 10, 2015, 05:28:44 pm by cryptyk »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Current flowing away from ground?
« Reply #5 on: April 10, 2015, 05:07:23 pm »
The Pi is rather short on hardware specs for its GPIO pins (due to Broadcom's NDA policy), but they can be programmed for various output drive strengths up to 16mA and various people who have seen the Broadcom data say 17mA should be regarded as the upper limit.    Unless your LED Vf is up around 2.2-2.4V or higher, you are almost certainly overloading the GPIO driving the LED.

Its also worth noting that the total extras current from the 3.3V rail INCLUDING all current sourced by high GPIOs needs to be kept under 50mA.

Use of logic buffers between the PI and any indicators (LEDs etc.) is strongly recommended.
 

Offline cryptykTopic starter

  • Contributor
  • Posts: 21
Re: Current flowing away from ground?
« Reply #6 on: April 10, 2015, 05:27:32 pm »
Thanks for the reply.  I don't understand most of it, but want to see if I can parse.  Thanks for your patience!

The Pi is rather short on hardware specs for its GPIO pins (due to Broadcom's NDA policy), but they can be programmed for various output drive strengths up to 16mA and various people who have seen the Broadcom data say 17mA should be regarded as the upper limit.    Unless your LED Vf is up around 2.2-2.4V or higher, you are almost certainly overloading the GPIO driving the LED.
I calculated the resistor I'm using for the LED circuit using 3.3V supply voltage (assuming this is what the GPIO pin outputs when it's high?), 2.2V voltage drop across the green LED, and 20mA LED current.  My math gave me a 55ohm resistor, but I only had a 56.  If I'm understanding what you're saying, I shouldn't use more than 16-17mA for the LED current?  That gives me 73ohms for the resistor.  I'll try that when I get home.  I'd like to understand the "why", though.  Am I just pulling too much current from the GPIO pin for a Pi?  Does that lead to instability, etc?

Its also worth noting that the total extras current from the 3.3V rail INCLUDING all current sourced by high GPIOs needs to be kept under 50mA.
If I'm reading correctly, I wouldn't want to drive 4 different LEDs simultaneously at 15mA?  That seems really limiting!  Is that the point at which I would power the LEDs off a different power supply and use the GPIO pin to just switch the power on/off to the LEDs?


Use of logic buffers between the PI and any indicators (LEDs etc.) is strongly recommended.

A quick search didn't bring anything up that made it clear why, other than for circuit protection of the Pi.  Is this just a best practice to make sure that something doesn't get wired awry that causes current to flow back into the input pin?  Or is this something that would fix the problem I'm having with the switch?

Thanks!
Ryan
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 19497
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Current flowing away from ground?
« Reply #7 on: April 10, 2015, 06:53:09 pm »
Basic troubleshooting:
  • visually check the circuit has been wired up correctly
  • check electrical continuity
  • ...especially with those wretched poke-a-wire-in-a-leaf-spring-and-hope-it-makes-contact breadboards
  • use a multimeter to check the voltages are what you would expect
  • bring up one bit of the circuit at a time, e.g. LED on its own, then switch on its own, then LED and switch
  • throw out the breadboard - you'll spend more time debugging the breadboard than debugging your circuit
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline Laura

  • Contributor
  • Posts: 18
  • Country: us
Re: Current flowing away from ground?
« Reply #8 on: April 10, 2015, 07:56:50 pm »
Also check the high level output current capability on your MCU pins. You may to make that active low.

I second this.

If you look at old electronics, the switched side of inputs and outputs is almost always the ground leg. In an era of NPN transistors and TTL logic, it just worked better that way. Even today, pullup resistors are preferred over pulldowns, and many output drivers can sink current to ground better than they can source current from the supply rail.

Ground side switches also means you don't have a power supply rail running out to your switches.

So, essentially, turn your circuit diagram upside down.
 

Offline cryptykTopic starter

  • Contributor
  • Posts: 21
Re: Current flowing away from ground?
« Reply #9 on: April 10, 2015, 08:14:12 pm »
Cool.  I have a couple of things to try tonight, assuming the wiring diagram is actually correct.
1)  Separate ground for the LED
2)  Bigger resistor for the LED
3)  Pull-up resistors on the switches instead of pull-down

I'd love to understand the theory of what's happening, as well, if there's a high-level way to explain it intuitively.  Is the ground not capable of sinking the pulse of current created on the cathode side of the LED, so some spare current makes it's way to the other GPIO pin?  That kind of mental model would help me out...

Thanks!
Ryan
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Current flowing away from ground?
« Reply #10 on: April 10, 2015, 08:39:10 pm »
You need to check your ground wiring. There should be less than 0.1V between your breadboard ground strip and a ground point on the Pi (e.g. the USB socket shell) with the LED on.  If its more, you've got a bad connection somewhere

The other thing you should try is to increase the LED's series resistor to get the current down to 4 or 5 mA.  That's plenty bright enough for most applications using modern high efficiency LEDs.  100R should be in the right ballpark if your LED Vf is actually 2.2V.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf