Pages: [1]   Go Down
Author Topic: Tri-state logic on IO pins?  (Read 3434 times)
0 Members and 1 Guest are viewing this topic.
Atascadero, CA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 468
Arduino addict
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Since the digital IO pins can be used for I and O  smiley-wink  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!
Logged

What about elevensies? Luncheon? Afternoon tea? Dinner? Supper?

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Atascadero, CA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 468
Arduino addict
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

What about elevensies? Luncheon? Afternoon tea? Dinner? Supper?

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-wink

Lefty
Logged

Pages: [1]   Go Up
Jump to: