# Problem interfacing with created Software Serial

**URL:** <https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875>\
**Category:** Programming\
**Created:** [September 17, 2013, 8:50pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875 "2013-09-17T20:50:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 17, 2013, 8:50pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/1 "2013-09-17T20:50:58Z")

</div>

I have an Arduino Mega 2560, and I'm trying to create a test for it to test it's Software Serial. It would be similar to the echo test, but instead of using serial monitor I'm trying to use 2 Software Serials I created.

Here is my code:

```cpp
#include <SoftwareSerial.h>
#define Tx1Pin 12
#define Rx1Pin 11
#define Tx2Pin 10
#define Rx2Pin 9
#define serial_baudrate 9600
SoftwareSerial serial1(Rx1Pin, Tx1Pin);
SoftwareSerial serial2(Rx2Pin, Tx2Pin);
int incomingByte = 0;
void setup(){
  pinMode(Rx1Pin, INPUT);
  digitalWrite(Tx1Pin, HIGH);
  pinMode(Tx1Pin, OUTPUT);
  pinMode(Rx1Pin, INPUT);
  digitalWrite(Tx2Pin, HIGH);
  pinMode(Tx2Pin, OUTPUT);
  Serial.begin(serial_baudrate);
  serial1.begin(serial_baudrate);
  serial2.begin(serial_baudrate);
  delay(1000);
}
void loop(){
  serial1.write("HelloWorld");
  delay(50);
  if (serial2.available() > 0) {
    incomingByte = serial2.read();
    Serial.println((char)incomingByte);
  }
  delay(50);
}

```

No matter what I do, the arduino always says that there is not bytes incoming. This is a brand new arduino mega, so that shouldn't be a problem. the wiring for it that I'm using is just a wire between pins 12 and 9, and a wire between 11 and 10. I've performed a regular echo test on the arduino and it passes just fine for regular serial monitor. The arduino is powered by the USB cord to my computer so that I can use serial monitor to check if the code is working. The code I put up there outputs nothing since it says that serial1 is never available. I've looked up other uses for software serial on the internet, and it seems like everyone else is doing the communication the same way my code should be doing it.

Can anyone tell me what I'm doing wrong here?

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [September 17, 2013, 8:55pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/2 "2013-09-17T20:55:54Z")

</div>

Perhaps you have hit one of the documented limitations:

> **[SoftwareSerial Library | Arduino Documentation](https://docs.arduino.cc/learn/built-in-libraries/software-serial)**
>
> The SoftwareSerial library allows serial communication on other digital pins of an Arduino board.

Limitations

The library has the following known limitations:

If using multiple software serial ports, only one can receive data at a time.

Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

Not all pins on the Leonardo support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 17, 2013, 10:12pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/3 "2013-09-17T22:12:05Z")

</div>

I think I saw something like that earlier. I changed the code and the wiring so that I am only using pins 10-13. This gives me the same result though. No print, and it always says that there is nothing available.

---

<div class="post-metadata">

**Author:** ![int2str](https://avatars.discourse-cdn.com/v4/letter/i/4da419/32.png) [@int2str](https://forum.arduino.cc/u/int2str)\
**Post date:** [September 17, 2013, 10:34pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/4 "2013-09-17T22:34:21Z")

</div>

You can try my new library and change "serial1" from SoftwareSerial to SoftwareSerialTX.  
[http://forum.arduino.cc/index.php?topic=188578.0](http://forum.arduino.cc/index.php?topic=188578.0)

That way you're not doubling up on the interrupt handlers.

Note: You have to use the baud rate constants (SoftwareSerialTX.BAUD\_9600) for the constructor.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 17, 2013, 11:14pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/5 "2013-09-17T23:14:25Z")

</div>

Thanks for the suggestion, I've seen NewSoftSerial, but not SoftSerialTX. I downloaded the zip file for the SoftSerialTX library and copied it into the Arduino Libraries. This is my new code to use the SoftSerialTX Library. I ran it with no errors, but it still results in not printing anything.  
Code:

```cpp
#include <SoftwareSerial.h>
#include <SoftwareSerialTX.h>
#define Tx1Pin 12
#define Rx1Pin 11
#define Tx2Pin 13
#define Rx2Pin 10
#define serial_baudrate 9600
SoftwareSerialTX serial1(SoftwareSerialTX::BAUD_9600, Tx1Pin);
SoftwareSerial serial2(Rx2Pin, Tx2Pin);
int incomingByte = 0;
void setup(){
  pinMode(Rx1Pin, INPUT);
  digitalWrite(Tx1Pin, HIGH);
  pinMode(Tx1Pin, OUTPUT);
  pinMode(Rx1Pin, INPUT);
  digitalWrite(Tx2Pin, HIGH);
  pinMode(Tx2Pin, OUTPUT);
  Serial.begin(serial_baudrate);
  serial2.begin(serial_baudrate);
  delay(1000);
}
void loop(){
  serial1.write("HelloWorld");
  delay(50);
  if (serial2.available() > 0) {
    incomingByte = serial2.read();
    Serial.println((char)incomingByte);
  }
  delay(50);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 18, 2013, 9:33am UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/6 "2013-09-18T09:33:52Z")

</div>

> No matter what I do, the arduino always says that there is not bytes incoming.

No mention of what is connected to the software serial instance's pins. Why not?

```arduino
  serial1.write("HelloWorld");

```

This makes the serial1 instance the active instance.

```arduino
  if (serial2.available() > 0) {
    incomingByte = serial2.read();

```

Nothing heard by the inactive instance. Gee, I wonder why. It isn't listening!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 18, 2013, 7:00pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/7 "2013-09-18T19:00:36Z")

</div>

In my original post it says that I just have one wire connected between pin 13 and pin 11, and another wire connected between pin 12 and pin 10. If you're saying that I need to insert

```cpp
serial2.listen();

```

before my if statement, then I'd tell you that I have already tried that. It results in the arduino still saying that there is no bytes available, even though serial2 is listening.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 18, 2013, 7:09pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/8 "2013-09-18T19:09:46Z")

</div>

> If you're saying that I need to insert...before my if statement, then I'd tell you that I have already tried that. It results in the arduino still saying that there is no bytes available, even though serial2 is listening.

But, does the data arrive while you are listening? Or, does loop() and, restart, and switch to the other instance because you write() using that instance?

Why are you using SoftwareSerial for a loop back test on a device with 4 hardware serial ports?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 18, 2013, 7:34pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/9 "2013-09-18T19:34:17Z")

</div>

So the serial2.listen should actually go before I start writing with serial1? That makes sense. I just tried it though, and it still didn't work.

I am using software serial because I am working on a project that uses a Micro Maestro 6-Channel USB Servo Controller that is controlled by the Arduino Mega. Currently I am able to send the Maestro commands to move a servo, and to set it's speed and acceleration. I am not able though to receive any data back from the Maestro though. I measured the signals from both the Arduino and the Maestro, so the only problem is that the arduino is not receiving the signal that the Maestro is sending. I'm using this artificial loop back test to ensure that my arduino is able to receive and process signals.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 18, 2013, 8:21pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/10 "2013-09-18T20:21:41Z")

</div>

> So the serial2.listen should actually go before I start writing with serial1?

No. You really can't use two instances of SoftwareSerial the way you are trying to. There is just no way.

> I'm using this artificial loop back test to ensure that my arduino is able to receive and process signals.

This is not an explanation of why you are not using two hardware serial ports or two software instances on different machines. Either would work. Two software serial instances on one machine will never work.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 8:21pm UTC](https://forum.arduino.cc/t/problem-interfacing-with-created-software-serial/183875/11 "2021-05-05T20:21:05Z")

</div>

Closed on May 5, 2021, 8:21pm UTC


