1

I have this code:

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

#include <GSM.h>

#define PINNUMBER ""  // Opt from user
#define GPS_RX_PIN 2
#define GPS_TX_PIN 3
#define WHITE 0x7  //For LCD library

//Objects initialization
GSM gsmAccess;
GSM_SMS sms;

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

TinyGPSPlus gps;
SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN);

// Chars and strings for gps values
char clat[10 + 20 + 1] = "Latitude/Longitude: ";
char clng[10 + 1];
String string1, string2, finalstr;


const int xpin = A0;                  // X-axis of the accelerometer
const int ypin = A1;                  // Y-axis
const int zpin = A2;                  // Z-axis (only on 3-axis models)

float convX = 0.0, convY = 0.0, convZ = 0.0;
int sampleDelay = 20;

char remoteNumber[20] = "306978666866"; // Opt from user

uint8_t i = 0;

void setup()
{
  Serial.begin(9600); //GSM
  ss.begin(4800);     //gps

  analogReference(EXTERNAL); // For external analog reference of ADXL335
  pinMode(xpin, INPUT);
  pinMode(ypin, INPUT);
  pinMode(zpin, INPUT);

  // Set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.setBacklight(WHITE);
  lcd.setCursor(0, 0);

  // GSM connection state
  boolean notConnected = true;

  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      lcd.print("Not connected");
      delay(1000);
    }
  }
  lcd.print("GSM initialized");

  delay(2000);
  lcd.print("SELECT=Emergency");
}

void loop()
{
  bool uniFlag = false;
  int x = analogRead(xpin);
  delay(1); // Add a small delay between pin readings. I read that you should
            // do this but haven't tested the importance.

  int y = analogRead(ypin);
  delay(1);

  int z = analogRead(zpin);

  // zero_G is the reading we expect from the sensor when it detects
  // no acceleration. Subtract this value from the sensor reading to
  // get a shifted sensor reading.
  float zero_G = 502.0;

  // 'scale' is the number of units we expect the sensor reading to
  // change when the acceleration along an axis changes by 1G.
  // Divide the shifted sensor reading by scale to get acceleration in Gs.
  //   610 (1g) - 502 (0g) = 108
  float scale = 108;

  //value (g) = (measurement - 502)/ 108
  convX = ((float)x - zero_G)/scale;
  convY = ((float)y - zero_G)/scale;
  convZ = ((float)z - zero_G)/scale;

  delay(sampleDelay);

  if (convX > 2 || convX < -2 || convY > 2 || convY < -2)
    uniFlag = true;

  uint8_t buttons = lcd.readButtons();

  if (buttons) {
    if (buttons & BUTTON_SELECT) {
      uniFlag = true;}
  }

  if (uniFlag == true)
  {
    bool isGpsLocationValid = false;
    do
    {
      while (ss.available()>0)
      {
        char c = byte(ss.read());
        if (gps.encode(c))
        {
          if (gps.location.isValid())
          {
            dtostrf(gps.location.lat(), 10, 6, clat+20);
            dtostrf(gps.location.lng(), 10, 6, clng);
            isGpsLocationValid = true;
            string1 = String(clat);
            string2 = String(clng);
            finalstr = string1 + string2;
          }
        }
      }
    } while (isGpsLocationValid == false);
  }
  sendSMS(finalstr);
}

void sendSMS(String thisString)
{
  sms.beginSMS(remoteNumber);
  sms.print(thisString);
  sms.endSMS();
  lcd.setCursor(0, 0);
  lcd.print("Message sent!");
  delay(10000); //for multiple bumps
}

When I try to compile it I get these errors:

GSM\GSM3SoftSerial.cpp.o: In function `__vector_5':
C:\Program Files (x86)\Arduino\libraries\GSM/GSM3SoftSerial.cpp:525: multiple definition of `__vector_5'
SoftwareSerial\SoftwareSerial.cpp.o:C:\Program Files (x86)\Arduino\libraries\SoftwareSerial/SoftwareSerial.cpp:319: first defined here
GSM\GSM3SoftSerial.cpp.o: In function `__vector_4':
C:\Program Files (x86)\Arduino\libraries\GSM/GSM3SoftSerial.cpp:518: multiple definition of `__vector_4'
SoftwareSerial\SoftwareSerial.cpp.o:C:\Program Files (x86)\Arduino\libraries\SoftwareSerial/SoftwareSerial.cpp:312: first defined here
GSM\GSM3SoftSerial.cpp.o: In function `__vector_3':
C:\Program Files (x86)\Arduino\libraries\GSM/GSM3SoftSerial.cpp:511: multiple definition of `__vector_3'
SoftwareSerial\SoftwareSerial.cpp.o:C:\Program Files (x86)\Arduino\libraries\SoftwareSerial/SoftwareSerial.cpp:305: first defined here

What is going on? Is it that GSM.h declares SoftwareSerial inside? Are there any solutions?

This is the first time I get these kinds of compilation errors and have no idea what is going on or how to fix it.

3
  • 1
    Welcome to Arduino SE! Is it that GSM.h declares SoftwareSerial inside? You could've tried that before posting. It seems as that's the problem. I'm closing this as a duplicate of the question listed, in the time being as the errors are near identical, but if it's not, feel free to ping me with @ and my username or to flag this. Thanks! Commented Jun 24, 2014 at 20:58
  • No problem! Glad you got it solved. Commented Jun 25, 2014 at 0:18
  • the code utilizes interrupt 3/4/5 (check your datasheet to see what they are) that are already being utilized by other parts of your code. Commented Dec 2, 2017 at 13:08

2 Answers 2

3

Both SoftwareSerial and GSM are trying to declare the same interrupt vectors. You'll have to drop one of the libraries, find a replacement or change your code to omit one of the libraries. This is the disadvantage of using high level libraries.

Some Arduino's (Arduino Mega) have a microcontroller that supports more than one hardware serial channel, you may want to check that in the datasheet of the ATmega that is on the board.

1

I have not downloaded the libraries in question, but It would appear that there is a collision between "SoftSerial.h" and the "GSM/GSM3SoftSerial.h" built in to your GSM library.

There is a disscussion of this conflict here: https://github.com/mainehackerclub/open_vehicle_tracker/issues/28

It seems the answer is to use the "AltSoftSerial" library instead of the stock "SoftSerial" library. The "AltSoftSerial" library can be downloaded here http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.