Problems sinking current into digital I/O pins. .

I'm trying to drive an LED from one digital pin and sink it into another however it does not seem to work. I know this is not how an LED is typically driven, however I need to forward bias and reverse bias the LED so many times per second and this it the only way without additional circuitry. I know that PIC's can do it and I'm sure the atmega8 can do it as well but not familiar with the code enough. I read something in the atmega8 data sheet about a digital pin will sink 20ma at 5vcc, so I made sure that the current limiting resistor was large enough to keep me under 20ma. I have a feeling it has something to do with the commands of the arduino. Currently I use the pinMode(gndPin, INPUT) command to try to sink the LED into.

So my question is first of all is it possible to source an LED from one digital pin and sink it into another?
If so, am I correct in saying that it must be under 20ma?
And lastly what commands will allow me to do this?

Thanks for any help in advance!

hi

can you post the code you tried, and a schematic diagram of how you wired it?
We could speculate for days without those things :slight_smile:

In theory what you want to do should be possible:

All AVR ports have true Read-Modify-Write functionality when used as general digital
I/O ports. This means that the direction of one port pin can be changed without uninten-
tionally changing the direction of any other pin with the SBI and CBI instructions... Each output buffer has symmetrical drive
characteristics with both high sink and source capability. The pin driver is strong enough
to drive LED displays directly.

(p.51 of the Atmega8 datasheet)

PS:

Currently I use the pinMode(gndPin, INPUT) command to try to sink the LED into.

You need to use the output mode for sink/source. Input mode will always be Hi-Z, only sinking a few microamperes.
So for it to work, the pinmode has to always be OUTPUT. To sink you would set the pin LOW; to source, set it to HIGH.

D

Daniel,

Thanks for the help. . . works great, now that it is set as an output low. I've spent days trying to figure this one out. It would seem non logical (to me at least) to sink into an output, so I never would have thought about trying that.

Once again, thanks, I really appreciate the relief of frustration

Craig