Open Drain

To put an Arduino Input/Output into Open Drain mode I assume I do the following.

Set the Pin as an Input

Send the Input HIGH to present a High Impedance at the Input

Send the Input LOW to Sink current

Can someone please confirm I have this right or otherwise.

No.

Open drain means you have an output, so you'd need to set it up as such.
Setting it HIGH means it will put 5 volts to that pin.
Setting it LOW means it will connect it to GND (0 volts).

They (the electronics world) call it an Output!! but if you google Open Drain the explanation is that it can only Sink current or present a High Impedance so it cannot output anything. :slight_smile: The Output definition is very confusing.

Firefox:
They (the electronics world) call it an Output!! but if you google Open Drain the explanation is that it can only Sink current or present a High Impedance so it cannot output anything. :slight_smile: The Output definition is very confusing.

Open drain, like open collector outputs are used where the external circuitry determines what the HIGH output voltage needs to be and then the open drain output can turn it LOW by turning on and the output signal goes to ground. There is a real world place for open drain/open collector outputs Vs full push-pull output pins. Simply wiring an external pull-up resistor will convert a open drain/open collector output pin to a standard output that you seem more comfortable with. :wink:

One good example for the need of open drain output pins is the AVR chip's I2C clock and data pins when I2C is engaged. These two pins have to be able to switch from input or output mode to support bi-directional communications on these two pins, and they need to be open drain outputs so the external pull-up resistor can determine the logic voltage level to use with specific I2C chips.

Lefty

Firefox:
They (the electronics world) call it an Output!! but if you google Open Drain the explanation is that it can only Sink current or present a High Impedance so it cannot output anything. :slight_smile: The Output definition is very confusing.

No it is not.

Sinking current IS an output. Just like sourcing current is an output.

There is no open drain or open collector configuration in an arduino. If you want one you have to use an external transistor or FET.

1 Like

Grumpy_Mike:

Firefox:
They (the electronics world) call it an Output!! but if you google Open Drain the explanation is that it can only Sink current or present a High Impedance so it cannot output anything. :slight_smile: The Output definition is very confusing.

No it is not.

Sinking current IS an output. Just like sourcing current is an output.

There is no open drain or open collector configuration in an arduino. If you want one you have to use an external transistor or FET.

Well except if you enable the I2C hardware, then it's two signal pins will be open drain when in output mode.

Lefty

Can't he just use INPUT/LOW as high impedance, and switch to OUTPUT/LOW to sink current?

"Can't he just use INPUT/LOW as high impedance"

That's what is needed if the internal pullup resistor is to be unconnected.

Grumpy_Mike:

Firefox:
They (the electronics world) call it an Output!! but if you google Open Drain the explanation is that it can only Sink current or present a High Impedance so it cannot output anything. :slight_smile: The Output definition is very confusing.

No it is not.

Sinking current IS an output. Just like sourcing current is an output.

There is no open drain or open collector configuration in an arduino. If you want one you have to use an external transistor or FET.

It may not be confusing to you but it is to me.

Doesn't Sinking Current mean the current is going into the Pin?

If you I set the Arduino digital pin as an Input, and set it LOW, will it Sink Current?

If you I set the Arduino digital pin as an Input, and set it HIGH, will it present a HIGH Impedance?

If you I set the Arduino digital pin as an Input, and set it LOW, will it Sink Current?

No it won't. It will be high impedance.

If you I set the Arduino digital pin as an Input, and set it HIGH, will it present a HIGH Impedance?

It will be high impedance with an added approximately 50K pull-up resistor.

To sink current it has to be OUTPUT mode and LOW.

Doesn't Sinking Current mean the current is going into the Pin?

Yes. If you have it output/low it will attempt to make that pin 0V, thus sinking any current going into it. It will succeed in comfortably sinking around 20 mA.

If it is output/high it will attempt to make that pin 5V, thus sourcing that current. It will succeed in comfortably sourcing around 20 mA.

Arduino digital pin as an Input, and set it LOW, will NOT Sink Current. Its an input. Setting it low only disables the internal pullup resistor. That will be the High Impedance state.

Arduino digital pin as an Input, and set it HIGH, will turn on the internal 20Kto 50K pullup resistor. Pretty high impedance, but still capable of outputting some current (like 1/4 of a mA, not much, but enough to pull a switch high, or make a sensitive LED appear to be dimly on).

Try this experiment with two LEDs:

One connects pin D8 to +5v. Thus for the LED to come on D8 has to sink current.
The other LED connects pin D9 to Gnd. Thus for the LED to come on D9 has to source current.

Run this sketch:

void setup ()
  {
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  }  // end of setup

void loop ()
  {
  digitalWrite (8, LOW);
  digitalWrite (9, LOW);
  delay (500);
  digitalWrite (8, HIGH);
  digitalWrite (9, HIGH);
  delay (500);
  }  // end of loop

The sketch turns D8 and D9 on and off at the same time, but the LEDs blink alternately. The D8 LED lights up when D8 is LOW, and the D9 LED lights up when D9 is HIGH.

Both pins are output.

Excellent, thank you for all of your help.

Add a 3rd state, D9 as input with pullup enabled.

Firefox:
They (the electronics world) call it an Output!! but if you google Open Drain the explanation is that it can only Sink current or present a High Impedance so it cannot output anything. :slight_smile: The Output definition is very confusing.

The insight you need is that input and output refer to information flow, not anything like charge or current or voltage.

In fact an Arduino pin used as an open-drain can be used for input at the same time - so its actually an IO pin - this is
exactly why open-drain is useful in protocols like I2C.

When the pin is pulled LOW (mode = OUTPUT, value = LOW), it will will always be LOW, so this is outputing only,
but when it is hi-Z (mode = INPUT, a.k.a. "tri-stated") you are both outputing and inputing - outputing the fact that
its not being pulled LOW by you, but inputting information about whether something else is pulling it low.

The OneWire protocol used by Dallas Semiconductor devices are an example of this clever signalling technique.
Such a protocol standardizes when each participant should be idle and listening, and when it can "transmit" - very
similar to a wireless data link in fact.

Hello every one,

Firefox:
To put an Arduino Input/Output into Open Drain mode I assume I do the following.

I still not sure the right way to turn the pin as open drain.

I want to use a digital pin as PWM generator to control a DC voltage from 0 to 9V as it follows.

Thank you for your time and help

Other then the two I/O pins associated with the two I2C hardware pins you can't place any other I/O pins into 'open drain' output mode, and output pin are always in either an active high (sourcing +5vdc) or low state (active sinking to ground). Plus all the I/O pins have internal clamping protection pins wired to ground and Vcc to protect the chip from voltage below ground or above Vcc.

You need to buffer your arduino output pin with transistor(s) or logic gates that do have true open collector or open drain outputs.

Lefty

Thank you.

Not even messing around with atmel's internal registers?? I know there are other uControllers that allow to set a PWM output as open drain.

Do you mean by buffering something like this?

Cheers

Yes, but:

Use a PNP transistor to source current to the load, not an NPN.
Use a resistor between the base and the arduino pin to protect the pin. 270 to 1K ohm should be good.

The cap will limit how fast the signal can switch, and/or slow the rate of change of the edges.