Combining Arduino GSM with serial LCD

I am working on a project that integrate a serial LCD and Arduino GSM shield, but the file can not compile. I keep getting this error? How can I solve the issue ?

https://www.zeroohm.com/lcd-serial-16x2-white-on-black-5v/?search=serial%2520LCd

Each program works individually but when combined, I get the error.

Arduino: 1.6.4 (Mac OS X), Board: "Arduino Uno"

GSM/GSM3SoftSerial.cpp.o: In function `__vector_3':
Desktop/Arduino.app/Contents/Java/libraries/GSM/src/GSM3SoftSerial.cpp:499: multiple definition of `__vector_3'
SoftwareSerial/SoftwareSerial.cpp.o:/Users/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:227: first defined here
GSM/GSM3SoftSerial.cpp.o: In function `GSM3SoftSerial::spaceAvailable()':
Desktop/Arduino.app/Contents/Java/libraries/GSM/src/GSM3SoftSerial.cpp:487: multiple definition of `__vector_4'
SoftwareSerial/SoftwareSerial.cpp.o:/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:392: first defined here
GSM/GSM3SoftSerial.cpp.o: In function `GSM3SoftSerial::spaceAvailable()':
/Users/Desktop/Arduino.app/Contents/Java/libraries/GSM/src/GSM3SoftSerial.cpp:487: multiple definition of `__vector_5'
SoftwareSerial/SoftwareSerial.cpp.o:/Users/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:392: first defined here
collect2: error: ld returned 1 exit status
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
/code]

how do you drive your LCD? with a software serial as well?

Yes, as I am using a serial LCD.

Then you have a conflict of same interrupts being used by two libraries (GSM3SoftSerial and SoftwareSerial) - any chance you can move your LCD to a/the hardware Serial ? (As you are on a UNO it means loosing your debug capability to the console using USB, if you move to a mega you have plenty to choose from)

You might want also to consider testing with AltSoftSerial Library instead of SoftwareSerial or see “YASS” in Robin’s post

If I use mega, how can I change the interrupt pins to remove the conflict ?

FutureEngineer:
If I use mega, how can I change the interrupt pins to remove the conflict ?

the interrupts are used by the software emulation of the Serial Port. so if you use a mega and connect your LCD to a hardware port then there is no longer a need for the interruptions; just remove the Software Serial library from your code and use Serial2 for example instead of your instance of SoftwareSerial to discuss with the LCD

What do you mean by serial2 ? The code is the combination of GSM send SMS and serial LCD program, how to modify it to remove the conflict ?

// Include the GSM library
#include <GSM.h>

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;

/////////////// Serial LCD
#include <SoftwareSerial.h>
SoftwareSerial mySerial(22,12);   /////first one doesnt matter 

void setup()
{
  
  ////////////////// Serial LCD
   mySerial.begin(9600); 
  delay(500); 
  
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("SMS Messages Sender");

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
}

void loop()
{
  
  mySerial.write(254); 
  mySerial.write(128);
  mySerial.write("                "); // clear display
  mySerial.write("                ");

  mySerial.write(254); // move cursor to beginning of first line
  mySerial.write(128);
 
  //mySerial.print(x);
    mySerial.write("welcome"); 

  while(1); // wait forever
  
  

  Serial.print("Enter a mobile number: ");
  char remoteNum[20];  // telephone number to send sms
  readSerial(remoteNum);
  Serial.println(remoteNum);

  // sms text
  Serial.print("Now, enter SMS content: ");
  char txtMsg[200];
  readSerial(txtMsg);
  Serial.println("SENDING");
  Serial.println();
  Serial.println("Message:");
  Serial.println(txtMsg);

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");
}

/*
  Read input serial
 */
int readSerial(char result[])
{
  int i = 0;
  while (1)
  {
    while (Serial.available() > 0)
    {
      char inChar = Serial.read();
      if (inChar == '\n')
      {
        result[i] = '\0';
        Serial.flush();
        return 0;
      }
      if (inChar != '\r')
      {
        result[i] = inChar;
        i++;
      }
    }
  }
}/code]

if you have an Arduino Mega, it has 4 hardware Serial Ports used to receive (RX) and transmit (TX) TTL serial data

Serial: 0 (RX) and 1 (TX) → this one is connected to your USB cable and the Arduino Console
Serial1: 19 (RX) and 18 (TX)
Serial2: 17 (RX) and 16 (TX)
Serial3: 15 (RX) and 14 (TX)

Give this a try

I’ve taken arbitrarily Serial2 so connect pin 17 to the Tx of your LCD and pin 16 to the Rx of your LCD - assuming of course your LCD’s Serial is 5 volt (I replaced all the mySerial stuff in your code directly with Serial2 and got rid of the SoftwareSerial library)

You need to double check that those pins are not used by your GSM shield otherwise use Serial1 or Serial3 hopefully one of those will have pins unused by your GSM shield

// Include the GSM library
#include <GSM.h>

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;

// Serial LCD is connected on Serial2. pins are 17 (RX --> Tx of LCD) and 16 (TX --> Rx of LCD); 


void setup()
{

  ////////////////// Serial LCD
  Serial2.begin(9600);
  delay(500);

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("SMS Messages Sender");

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
}

void loop()
{

  Serial2.write(254);
  Serial2.write(128);
  Serial2.write("                "); // clear display
  Serial2.write("                ");

  Serial2.write(254); // move cursor to beginning of first line
  Serial2.write(128);

  //Serial2.print(x);
  Serial2.write("welcome");

  while (1); // wait forever



  Serial.print("Enter a mobile number: ");
  char remoteNum[20];  // telephone number to send sms
  readSerial(remoteNum);
  Serial.println(remoteNum);

  // sms text
  Serial.print("Now, enter SMS content: ");
  char txtMsg[200];
  readSerial(txtMsg);
  Serial.println("SENDING");
  Serial.println();
  Serial.println("Message:");
  Serial.println(txtMsg);

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");
}

/*
  Read input serial
*/
int readSerial(char result[])
{
  int i = 0;
  while (1)
  {
    while (Serial.available() > 0)
    {
      char inChar = Serial.read();
      if (inChar == '\n')
      {
        result[i] = '\0';
        Serial.flush();
        return 0;
      }
      if (inChar != '\r')
      {
        result[i] = inChar;
        i++;
      }
    }
  }
}

I kept the [color=red]while (1); // wait forever[/color] in the middle of the loop() which is obviously a bad idea… i guess you have that only to see the “welcome” message because you will not go further than this…