Arduino Nano two Softwareserials for Sim800l and GPS

Hey guys,

i am trying to connect a Sim800l and a GPS module to my Arduino. I am initialising the softwareserial in the setup-section but only the one who comes last, in the code, is working.

Is there a way to get them both running?

The Serialclass for the SIM800l is set in the Sim800l-library, so i didnt forgot it. Both modules are working in different sketches.

#include <Sim800l.h>

#include <TinyGPS++.h>

#include <SoftwareSerial.h>
Sim800l Sim800l;  //to declare the library

//GPS
#define RXD2 6
#define TXD2 5
#define GPS_BAUD 9600
TinyGPSPlus gps;
SoftwareSerial gpsSerial(RXD2,TXD2);

//SMS
String textSms,numberSms;
uint8_t index1;
bool error;

void setup() {
  gpsSerial.begin(9600);
  Serial.begin(19200); // only for debug the results . 
  Sim800l.begin(); // initializate the library. 
  //Sim800l.reset();
  //don't forget to catch the return of the function delAllSms! 
  //error=Sim800l.delAllSms(); //clean memory of sms;
  
  Serial.println("setup beendet");
}

void loop() {
  Serial.println("Lese Speicher");
  delay(100);
  textSms=Sim800l.readSms(1); //read the first sms
  
        
  if (textSms.indexOf("OK")!=-1) //first we need to know if the messege is correct. NOT an ERROR
  { 
    Serial.println("Speicher wird verlesen");
    delay(100);
    Serial.println(textSms);  
    Serial.println("Nachricht verlesen");
    if (textSms.indexOf("Test")!=-1){
        Serial.println("bestimme Position");
        
        while (gpsSerial.available() > 0) {
          gps.encode(gpsSerial.read());
        }
        if (gps.location.isUpdated()) {
          Serial.print("LAT: ");
          Serial.println(gps.location.lat(), 6);
          Serial.print("LONG: "); 
          Serial.println(gps.location.lng(), 6);
        }
        else {
          Serial.println("Positions nicht gefunden");
        }
    }
    Serial.println("leere Speicher");
    delay(5000);
    //Sim800l.delAllSms(); //do only if the message is not empty,in other case is not necesary
             //delete all sms..so when receive a new sms always will be in first position
  }
  
       
}

Apart from trivial tests I have yet to see 2 instances of SoftwareSerial working successfully on a classic Nano or any other Arduino

Please clarify exactly which Nano board you have as there are several different boards of that name

its a non-original, arduino nano with an ATmega328P similar to this one: Arduino Nano Amazon

Then you will not be able to use two instances of SoftwareSerial. The library does have a listen() function that allows it to listen on one of several interfaces but you will miss data from the interfaces not in use.

Consider using a board with multiple hardware serial interface such as the Mega

1 Like

Not really, Software Serial is blocking code and only one instance can run at a given time. @UKHeliBob gives you the best solution, use a device that has several hardware serial ports.

1 Like

ok thank you i upgrade than. I got some ESP8266, ESP32 and a arduino pro micro laying around . Thank you!

On the strength of that, some further rummaging might produce a spare LCD display that you could press into service for your output, thereby releasing hardware serial for the GPS. Doing it that way might even lend more point to the exercise

Since the GPS only needs serial Rx, its possible to use hardware Serial with receive being used for GPS and send being used for debug messages to the serial monitor. There does need to be a way to disconnect the GPS while uploading code.