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);
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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.