Arduino GSM Library Can't Tolerate Software Serial

Write the following line in any of the GSM examples and see for yourself.

#include <SoftwareSerial.h>

When I compile any GSM example while including SoftwareSerial using the Arduino Mega, the following error messages appear.

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

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

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\GSM\GSM3SoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

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

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\GSM\GSM3SoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

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

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\GSM\GSM3SoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

Using library GSM at version 1.0.6 in folder: C:\Program Files (x86)\Arduino\libraries\GSM 
Using library SoftwareSerial at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial 
exit status 1
Error compiling for board Arduino Mega or Mega 2560.

When I compile any GSM example while including SoftwareSerial using the Arduino UNO, the following error messages appear.

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

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

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\GSM\GSM3SoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

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

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\GSM\GSM3SoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

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

C:\Users\ABDULL~2\AppData\Local\Temp\arduino_build_684123\libraries\GSM\GSM3SoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

Using library GSM at version 1.0.6 in folder: C:\Program Files (x86)\Arduino\libraries\GSM 
Using library SoftwareSerial at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial 
exit status 1
Error compiling for board Arduino Uno.

Both responses are similar, just the vector numbers are different.

I have tried to find these vector definitions in various related .h and .cpp files but I could find them anywhere.

Is there any way I can use SoftwareSerial while using Arduino GSM Library?

I am using the ArduinoGSMShield and the Adafruit's Ultimate GPS shield on Arduino Mega. I think I can use the Mega's Serial1 and Serial2 for the GPS shield, but that may involve some hardware connections.

I am using Arduino 1.8.12 on Windows 8.1

From the Adafruit Ultimate GPS Logger Shield's documentation:

Soft Serial connection works on Uno/Duemilanove/Diecimila Arduinos as well as Leonardos. It does not work on Mega as the Mega does not have Soft Serial support on pins 7 & 8

From the SoftwareSerial library's reference page:

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).

So you are going to need to change the hardware connections of the shield anyway in order to use it with your Mega. You have the right idea about changing the connections of pins 7 and 8 to one of the unused hardware serial ports on the Mega. If you remove the GPS shield from the Mega, bend pins 7 and 8 at a right angle outward from the shield, then plug the shield back into the Mega, you should be able to use two female to male dupont jumper wires to connect the bend pins on the shield to the hardware serial pins on the Mega. Be aware that when you bend the pins, it weakens the metal and repeated bending can result in the pins eventually breaking off. You should be fine with bending them once though.


As for the issue of the GSM library blocking the use of the SoftwareSerial library in your sketch, although it is not relevant in this particular case, it certainly is unfortunate. Keep in mind that this library is very old and the Arduino GSM Shield has been retired for a long time. I'm certain Arduino's current developers would do a much better job designing this library if they wrote it today.

Thanks a lot pert. I will try to use one of the free hardware serial ports for the GPS shield and post the results. Also, I think bending the pins wouldn't be necessary. There is a dedicated header on the shield with Rx and Tx pins of the GPS module. I may be able to connect a male-female jumper from this connector to one of the hardware serial ports.

Adafruit Ultimate GPS Shield

pert:
GSM library blocking the use of the SoftwareSerial library in your sketch, although it is not relevant in this particular case,

It is relevant because the default way of communication in Adafruit's GPS library is SoftwareSerial. I had run the GSM and GPS shields separately on Mega with success and a big smile on my face but it started cracking apart when I tried to stich both codes together. But good thing is that Adafruit GPS library also has provision for hardware serial and a few other protocols.

pert:
Keep in mind that this library is very old and the Arduino GSM Shield has been retired for a long time.

Oh, I thought I bought a really "genuine piece" from an online shop.

perplexed_user:
Oh, I thought I bought a really "genuine piece" from an online shop.

It is possible. Arduino doesn't sell the GSM shield anymore, but there might still be some out there for sale. I've seen shops having inventory of long-retired genuine Arduino products before.