2

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);
user3704293
4717 silver badges19 bronze badges
asked Sep 13, 2015 at 6:57

1 Answer 1

2

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.

answered Sep 13, 2015 at 7:33
5
  • 2
    You can regain control over the TX or RX pins by unsetting the TXENn or RXENn bit in the UCSRnB register. Commented Sep 13, 2015 at 12:11
  • Nice, simple solution! Good idea. Commented Sep 13, 2015 at 20:50
  • See amended post, using that pin as a digital pin may have side-effects. Commented Sep 13, 2015 at 21:30
  • 1
    Great finding. Though calling Serial.println, after disabling TX is kind of silly. Commented Sep 14, 2015 at 12:24
  • 1
    I hoped you wouldn't notice that. :P Commented Sep 14, 2015 at 20:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.