Open Drain/ Push Pull


To configure a pin in output or input there is the "pinMode" function .
To configure the pin level (in case of output) , there is the "digitalWrite" function,
But is there a function to configure the pin in open drain or push pull ?

Thanks by advance

Using the search feature on this site, one can come up with several thingies like this one
a thingy about open drain. Also, you can do an internet search on the words "arduino gpio open drain". That way you won't have to wait for someone else to do it for you.

Yes, that function is pinMode().

There is a procedure: burn the pullup transistor of the output to convert it permanently into open drain, or into disfunct with not enough luck.

Look into the data sheet of your Arduino whether it supports open drain outputs at all.

Only if the processor supports it. On the AVR-based Arduinos (UNO, Nano, Mini, Mega, Leonardo, Micro...) the outputs are all Push-Pull. You can use an external N-Channel MOSFET to convert the output to Open Drain or an NPN transistor to convert the output to Open Collector.

You can SIMULATE an Open Drain output by using:
pinMode(pin, OUTPUT); digitalWrite(pin, LOW);
for LOW and:
pinMode(pin, INPUT);
for High Impedance.

1 Like

Well not quite. The AVR pins support pseudo-open-drain as you explain (ie the pin still has a protection diode to the Vcc rail, but is driven only by the low-side FET):

The fact there is a protection diode still connected is nothing to do with push-pull v. open drain per se - you can have open-drain with a protection diode and still implement wired-AND busses using it.

void setup ()
  pinMode (pin, INPUT) ;
  digitalWrite (pin, LOW) ;

void loop ()
  pinMode (pin, OUTPUT) ; // drive pin LOW
  pinMode (pin, INPUT) ; // float pin

To do level shifting to a higher voltage requires that there be no protection diode, and that the output FET is high-voltage rated. This is the full open drain / open collector arrangement, but many logic chips have open-drain pins that are not high-voltage.