2 Rx & 2 Tx on arduino nano

Hello.
I want to use 2 modules with UART connectivity with Arduino nano
Arduino nano has Tx Rx on pins 1 and 2.
I wonder If it's possible to use and 2 other pins with library as Tx , Rx.

Any suggestions?
Thanks

Yes, it is Possible. :slight_smile:
Have a look at that code. It may help you. there are 2 serial ports. 1 usb serial port & the other is for reading the data from GPS.
Cheers.

#include "TinyGPS.h"
#include <SoftwareSerial.h>
TinyGPS gps; // create a TinyGPS object
SoftwareSerial nss(4, 5); // SoftwareSerial(rxPin, txPin // serial port for GPS Tx(4). // or connect other serial devices.

void setup()
{
  Serial.begin(115200); // PC<---> arduino 115200 baud
  nss.begin(9600); // GPS---> arduino at 9600 baud
}

void loop()
{
  while (nss.available()) // when data is available in serial buffer
  {
    int c = nss.read(); //Read the GPS serial port
    // Encode() each byte
    // Check for new position if encode() returns "True"
    if (gps.encode(c))
    {
      long lat, lon;  // variables for storing lat & lon data
      gps.get_position(&lat, &lon); // TinyGPS function for aquiring positional information
      float flon = lon; // copy the value in a float variable to get fractional value
      float flat = lat; //  
      flon = flon/1000000; // formatting the data
      flat = flat/1000000;  //      
      Serial.print(flat, 6); // print latitude to serial monitor
      if(flat>0) Serial.println("*N");
      else  Serial.println("*S");
      Serial.print(flon, 6); // print longitude to serial monitor
      if(flon>0) Serial.println("*E");
      else  Serial.println("*W");
      delay(500);
    }
  }
}

Thanks for your reply!:slight_smile:
Ok Great! I read that no more than two serial connections can be used at tha same time!
Should I use listen(); and available(); functions in order to read from 2 modules?

Thanks:)

In order to get things done while using two software serials you need to follow that algo

  1. begin ports
  2. listen port (any one at a time)
  3. if data available in serial buffer
    {
    // code
    }

Check it - http://arduino.cc/en/Tutorial/TwoPortReceive

Note that SoftwareSerial blocks with interrupts disabled during send operations. If you only use it to receive that wouldn't be a problem, but if ou also use it to send then it would inhibit the hardware Serial port while it was sending. Also note that it is much less accurate than the hardware serial at higher data rates, so don't plan to use it for any fast connections.

PeterH:
Note that SoftwareSerial blocks with interrupts disabled during send operations.

It means either print or write?

It means either print or write?

Since print() eventually calls write(), yes.