library conflicts

OK - I joined today and I’m trying to stitch two sketches together to use a GPS shield and a GSM shield in order to text me the arduino’s location. (I got each shield to do it’s bit independently in separate sketches (basically the example tutorials) and and am now trying to get them to repeat that from the one sketch) I’ve just taken the two examples and joined them up… They both use pins 2 and 3 for serial, so I set software serial to use pins 4 and 5 on the GPS. Both the shields came from Maplins and appear to use standard supported libraries, and it seems to be objecting to multiple definitions of “read()” which does not seem like the sort of name that ought to be in a library. The error is multiple definitions of __vector_3 and similar 4 and 5.
Both shields wanted pins 2 and 3 so I jumpered the GPS shield serial pins to UNO pins 4 and 5
Not sure where to start (sorry!) so any advice welcome! Thank you!
Alan

When I try and compile I get:

arduino-builder/arduino-builder -compile -core-api-version 10611 -build-path /tmp/915960688 -hardware arduino-builder/hardware -hardware arduino-builder/packages/cores -tools arduino-builder/tools -tools arduino-builder/packages/tools -built-in-libraries arduino-builder/latest -libraries /tmp/763214613/pinned -libraries /tmp/763214613/custom -fqbn arduino:avr:uno -build-cache /tmp -verbose=false /tmp/763214613/sketch_test_gps_with_sms
Multiple libraries were found for “SoftwareSerial.h”
Used: /home/admin/builder/arduino-builder/packages/cores/arduino/avr/libraries/SoftwareSerial
Not used: /home/admin/builder/arduino-builder/latest/Printoo_Library-1.0.2
/tmp/915960688/libraries/SoftwareSerial/SoftwareSerial.cpp.o (symbol from plugin): In function SoftwareSerial::read()': (.text+0x0): multiple definition of __vector_3’
/tmp/915960688/libraries/GSM-1.0.5/GSM3SoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
/tmp/915960688/libraries/SoftwareSerial/SoftwareSerial.cpp.o (symbol from plugin): In function SoftwareSerial::read()': (.text+0x0): multiple definition of __vector_5’
/tmp/915960688/libraries/GSM-1.0.5/GSM3SoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
/tmp/915960688/libraries/SoftwareSerial/SoftwareSerial.cpp.o (symbol from plugin): In function SoftwareSerial::read()': (.text+0x0): multiple definition of __vector_4’
/tmp/915960688/libraries/GSM-1.0.5/GSM3SoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1

from trying to verify :

// Example 19.6
/*
SMS sender

This sketch, for the Arduino GSM shield,sends an SMS message
you enter in the serial monitor. Connect your Arduino with the
GSM shield and SIM card, open the serial monitor, and wait for
the “READY” message to appear in the monitor. Next, type a
message to send and press “return”. Make sure the serial
monitor is set to send a newline when you press return.

Make sure you switch POWER ON ON THE SHIE

Circuit:

  • GSM shield
  • SIM card that can send SMS

created 25 Feb 2012
by Tom Igoe

This example is in the public domain.

*/

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

#define PINNUMBER “”

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

#include <SD.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>
SoftwareSerial shield(4,5); //configure software serial port to MATCH JUMPERS(default is 2,3)

SoftwareSerial smsshield(2,3); //configure software serial port to MATCH JUMPERS(default is 2,3)

// Create an instance of the TinyGPS object
TinyGPS gps;

void setup()
{
pinMode(10, OUTPUT);
shield.begin(9600);
smsshield.begin(9600);
Serial.begin(9600);
// check that the microSD card exists and can be used v
if (!SD.begin(10)) {
Serial.println(“Card failed, or not present”);
// stop the sketch
return;
}
Serial.println(“SD card is ready”);
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() == GSM_READY) {
notConnected = false;
} else {
Serial.println(“Not connected”);
delay(1000);
}
}

Serial.println(“GSM initialized”);

}

void getgps(TinyGPS &gps)
{
float latitude, longitude;
int year;
byte month, day, hour, minute, second, hundredths;

//decode and display position data
gps.f_get_position(&latitude, &longitude);
File dataFile = SD.open(“DATA.TXT”, FILE_WRITE);
// if the file is ready, write to it
if (dataFile)
{
dataFile.print("Lat: “);
dataFile.print(latitude,5);
dataFile.print(” ");
dataFile.print("Long: “);
dataFile.print(longitude,5);
dataFile.print(” “);
Serial.print(“Lat “);
Serial.print(latitude,5);
Serial.print(“Long “);
Serial.println(longitude,5);
// decode and display time data
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
// correct for your time zone as in Project #45
hour=hour+1;
if (hour>23)
{
hour=hour-24;
}
if (hour<10)
{
dataFile.print(“0”);
}
dataFile.print(hour, DEC);
dataFile.print(”:”);
if (minute<10)
{
dataFile.print(“0”);
}
dataFile.print(minute, DEC);
dataFile.print(”:”);
if (second<10)
{
dataFile.print(“0”);
}
dataFile.print(second, DEC);
dataFile.print(” ");
dataFile.print(gps.f_speed_kmph());
dataFile.println(“km/h”);
dataFile.close(); // this is mandatory
delay(10000); // record a measurement about every 10 seconds
}
}

void loop()
{

// get the location
shield.listen();

byte a;
if ( shield.available() > 0 ) // if there is data coming into the serial line
{
a = shield.read(); // get the byte of data
if(gps.encode(a)) // if there is valid GPS data…
{
getgps(gps); // grab the data and display it on the LCD
}
}

// now do the text
smsshield.listen();

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 = ‘\0’;

  • Serial.flush();*
  • return 0;*
  • }*
  • if (inChar != ‘\r’) {*
    _ result = inChar;_
    * i++;*
    * }*
    * }*
    * }*
    }

You have two different versions of SoftwareSerial library, they use the same interrupt vectors and are thus giving the linker a fit.

Temporarily remove/rename one of the library versions?

Thanks MarkT As I said - I joined today so am feeling my way round a bit - I am using a supported GSM library and including a core(?) SoftwareSerial library - how do I go about editing what these include??! Can I easilly remake these? where do I find the source? I was thinking these would be safe to combine... Sorry to be a bit ignorant... Alan

OK - been looking to see how I can access these libraries in order to make changes and cannot see how to do this, but I do see that these are both listed as core (ie GSM and SoftwareSerial) - surely these do not conflict with each other?

awherbert: OK - been looking to see how I can access these libraries in order to make changes and cannot see how to do this, but I do see that these are both listed as core (ie GSM and SoftwareSerial) - surely these do not conflict with each other?

But they do. The GSM library has its own version of SoftwareSerial.cpp called GSM3Serial.cpp. Even if you got rid of one, the SoftwareSerial library can't deal with input from multiple ports at the same time. You have a few good choices: A: Switch from UNO to Leonardo and put one of the devices on Serial1. B: Switch from UNO to MEGA 2560 and put the devices on Serial1, Serial2, or Serial3. C: Switch to a GSM shield that incorporates GPS so you don't need a third serial port.

Ahh... I see GSM3softSerial is needed to overcome issues with softwareSerial, but introduces issues of its own (and restricted to using pins 2 and 3) so I would end up with a major project I guess... As you suggest it seems much easier, and not so expensive, to buy a mega with more hardware serial ports! More straightforward to go that way up the learning curve! :) Thanks for your sensible advice! Alan