Go Down

Topic: TX and RX pins Arduino Uno (Read 4225 times) previous topic - next topic

dicky96

Arduino Uno
Can I use Digital Pins 0 and 1 as normal digital inputs if I don't need to use these pins for serial comms (TX and RX) for my application?

pinMode (0, INPUT);
pinMode (1, INPUT);
pinState = (digitalRead,0);
.....


What is it that makes these pins TX/RX are they allocated this purpose only if I use the serial library?

It's just that I have run out of pins for this application but if I can use these two then all is good

Rich

PaulS

Quote
Can I use Digital Pins 0 and 1 as normal digital inputs if I don't need to use these pins for serial comms (TX and RX) for my application?

Yes, but...

Quote
It's just that I have run out of pins for this application but if I can use these two then all is good

You can, but...

The but is that there are resistors associated with these pins, to facilitate their use as serial pins, and these resistors can cause issues with some uses as input and output pins, depending on what the input or output is from or driving.

Try it and see.

Are you using all the analog pins? If not, they can be used as digital pins, too.

dicky96

No I'm not using the analog pins

So I can just set them with pinMode and use digitalRead same way as the digital pins?

gm1mfn

Yes. Use digital pin numbers 14-19 for pins A0-A5 respectively.

dicky96


PeterH


Yes. Use digital pin numbers 14-19 for pins A0-A5 respectively.


Better to use the defined constants A0 - A5 since they will map to the correct pins appropriate to the board you're on, rather than hard-coding the assumption that the board is a UNO.

Code: [Select]

pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);
// etc

Go Up