Current flowing away from ground? - Page 1
Forum section: electronics / beginners

author: cryptyk
author_rank: Contributor
timestamp: April 10, 2015, 02:36:31 pm
content: 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 resistorR3 is a 10k pulldown resistorThe 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

author: cryptyk
author_rank: Contributor
timestamp: April 10, 2015, 02:48:44 pm
content: It's on a 3.3v GPIO output pin.

author: elgonzo
author_rank: Unknown
timestamp: April 10, 2015, 02:51:51 pm
content: Quote from: cryptyk on April 10, 2015, 02:48:44 pmAhh, 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...

author: bobcat
author_rank: Regular Contributor
timestamp: April 10, 2015, 03:00:44 pm
content: 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.

author: cryptyk
author_rank: Contributor
timestamp: April 10, 2015, 04:35:05 pm
content: 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

author: Ian.M
author_rank: Super Contributor
timestamp: April 10, 2015, 05:07:23 pm
content: 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.

author: cryptyk
author_rank: Contributor
timestamp: April 10, 2015, 05:27:32 pm
content: Thanks for the reply. I don't understand most of it, but want to see if I can parse. Thanks for your patience!Quote from: Ian.M on April 10, 2015, 05:07:23 pmI 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?Quote from: Ian.M on April 10, 2015, 05:07:23 pmIf 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?Quote from: Ian.M on April 10, 2015, 05:07:23 pmA 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

author: tggzzz
author_rank: Super Contributor
timestamp: April 10, 2015, 06:53:09 pm
content: Basic troubleshooting:visually check the circuit has been wired up correctlycheck electrical continuity...especially with those wretched poke-a-wire-in-a-leaf-spring-and-hope-it-makes-contact breadboardsuse a multimeter to check the voltages are what you would expectbring up one bit of the circuit at a time, e.g. LED on its own, then switch on its own, then LED and switchthrow out the breadboard - you'll spend more time debugging the breadboard than debugging your circuit

author: Laura
author_rank: Contributor
timestamp: April 10, 2015, 07:56:50 pm
content: Quote from: bobcat on April 10, 2015, 03:00:44 pmI 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.

author: cryptyk
author_rank: Contributor
timestamp: April 10, 2015, 08:14:12 pm
content: Cool. I have a couple of things to try tonight, assuming the wiring diagram is actually correct.1) Separate ground for the LED2) Bigger resistor for the LED3) Pull-up resistors on the switches instead of pull-downI'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

author: Ian.M
author_rank: Super Contributor
timestamp: April 10, 2015, 08:39:10 pm
content: 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 somewhereThe 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.