Pages: [1]   Go Down
Author Topic: Is it possible to write a pin open?  (Read 303 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Team WIKISPEED
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to switch a pin open and high as opposed to high or ground?

analog or digital, can either one write open?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46045
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A pin is either INPUT or OUTPUT. In either configuration, it is either HIGH or LOW.

What do you mean by open? Files and doors can be open. Pins can't.
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1010
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes.

If a pin is INPUT, the impedance is very high. So the pin is floating.
If a pin is OUTPUT, it can be set HIGH or LOW.
So it it possible to use a pin as a open collector by switching it between INPUT and OUTPUT LOW. However two instructions are needed for the microcontroller, and using the pull-up resistor should be avoided. You have to read the datasheet for that.
The 'open collector' is not a real open collector, since the voltage on the pin may not be above 5V.

If you want to switch between open/floating and high 5V. You need a few instructions:
Code:
const int myPin 10;

// pin open/floating
// set as input, no pull-up in Arduino 1.0.1 and higher.
pinMode( myPin, INPUT);

delay(1000);

// pin HIGH
// first set the pullup,
// to be sure the output is high at the moment the pin is set as OUTPUT
pinMode( myPin, INPUT_PULLUP);
pinMode( myPin, OUTPUT);
digitalWrite( myPin, HIGH);

delay(1000);

The analog inputs can be set as digital input or digital output pins.
So it is the same for analog inputs.

http://arduino.cc/en/Reference/pinMode
http://arduino.cc/en/Reference/digitalWrite
« Last Edit: January 15, 2013, 06:00:09 am by Krodal » Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4019
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If a pin is INPUT, the impedance is very high. So the pin is floating.
If a pin is OUTPUT, it can be set HIGH or LOW.
So it it possible to use a pin as a open collector by switching it between INPUT and OUTPUT LOW. However two instructions are needed for the microcontroller, and using the pull-up resistor should be avoided. You have to read the datasheet for that.
The 'open collector' is not a real open collector, since the voltage on the pin may not be above 5V.

If you want to switch between open/floating and high 5V. You need a few instructions:
Code:
const int myPin 10;

// pin open/floating
// set as input, no pull-up in Arduino 1.0.1 and higher.
pinMode( myPin, INPUT);

delay(1000);

// pin HIGH
// first set the pullup,
// to be sure the output is high at the moment the pin is set as OUTPUT
pinMode( myPin, INPUT_PULLUP);
pinMode( myPin, OUTPUT);
digitalWrite( myPin, HIGH);

delay(1000);

The analog inputs can be set as digital input or digital output pins.
So it is the same for analog inputs.

http://arduino.cc/en/Reference/pinMode
http://arduino.cc/en/Reference/digitalWrite
Logged

Examples can be found in your IDE.

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4019
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If a pin is INPUT, the impedance is very high. So the pin is floating.

It is only floating if you don't connect it to anything and have it set LOW.
And who reads a disconnected INPUT except someone looking for randoms in a weird way?

You can connect a pin to ground through a switch, set the pin to INPUT and digitalWrite it HIGH then when you close the switch it will ground to LOW **through the pullup resistor**. That makes a nice, safe button/switch circuit which at no time is floating but does need to be debounced.

 
Logged

Examples can be found in your IDE.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6893
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to switch a pin open and high as opposed to high or ground?

analog or digital, can either one write open?

It seems like your term "OPEN" is not well understood. When I encounter this, I would try to explain why I want a pin "OPEN". You could help us understand your need to "OPEN" a pin if you tell us the why. Complete your story.
Logged


Pages: [1]   Go Up
Jump to: