Go Down

Topic: Tri-state logic on IO pins? (Read 12720 times) previous topic - next topic

koyaanisqatsi

Since the digital IO pins can be used for I and O  ;)  Can their direction be changed as necessary to accommodate/emulate a tri-state output?

I have a specific need to either ground the pin's output or let if go to a high impedance so that the device I'm controlling can rise to well above 5V.  (I can protect the Arduino pin from unhealthy voltages.)  But I need to know if this is a valid use of the pin input/output setting.

And would I need to address the built-in pull-something resistor?

Thanks!

retrolefty

The pinMode function can be used to put pin into a quasi Tri-state mode by setting it to input mode. When mode is set as output then either a high or low can be generated with the digitalWrite function. I believe the best way to ensure that the internal 'soft' pull-up is disabled is to make the output state a low before setting the mode to input.

Lefty


Cross

digitalWrite( pinNumber, LOW );
pinMode( pinNumber, OUTPUT );  // now we're sourcing current, i.e. GND
pinMode( pinNumber, INPUT ); // now we're tri-stated
pinMode( pinNumber, OUTPUT );  // and back again


koyaanisqatsi

Cool, so flipping the pinMode back and forth between input and output (very rapidly) is not going to harm anything then?

retrolefty

Quote
Cool, so flipping the pinMode back and forth between input and output (very rapidly) is not going to harm anything then?


Nothing except maybe your brain during checkout and troubleshooting time  ;)

Lefty

Go Up