0

Writing to an INPUT pin?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Writing to an INPUT pin?

by dragonuv on Wed Apr 08, 2009 6:35 pm

I was exploring around the arduino interfacing at arduino.cc and in one sketch that communicates with the ps\2 mouse it has the following code:

Code: Select all | TOGGLE FULL SIZE
void gohi(int pin)
{
  pinMode(pin, INPUT);
  digitalWrite(pin, HIGH);
}


in one hand the pin is set to INPUT, but on the other hand it gives it a HIGH reading. how is it possible and why would someone do it?
dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

Re: Writing to an INPUT pin?

by unwiredben on Wed Apr 08, 2009 6:42 pm

Writing HIGH to a pin set as input enables the internal pull-up resistor on that pin. This helps when you have a signal that would otherwise tend to float and not consistently be read as high or low.

unwiredben
 
Posts: 75
Joined: Fri Dec 19, 2008 2:02 pm
Location: Brooklyn, NY

Re: Writing to an INPUT pin?

by dragonuv on Wed Apr 08, 2009 6:55 pm

what if the signal is inconsistent? (lets say the signal is going random between 5 to 0 volts), at what stage will there be a HIGH reading?

and what does writing LOW to a pin set as input do? enables the pull DOWN resistor?
dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

Re: Writing to an INPUT pin?

by trialex on Thu Apr 09, 2009 12:16 am

No there is no internal pull down resistor. Writing LOW to an input does nothing. If you want to pull-down an input you need to use an external resistor.

You should do some reading of the theory behind pull-up/pull down resistors, but they are also known as weak resistors - they are designed to be easily overcome by the external signal. As longs as your external signal provides more power to the input pin than the path through the internal pull-up, the microcontroller will correctly read the external signal. The internal resistors are quite large, which means that they provide only a small amount of current to the input pin when nothing is connected externally.

Have you read ladyada's tutorial on pull-up / pull-down resistors?
trialex
 
Posts: 189
Joined: Mon Apr 03, 2006 6:25 pm

Re: Writing to an INPUT pin?

by unwiredben on Thu Apr 09, 2009 12:27 am

Setting it to low just means that the signal floats. According to http://www.allaboutcircuits.com/vol_4/chpt_3/10.html, TTL levels are read as high when above 2V, low when below 0.8V, and indeterminate when there's no connection or it's between 0.8 and 2V.

unwiredben
 
Posts: 75
Joined: Fri Dec 19, 2008 2:02 pm
Location: Brooklyn, NY

Please be positive and constructive with your questions and comments.