Different Serial port on Arduino Uo

Hi Everyone.

I am using the GPS Module (NEO-6mUblox) and GSM Module (SIM800L) simultaneously with Arduino UNO.
I am using the ports number 3 and 4 for GPS module and 10 and 11 for SIM800L to communicate with them. I have a problem for listening to both of them.
In fact I want to get the position from GPS module always and also receive/send SMS via SIM800L.

A Sample of Code is as follows:

if (gps.available() > 0){ //Listening to the GPS Module
    while(sim.available()){ //Listening o the SIM800L
      S = sim.readString();
      //if(count==64) break;
      Serial.println(S);
      S=S.substring(2);
      Serial.print("S = ");
      Serial.println(S.substring(0,4));
    if(S.startsWith("+CMGF=")){
      int EDate = S.lastIndexOf('"');
      int SDate = S.lastIndexOf('"', EDate - 1);
      int SNum = S.indexOf(',');
      int ENum = S.indexOf(',', SNum + 1);
      int EMessage = S.lastIndexOf('\n');
      EMessage = S.lastIndexOf('\n', EMessage-1);
      //Serial.print("N = ");
      //Serial.println(EMessage);
      Serial.println(S.substring(SDate+1, EDate));
      Serial.println(S.substring(SNum+2, ENum-1));
      String Number = S.substring(SNum+2, ENum-1);
      Serial.println(S.substring(EDate+3,EMessage-2));
      String Message = S.substring(EDate+3,EMessage-2);
      //Serial.println(Message.length());
      if(Number.equals("+989127360392")){
        Decode_SMS(Message);
      }
    }
    }
gps.encode(ss.read());
    if (gps.location.isUpdated()){
      Serial.println("GPS Data----------------");
      // Year (2000+) (u16)
      Serial.print("Year = "); 
      Serial.println(gps.date.year()); 
      // Month (1-12) (u8)
      Serial.print("Month = "); 
      Serial.println(gps.date.month()); 
      // Day (1-31) (u8)
      Serial.print("Day = "); 
      Serial.println(gps.date.day());
      // Raw time in HHMMSS format (u32)
      Serial.print("Raw time in HHMMSSCC = "); 
      Serial.println(gps.time.value()); 

      // Hour (0-23) (u8)
      Serial.print("Hour = "); 
      Serial.println(gps.time.hour()); 
      // Minute (0-59) (u8)
      Serial.print("Minute = "); 
      Serial.println(gps.time.minute()); 
      // Second (0-59) (u8)
      Serial.print("Second = "); 
      Serial.println(gps.time.second()); 
      // Latitude in degrees (double)
      My_LAT=gps.location.lat();
      Serial.print("Latitude= "); 
      //Serial.print(gps.location.lat(), 6);      
      Serial.print(My_LAT, 6);
      // Longitude in degrees (double)
      Serial.print(" Longitude= "); 
      //Serial.println(gps.location.lng(), 6); 
      My_LONG=gps.location.lng();
      Serial.print(My_LONG, 6);
  }
}

Thanks in advance
Mahdiyar

You could try using AltSoftSerial or NeoSWSerial for one of the devices (in place of the standard SoftwareSerial). But, realistically you should be using a Mega which has 3 spare HardwareSerial ports.

…R

I am using the GPS Module (NEO-6mUblox) and GSM Module (SIM800L) simultaneously with Arduino UNO.
I am using the ports number 3 and 4 for GPS module and 10 and 11 for SIM800L to communicate with them. I have a problem for listening to both of them.

Get a Mega2560 or one of the new MKR series Arduinos as they have several hardware serial interfaces available. SoftwareSerial allows only for one instance to be listening. Newer versions of SoftwareSerial probably have conflicts with AltSoftSerial and NeoSWSerial as they might use the same hardware.

Robin2:
You could try using AltSoftSerial or NeoSWSerial for one of the devices (in place of the standard SoftwareSerial). But, realistically you should be using a Mega which has 3 spare HardwareSerial ports.

…R

Thank you for your reply. I’ve tried NeoSWSerial. When I compile the code, it returns the following Error.
Error compiling for board Arduino/Genuino Uno.
Of course, I’ve just include the library as follows:
#include <NeoSWSerial.h>

