# Can we use two modules under single software serial port ?

**URL:** <https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929>\
**Category:** Programming\
**Created:** [March 5, 2021, 6:08pm UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929 "2021-03-05T18:08:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sundarraj238](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sundarraj238/32/551358_2.png) [@sundarraj238](https://forum.arduino.cc/u/sundarraj238)\
**Post date:** [March 5, 2021, 6:08pm UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929/1 "2021-03-05T18:08:27Z")

</div>

Greetings....  
I'm currently working on a project which is running out of pins in Arduino NANO.  
I have a question,  
Whether a single declared software serial ports be used to communicate between two different devices.

The first device is SIM800L GSM in which Arduino is going to only transmit commands.  
The second device is NEO6M GPS module in which the Arduino is going to only receive data.

Can softwareSerial serial1(9, 10); be used ?  
9 for NEO6M and 10 for SIM800L ?

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [March 5, 2021, 6:24pm UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929/2 "2021-03-05T18:24:20Z")

</div>

If the baudrates and other parameters for the two devices is the same, I see no reason why it would not work.

---

<div class="post-metadata">

**Author:** ![CrossRoads](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/crossroads/32/214033_2.png) [@CrossRoads](https://forum.arduino.cc/u/CrossRoads)\
**Post date:** [March 5, 2021, 6:24pm UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929/3 "2021-03-05T18:24:48Z")

</div>

"running out of pins in Arduino NANO"  
You are using the Ax pins as digital IO also? A0 to A5 = D14 to D19.  
A6, A7 are analog input only.

I don't see any reason why Tx and Rx couldn't go to two different devices electrically. Be sure to connect GNDs.  
If you are using two different libraries for those, that might complicate things.  
I think there is also a Timer associated with those pins, that also should be considered.

Baud rate - Software serial can only transmit, or only receive. If different baud rates are needed, I would leave it set for the receive side, then change to the Tx frequency, and then switch it back to the Rx frequency.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [March 5, 2021, 6:27pm UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929/4 "2021-03-05T18:27:12Z")

</div>

Yes that should work (with previous remarks) as long as you don’t rely on a library for the sim800 (and you’ll be blind to how the sim800 is answering your commands). TinyGPS++ only depends on you feeding it, so should be fine.

Just be careful that you can’t send and receive at the same time with software serial - so your gps will probably behave erratically when you are sending stuff out and you’ll miss some sentences.

Did you use pin 0 and 1 (Serial)?

---

<div class="post-metadata">

**Author:** ![sundarraj238](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sundarraj238/32/551358_2.png) [@sundarraj238](https://forum.arduino.cc/u/sundarraj238)\
**Post date:** [March 6, 2021, 4:15am UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929/5 "2021-03-06T04:15:33Z")

</div>

Thanks for replying.  
This is the first time I've using the Arduino forum for discussions.  
I've really used all of the digital pins form 0 to 13 and analog pins form A0 to A7 in Arduino NANO.  
For example I said I'm using (9, 10) for Rx and Tx.  
But you can suggest me a solution  
So that I'll swap my connected modules to another pins according.  
Right now only two digital pins are left  
Within that two I'm forced to use one as Tx to send commands with SIM800L and one as Rx to receive data form NEO6M.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![anon26818118](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon26818118](https://forum.arduino.cc/u/anon26818118)\
**Post date:** [March 6, 2021, 7:23am UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929/6 "2021-03-06T07:23:35Z")

</div>

it seems (to me) that you didnt pay the necessary attention to #2 and #3 above. Your problem is not on the pins but on the fact that with the softwareserial , some received messages will be lost if at the same time you are Txing.

So, in this case i suggest you put your tx at the end of the reception period. For example, if you receive every 1 sec, you start a timer (see "millis without delay") and arrange to Tx after about 900ms past start of reception. The remaining 100 ms are enough for tx a SIM800 command. Evaluate Rx/Tx ms ratio according to your period, number of characters rx/tx and baud rate.

---

<div class="post-metadata">

**Author:** ![sundarraj238](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sundarraj238/32/551358_2.png) [@sundarraj238](https://forum.arduino.cc/u/sundarraj238)\
**Post date:** [March 6, 2021, 12:54pm UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929/7 "2021-03-06T12:54:00Z")

</div>

Okay I understood your suggestions and I'm very thankful for that.  
If possible can you give me an example program code for that ?

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [March 6, 2021, 2:25pm UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929/8 "2021-03-06T14:25:18Z")

</div>

Did you connect a non serial device on pin 0 and 1?

If so - i would suggest you swap whatever is there for the 2 pins you wanted to share as Tx/Rx and use hardware Serial. This way you’ll have something more robust.

---

<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:** [July 4, 2021, 2:26pm UTC](https://forum.arduino.cc/t/can-we-use-two-modules-under-single-software-serial-port/698929/9 "2021-07-04T14:26:04Z")

</div>

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
