Can we use serial communication in arduino only for RX pin, so that I am free to use pin 1(TX) as digital I/O:
Serial.write('a');
pinMode(1,OUTPUT);
digitalWrite(1,LOW);
1 Answer 1
HardwareSerial takes over the Tx and Rx pins. However you can use SoftwareSerial.
Arduino forum user whiteglint143 made an adaptation of SoftwareSerial that does read-only.
http://gammon.com.au/Arduino/ReceiveOnlySoftwareSerial.zip
See Receive Only Software Serial - Arduino Forum
You can regain control over the TX or RX pins by unsetting the TXENn or RXENn bit in the UCSRnB register.
Like this?
const byte LED = 1;
void setup ()
{
Serial.begin (115200);
Serial.println ();
UCSR0B &= ~bit (TXEN0); // disable transmit
Serial.println ("Testing");
pinMode (LED, OUTPUT);
} // end of setup
void loop ()
{
digitalWrite (LED, HIGH);
delay (500);
digitalWrite (LED, LOW);
delay (500);
} // end of loop
Gerben's suggestion works, in a sense. The pin flashes, but rather disconcertingly, the Tx LED on the board also flashes, out of sync with pin 1. Clearly the signal is making its way to the ATmega16U2 chip, which then flashes the indicator LED. This may not be desirable if you have something connected to the serial port, as it may be interpreted as low-speed serial communications.
-
2You can regain control over the TX or RX pins by unsetting the TXENn or RXENn bit in the UCSRnB register.Gerben– Gerben09/13/2015 12:11:54Commented Sep 13, 2015 at 12:11
-
Nice, simple solution! Good idea.09/13/2015 20:50:35Commented Sep 13, 2015 at 20:50
-
See amended post, using that pin as a digital pin may have side-effects.09/13/2015 21:30:00Commented Sep 13, 2015 at 21:30
-
1Great finding. Though calling Serial.println, after disabling TX is kind of silly.Gerben– Gerben09/14/2015 12:24:56Commented Sep 14, 2015 at 12:24
-
1I hoped you wouldn't notice that. :P09/14/2015 20:33:04Commented Sep 14, 2015 at 20:33