Arduino: 1.8.9 (Windows 7), Board: "Arduino/Genuino Uno"

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino: In function 'void loop()':

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:148:74: warning: narrowing conversion of '(double)PLO1' from 'double' to 'int' inside { } [-Wnarrowing]

       Point polygon1[] = {{PLO1,PLA1},{PLO2,PLA2},{PLO3,PLA3},{PLO4,PLA4}};

                                                                          ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:148:74: warning: narrowing conversion of '(double)PLA1' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:148:74: warning: narrowing conversion of '(double)PLO2' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:148:74: warning: narrowing conversion of '(double)PLA2' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:148:74: warning: narrowing conversion of '(double)PLO3' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:148:74: warning: narrowing conversion of '(double)PLA3' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:148:74: warning: narrowing conversion of '(double)PLO4' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:148:74: warning: narrowing conversion of '(double)PLA4' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:150:29: warning: narrowing conversion of 'LONG1' from 'double' to 'int' inside { } [-Wnarrowing]

       Point p = {LONG1, LAT1};

                             ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:150:29: warning: narrowing conversion of 'LAT1' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:161:11: warning: narrowing conversion of 'LONG1' from 'double' to 'int' inside { } [-Wnarrowing]

         p = {LONG1, LAT1};

           ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:161:11: warning: narrowing conversion of 'LAT1' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:170:11: warning: narrowing conversion of 'LONG2' from 'double' to 'int' inside { } [-Wnarrowing]

         p = {LONG2, LAT2};

           ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:170:11: warning: narrowing conversion of 'LAT2' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:179:11: warning: narrowing conversion of 'LONG3' from 'double' to 'int' inside { } [-Wnarrowing]

         p = {LONG3, LAT3};

           ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:179:11: warning: narrowing conversion of 'LAT3' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:188:11: warning: narrowing conversion of 'LONG4' from 'double' to 'int' inside { } [-Wnarrowing]

         p = {LONG4, LAT4};

           ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:188:11: warning: narrowing conversion of 'LAT4' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:197:11: warning: narrowing conversion of 'LONG5' from 'double' to 'int' inside { } [-Wnarrowing]

         p = {LONG5, LAT5};

           ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:197:11: warning: narrowing conversion of 'LAT5' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:206:11: warning: narrowing conversion of 'LONG6' from 'double' to 'int' inside { } [-Wnarrowing]

         p = {LONG6, LAT6};

           ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:206:11: warning: narrowing conversion of 'LAT6' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:215:11: warning: narrowing conversion of 'LONG7' from 'double' to 'int' inside { } [-Wnarrowing]

         p = {LONG7, LAT7};

           ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:215:11: warning: narrowing conversion of 'LAT7' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:224:11: warning: narrowing conversion of 'LONG8' from 'double' to 'int' inside { } [-Wnarrowing]

         p = {LONG8, LAT8};

           ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:224:11: warning: narrowing conversion of 'LAT8' from 'double' to 'int' inside { } [-Wnarrowing]

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino: In function 'void clearBufferArray()':

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:261:16: warning: converting to non-pointer type 'unsigned char' from NULL [-Wconversion-null]

     _buffer1[i]=NULL;

                ^

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino: In function 'String _readSerial()':

D:\Software_Projects\Arduino\SafeControl\SafeControl.ino:325:1: warning: control reaches end of non-void function [-Wreturn-type]

 }

 ^

libraries\NeoSWSerial\NeoSWSerial.cpp.o (symbol from plugin): In function `NeoSWSerial::read()':

(.text+0x0): multiple definition of `__vector_3'

libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\NeoSWSerial\NeoSWSerial.cpp.o (symbol from plugin): In function `NeoSWSerial::read()':

(.text+0x0): multiple definition of `__vector_4'

libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\NeoSWSerial\NeoSWSerial.cpp.o (symbol from plugin): In function `NeoSWSerial::read()':

(.text+0x0): multiple definition of `__vector_5'

libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please post the full code that produced the error

multiple definition of `__vector_5'

That usually means two pieces of code are trying to use the same interrupt.

Does your program work when you use NeoSWSerial on one port and do not use SoftwareSerial?

...R

Robin2:
That usually means two pieces of code are trying to use the same interrupt.

Does your program work when you use NeoSWSerial on one port and do not use SoftwareSerial?

...R

Yes, it works. I mean it does not return error for compiling but the issue still exist and it does not listen to both serial ports. I define GPS module with SoftwareSerial and SIM800L with NeoSWSerial.

I have never used NeoSWSerial. Maybe you could use it for both devices?

The Arduino system is great for learning-by-doing

...R

You can run two instances of softwareserial, but not at the same time. You have to keep turning them on\off as they cannot both be active at the same time.

Running softwareserial and NeoSWSerial wont help, they compete at compile time for the same interrupt vector, hence the vector5 error. There is a way arround that error, but you still wont be able to run softwareserial and NeoSWserial at the same time.

Far far easier to use a Arduino thats up to the job, with multiple hardware serial ports.

srnet:
You can run two instances of softwareserial, but not at the same time. You have to keep turning them on\off as they cannot both be active at the same time.

Running softwareserial and NeoSWSerial wont help, they compete at compile time for the same interrupt vector, hence the vector5 error. There is a way arround that error, but you still wont be able to run softwareserial and NeoSWserial at the same time.

Far far easier to use a Arduino thats up to the job, with multiple hardware serial ports.

srnet:
You can run two instances of softwareserial, but not at the same time. You have to keep turning them on\off as they cannot both be active at the same time.

Running softwareserial and NeoSWSerial wont help, they compete at compile time for the same interrupt vector, hence the vector5 error. There is a way arround that error, but you still wont be able to run softwareserial and NeoSWserial at the same time.

Far far easier to use a Arduino thats up to the job, with multiple hardware serial ports.

Thank you for your reply.
The question is that if a SMS be sent to SIM800L during the time that is turn off would I miss that? Or I can get it as soon as I turn it on?

Mahdiyar:
The question is that if a SMS be sent to SIM800L during the time that is turn off would I miss that? Or I can get it as soon as I turn it on?

If a serial device sends data while SoftwareSerial (or NeoSwSerial) is not listening the data will be lost. In fact that is also true of HardwareSerial, but, happily it is always listening - at least up to the point (after 64 characters) where the Serial Input buffer overflows.

I think it's time to bite the bullet and get a Mega.

...R

Robin2:
If a serial device sends data while SoftwareSerial (or NeoSwSerial) is not listening the data will be lost. In fact that is also true of HardwareSerial, but, happily it is always listening - at least up to the point (after 64 characters) where the Serial Input buffer overflows.

I think it’s time to bite the bullet and get a Mega.

…R

Thank you I get the point.