Go Down

Topic: Alternative use of pins (Read 941 times) previous topic - next topic

SimLego

I can't find any clear information at all on whether it is possible to use special pins like those for serial communication and analog input for "normal" digital I/O.

For example, on http://arduino.cc/en/Reference/serial it reads:
Quote
All Arduino boards have at least one serial port (also known as a UART or USART): Serial. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output.
That vaugely implies that maybe I can use those two pins for digital I/O if I don't need them for serial communication, if I dare to read the unwritten information between the lines.

Same goes with the analog input pins. It seems I can assign the as digital inputs, even though they are presented as analog, all I have to do is define their tasks in the sketch. It looks as if I even can make them digital outputs, in spite of the fact that they are labelled analog inputs!

But the information on alternative use of pins is hard to find, if there even is any out there(?)

Nick Gammon

http://www.gammon.com.au/uno

The analog pins can certainly be used as digital pins.

You can use the serial pins too except that they have pull-ups connected internally. It would be OK to use them as outputs, not quite as useful to use them as inputs.

Retroplayer

Nick, when you say they have internal pullups on them, couldn't that be disabled? Or does the arduino code keep re-enabling that (or are we talking about the 32u4 connected to them?) If serial is never invoked in your code, I don't understand why the pins would be pulled up. But, wouldn't simply setting them as inputs and writing zero to them disable the pullups?

Nick Gammon

I'm not sure about the TxD pin (pin D1) but the RxD pin (pin D0) would be kept high by the Atmega8U2 chip via a 1K series resistor, because the 8U2 is trying to send to the main processor what it is receiving from the USB port, which, if nothing, will be a HIGH state.

As a test I uploaded this sketch to my Uno:

Code: [Select]

void setup () { }
void loop () { }


I measured 5V on both D0 and D1, and 0.5V on D2 onwards.

Checking for current I got 5 mA on D0 which would be consistent with a 1K resistor. On D1, I got 0.15 mA which is consistent with a 33K resistor, which the 8U2 chip may well use (as an internal pull-up) to make sure it doesn't interpret high impedance data as random rubbish.

Neither of those can be changed by programming the Atmega328P chip because they are external to it.

Setting the pins to OUTPUT however would override the pull-ups. Then you could drive them LOW or HIGH at your leisure.

MichaelMeissner


Same goes with the analog input pins. It seems I can assign the as digital inputs, even though they are presented as analog, all I have to do is define their tasks in the sketch. It looks as if I even can make them digital outputs, in spite of the fact that they are labelled analog inputs!

On the Uno, all 6 of the analog input pins can be used for digital output.  However, on some of the non-official Arduino machines that are programmed with the Arduino IDE that have more analog input pins, those extra pins cannot be used for digital output.

Go Up