Go Down

Topic: Is it possible to write a pin open? (Read 386 times) previous topic - next topic

NFrank89

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

analog or digital, can either one write open?

PaulS

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.

Krodal

#2
Jan 15, 2013, 11:51 am Last Edit: Jan 15, 2013, 12:00 pm by Krodal Reason: 1
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: [Select]

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

GoForSmoke


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: [Select]

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
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

GoForSmoke


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.


Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

liudr


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.

Go Up