Hello i'm trying to build an arduino with a7 gsm gps geolocator that find coordinates and sending them with sms if i send it an sms first and i encountered some errors while compiling.
here is my code: (check update below first please).
//*************************************************************
#include <TinyGPS++.h>//include the library code
#include <SoftwareSerial.h>//include the library code
#include <GSM.h>// include the GSM library
//#include <AltSoftSerial.h>
//*************************************************************
void SendMsg();
void RecvMsg();
void displayInfo();
//*************************************************************
#define PINNUMBER ""// PIN Number for the SIM
TinyGPSPlus gps;// The TinyGPS++ object
GSM gsmAccess;// initialize the library instances
GSM_SMS sms;
SoftwareSerial ss(3, 4);// The serial connection to the GPS device
//AltSoftSerial sms(5, 6);// The serial connection to the GPS device
int sec,min,hour,day,month,year;
float lat,lng;
char PhoneNumber[20]="+306943444650";
boolean notConnected = true;
boolean waitingSMS = true;
//char c;
//*************************************************************
void setup()
{
Serial.begin(115200);
ss.begin(115200);
delay(200);
ss.println("AT+IPR=9600");
delay(800);
Serial.begin(9600);
ss.begin(9600);
delay(200);
Serial.println("Welcome to my Arduino project");
delay(200);
ss.println("AT+GPS=1");
Serial.println("Initializing");
delay(1000);
Serial.println(".");
delay(1000);
Serial.println(".");
ss.println("AT+GPSRD=1");
delay(1000);
Serial.println(".\n");
delay(1000);
if (millis() > 10000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
Serial.println("Operation started SUCCESSFULLY\n");
delay(1000);
Serial.println("GSM initialized");
while (lat == 0 && lng == 0)
{
displayInfo();
}
delay(200);
Serial.println("Waiting for messages");
}
//*************************************************************
void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
{
if (gps.encode(ss.read()))
RecvMsg;
waitingSMS = true;
}
return(0);
}
//*************************************************************
void RecvMsg()
{
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
while(waitingSMS)
{
if (sms.available())// If there are any SMSs available()
{
Serial.println("Message received from:");
sms.remoteNumber(PhoneNumber, 20);// Get remote number
Serial.println(PhoneNumber);
if (sms.peek() == "Location")// Any message with the keyword Location should extract coordinates
{
Serial.println("Valid code");
Serial.println("Extracting Coordinates");
displayInfo();
SendMsg;
waitingSMS = false;
}
else
{
Serial.println("Discarded SMS");
sms.flush();//Message disposal
}
/* // Read message bytes and print them
while (c = sms.read())
{
Serial.print(c);
}
Serial.println("\nEND OF MESSAGE");
// Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
}*/
delay(1000);
}
}
}
//*************************************************************
void SendMsg()
{
delay(1000);
ss.println("AT+CMGF=1"); //Sets the GSM Module in TEXT Mode
delay(1000); // Delay of 1 second
ss.println("AT+CMGS=\"+306943444650\"\r"); // Mobile number you want to text to
delay(1000);
//ss.println(displayInfo());
ss.println("Location");
ss.println(lat,6);
ss.println(",");
ss.println(lng,6);
ss.println("/n");
ss.println(" Date");
ss.println(day);
ss.println("/");
ss.println(month);
ss.println("/");
ss.println(year);
ss.println("\n");
ss.println("Time ");
ss.println(hour+2);
ss.println(":");
ss.println(min);
ss.println(":");
ss.println(sec);
delay(100);
ss.println((char)26);// ASCII code of CTRL+Z for saying the end of sms to the module
delay(1000);
ss.println("AT+CMGF=0"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1 second
}
//*************************************************************
void displayInfo()
{
ss.println("AT+CMGF=0"); //Sets the GSM Module in GPS Mode
delay(1000); // Delay of 1 second
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
lat = (gps.location.lat());
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
lng = (gps.location.lng());
}
else
{
Serial.print(F("INVALID"));
lng = lat = 0;
}
Serial.print(F(" Date/Time: "));
if (gps.date.isValid())
{
Serial.print(gps.date.day());
day = (gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.month());
month = (gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.year());
year = (gps.date.year());
}
else
{
Serial.print(F("INVALID"));
day = month = year = 0;
}
Serial.print(F(" "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour()+2);
hour = (gps.time.hour()+2);
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
min = (gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
sec = (gps.time.second());
}
else
{
Serial.print(F("INVALID"));
hour = min = sec = 0;
}
Serial.println();
//Serial.print(lat,6);
//Serial.print(",");
//Serial.print(lng,6);
}
//*************************************************************
and here is the error message:
C:\Users\maxfi\AppData\Local\Temp\arduino_build_315871\libraries\GSM\GSM3SoftSerial.cpp.o (symbol from plugin): In function `GSM3SoftSerial::spaceAvailable()':
(.text+0x0): multiple definition of `__vector_3'
C:\Users\maxfi\AppData\Local\Temp\arduino_build_315871\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\maxfi\AppData\Local\Temp\arduino_build_315871\libraries\GSM\GSM3SoftSerial.cpp.o (symbol from plugin): In function `GSM3SoftSerial::spaceAvailable()':
(.text+0x0): multiple definition of `__vector_4'
C:\Users\maxfi\AppData\Local\Temp\arduino_build_315871\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
C:\Users\maxfi\AppData\Local\Temp\arduino_build_315871\libraries\GSM\GSM3SoftSerial.cpp.o (symbol from plugin): In function `GSM3SoftSerial::spaceAvailable()':
(.text+0x0): multiple definition of `__vector_5'
C:\Users\maxfi\AppData\Local\Temp\arduino_build_315871\libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "GSM.h"
Used: C:\Program
Multiple libraries were found for "TinyGPS++.h"
Used: E:\Documents\Arduino\libraries\TinyGPSPlus-1.0.2b
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Program
Using library TinyGPSPlus-1.0.2b at version 1.0.2 in folder: E:\Documents\Arduino\libraries\TinyGPSPlus-1.0.2b
Using library SoftwareSerial at version 1.0 in folder: C:\Program Files
Using library GSM at version 1.0.6 in folder: C:\Program Files
exit status 1
Error compiling for board Arduino/Genuino Uno.
ps: The error happened when i used gsm library and the void RecvMsg() .
I'm really noob so i need help.
UPDATE: Replacing the SoftwareSerial library with AltSoftSerial fix this error and the code compiles succssfully.
Does this happen because SoftwareSerial and Gsm use the same interrupt pins ?