Are GPIOs on a Spark Core supposed to be able to sink current or act as a DC return?

I am setting up an common cathode RGB LED as a status indicator for a small concept project. While I was setting up the prototype for testing, I noticed that when I run a 330 ohm resistor from VIN to the cathode and then connect a jumper wire from one of the legs of the LED to a digital I/O that isn’t configured, it sinks the current and acts like a ground and the LED lights up. Not what I had expected.

I have D7 configured as output and I get the same behaviour. I’m a little concerned as to the reasoning behind what seems like counter-intuitive occurrences.

Why is it doing this and what have I overlooked?

Shouldn't the common cathode be conneted to GND, since the RGB pins are the anodes which should be driven HIGH when you want the LED lit.

What pin was that?

There is the D7 LED that will always provide a connection to GND, irrespective of the GPIO setup.

Maybe 12:30 AM isn’t a good time to set up test environments. I mixed up voltage and current directions.

Though, something is interesting: why did it work when it was reversed? Diodes should block current in the opposite direction.

Yes, they should, but was it?
Is your diode really a common cathode and not a common anode (which would explain the D7 behaviour too)?

It was in my LED tray and there are no makings to indicate what it is or where I got it from.

I sat down with it and tried it as a common anode and got zilch. I rewired it to work as common cathode and it works, as expected.

I was messing with it really late last night and I think the timing may have something to do with it. Also, it didn’t help that my old buddy Jack Daniels decided to stop by.

I’ll try it again here shortly and see if I can replicate the findings from last night. If not, I’ll chalk it up to inebriated engineering (sounds like an interesting idea for a YouTube channel or a podcast).

Tangential question: I run ground to each pin and get either blue, green, or red. I combine blue and green and get a light blue but if I try to combine red and blue to get purple, I only get red, which doesn’t seem right. What gives?

I just tested it and I ran a jumper wire from VIN to a 330 ohm resistor in series with the anode (my apologies, I see now that I have a common ANODE rgb LED) and then ran a jumper wire from each leg (red, blue, and green) to a digital GPIO pin on the Spark Core (D0-D6) and they light up.

This means that I can sink current into a pin whether it is set up as input or output. That seems like strange behaviour. Is it supposed to do that? It is my understanding that an I/O pin configured for output isn’t run to ground–even in a low state. Is that an oversight/misunderstanding on my part?

You need to have a suitable resistor for each color, not one common resistor, otherwise the lower forward drop of red LEDs will pull all the current.
In parallel branches the voltage drop across each branch will be equal and the current will spread accordingly.
So when your red LED opens, the voltage on the blue and green LEDs (which have comparable forward drops but notably higher than for red LEDs) will be equal to the forward voltage of the red LED which won’t suffice to open these two LEDs.
With dedicated resistors for each color, you can adjust the voltage across the diodes individually.

You can google the typical forward drop for diffenrent LED colors and also the correct wiring of common anode/cathode RGB LEDs :wink:

1 Like

I also recommend connecting your common anode to 3V3 and not Vin.

That’s awesome! Thank you for taking the time to explain that. Seems like a rookie mistake and I’m a little ashamed of that.

I figured a common resistor could be shared throughout but I failed to consider forward voltage drops and how that will affect current and affinity towards easier paths.

It also explains why nearly all of the pictures I saw showed resistors on each leg.

So, should the resistor on the red LED be a little higher to balance when I have another diode closed in parallel?

I can definitely do that.

Can I ask the reason why 3v3 would be better than 5v so that I can make the best choice in the future?

You can go for different resistor values to adjust the current through each diode and “equalize” the brighness.
But don’t have to.

About @peekay123’s suggestion to use 3v3 instead:
The GPIOs are 3.3V pins so even if you drive a pin HIGH it will only go to 3.3V so you’ll still see some current flowing into the pin down from Vin which provides 5V.
And I’m not sure the pins will like that very much - even if they are not getting frazzled immediately, I’d not try it :wink:

2 Likes