Go Down

Topic: Using only TX of SoftwareSerial, leaving RX pin free (Read 29592 times) previous topic - next topic

Hi everyone.

I'm using SparkFun's OpenLog, a microSD card data-logger to which you communicate through serial. The only connection needed is Arduino TX to OpenLog RX, because the OpenLog handles the rest.

I have run out of pins in the project I'm using, and have exactly one digital I/O pin left to use for the OpenLog. I'm using SoftwareSerial. However, when I declare an instance of SoftwareSerial, I need to give it 2 pins: RX and TX. I only need TX, and every other pin on my Arduino (Nano) is currently being used for output.

Will something go wrong if I declare SoftwareSerial with an RX pin that's actually being used elsewhere for output? Can I, instead, declare SoftwareSerial with a pin that doesn't exist - say, 100? Any other options?

Thanks for any advice!
Ideally, if anything were any good, it would be indescribable.
- Edward Gorey

Nick Gammon

I wouldn't use pin 100 or anything like that, because it tries to use that pin, eg. here:

Code: [Select]
void SoftwareSerial::setRX(uint8_t rx)
{
  pinMode(rx, INPUT);
  if (!_inverse_logic)
    digitalWrite(rx, HIGH);  // pullup for normal logic!
  _receivePin = rx;
  _receiveBitMask = digitalPinToBitMask(rx);
  uint8_t port = digitalPinToPort(rx);
  _receivePortRegister = portInputRegister(port);
}


They don't seem to have allowed for no Rx at all, so you might be better off taking the class, and making a "send-only" version by removing the references to the reading part. I'll take a stab at it, shouldn't take long.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

I adapted SoftwareSerial to only have a send function. Download library here:

http://gammon.com.au/Arduino/SendOnlySoftwareSerial.zip

Example of use:

Code: [Select]
#include <SendOnlySoftwareSerial.h>

SendOnlySoftwareSerial mySerial (3);  // Tx pin

void setup ()
  {
  mySerial.begin(115200);
  }

int i;

void loop ()
{
  mySerial.print ("test: ");
  mySerial.println (i++);
  delay (100);
}
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Thanks so much, that's brilliant, I appreciate it!
Ideally, if anything were any good, it would be indescribable.
- Edward Gorey

Fantastic! Thank you very much.

Glenndrives

You can set RX to 0.

Code: [Select]
SoftwareSerial Serial2 = SoftwareSerial(0, 4);    //!< RX is 0. Pin 4 is TX

This works because there is no pin 0.

Mushfiq
Check out my site for DIY information: http://inventige.com

Nick Gammon

Yes there is a pin 0. Take a look at your board. It's labelled Rx (and 0).
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics


meman


I adapted SoftwareSerial to only have a send function. Download library here:

http://gammon.com.au/Arduino/SendOnlySoftwareSerial.zip

Example of use:

Code: [Select]
#include <SendOnlySoftwareSerial.h>

SendOnlySoftwareSerial mySerial (3);  // Tx pin

void setup ()
  {
  mySerial.begin(115200);
  }

int i;

void loop ()
{
  mySerial.print ("test: ");
  mySerial.println (i++);
  delay (100);
}



in my case I want to release TX pin
how I can change the library in order to implement this method?
more info:
http://forum.arduino.cc/index.php?topic=227760.0

Nick Gammon

I adapted SoftwareSerial to only have a receive function. Download library here:

http://gammon.com.au/Arduino/ReceiveOnlySoftwareSerial.zip

Example of use:

Code: [Select]

#include <ReceiveOnlySoftwareSerial.h>

ReceiveOnlySoftwareSerial mySerial(10); // RX

void setup() 
{
  Serial.begin(115200);
  while (!Serial) { }  // wait for Serial to become available

  // set the data rate for the ReceiveOnlySoftwareSerial port
  mySerial.begin(9600);
}

void loop() // run over and over
{
  // echo from software serial to hardware serial
  if (mySerial.available())
    Serial.write(mySerial.read());
}


This could be handy for situations (like reading from a GPS) where you don't need to write, and thus you can save a few hundred bytes of program code.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up