Send GPS weft from Arduino GSM Shield

Hello

I have a projecy and I have to create a scooter tracker (to warn a theft)

I have to send a GPS weft from a GSM

I already have the code to send a SMS and it work but and the weft to receive the GPS tram which work too.

I try to bring together the two codes to send the GSP weft from a GSM but it don’t work, If you can correct my mistakes please, thank you

This is my code :

#include <GSM.h>                                            // BIBLIOTHEQUE GPS 
#include <TinyGPS++.h>                                      // BIBLIOTHEQUE INCLUE
#include <SoftwareSerial.h>                                 // BIBLIOTHEQUE POUR ECHANGE LIAISON SERIE (USART)

static const int RXPin = 9, TXPin = 7;                      // LE PORT 9 = RXD et LE PORT 7 = TXD VARIABLES RESTE TOUJOURS LA MEME TOUT AU LONG SU PROG       
 uint32_t GPSBaud = 9600;                                   // VITESSE GPS = 9600   

TinyGPSPlus gps;                                            // Crée un objet TinyGPS ++ appelé "gps"
SoftwareSerial ss(RXPin, TXPin);                            // LA CONNEXION SERIE PAR RAPPORT AU GPS (9,0)

#define PINNUMBER "3970"                                     // If your SIM has PIN, pass it as a parameter of begin() in quotes            
                                                             
GSM gsmAccess;
GSM_SMS sms;

char remoteNumber[20];                                           // numero de telephone du destinataire
/**********************************************************************************************************************************************/
void setup() {

  Serial.begin(115200);                                     // INITIALISATION DE LA VITESSE LIAISON SERIE
  ss.begin(GPSBaud);                                        // INITIALISATION DE LA VITESSE GPS    
 
  while (!Serial) {                                         // wait for serial port to connect. Needed for native USB port only
    ;
  }

  Serial.println("Envoi SMS");                              // ECRIRE ENVOI SMS

 
  boolean notConnected = true;                                // connection state
 
  
 
  while (notConnected) {                                      // TANT QUE CE N'EST PAS CONNECTER A LA SIM 
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {            // DETECTION DU CODE PIN ET CONTINUER LA POURSUITE
      notConnected = false;
    } else {
      Serial.println("NON CONNECTE");                        // SINON AFFICHER NON CONNECTE
      delay(1000);
    }
  }

  Serial.println("GSM initialise");


}
/*************************************************************************************************************************************************/
void loop() 
{

  while (ss.available() > 0)                               // TANT QUE LA DISPONIBILITE > 0 ("$")
    if (gps.encode(ss.read()))                             // ALORS CODER ET STOCKER LA TRAME GPGGA
     { afficherInfo();    }                                  // aller au sous programme "AFFICHERinfo"

  if (millis() > 5000 && gps.charsProcessed() < 10)        // Si 5000 millisecondes passent et qu'il n'y a aucun caractère entrant
  {
    Serial.println(F("No GPS detected: check wiring."));   // sur le port série du logiciel, affiche une erreur "Aucun GPS détecté"
    while(true);                                           // TANT QUE C'EST VRAI
  }
  sendSMS();
}
/***********************************************************************************************************************************************/
void afficherInfo()                                   
{
  Serial.print(F("Localisation: ")); 
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F("  et  "));
    Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print(F("INVALID"));
  }  
  Serial.println();  delay(5000);

}
/****************************************************************************************************************************************************/
 
  
void sendSMS(){

  Serial.print("Entrez un numero de telephone:");
  Serial.println(remoteNumber);

  
  Serial.println("ENVOIE");
  Serial.println();
  Serial.println("Message:");
  Serial.println(gps.location.lat(), 6);
  Serial.println(F(","));
  Serial.println(gps.location.lng(), 6);

  
  sms.beginSMS(remoteNumber);
  sms.print(gps.location.lat(), 6);
  sms.print(F(","));
  sms.print(gps.location.lng(), 6);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");  
}
/***********************************************************************************************************************************************************/
 
int readSerial(char result[]) {
  int i = 0;
  while (1) {
    while (Serial.available() > 0) {
      char inChar = ss.read();
      if (inChar == '\n') {
        result[i] = '\0';
        Serial.flush();
        return 0;
      }
      if (inChar != '\r') {
        result[i] = inChar;
        i++;
      }
    }
  }
}

and in the attachment, there is the mistakes

You can NOT use SoftwareSerial.h and GSM.h in the same sketch.

Get an Arduino that has multiple hardware serial ports.

Here is an example of a board plus test sketch which has GPS and GSM functionality and does not require any libraries (although at least to interpret the GPS data you'd probably want to keep the TinyGps++) https://www.elecrow.com/wiki/index.php?title=32u4_with_A7_GPRS/GSM The board uses an ATmega32U4 (as in arduino Micro/Leonardo) which has two hardware serial ports. The GPS/GSM module is an AI-thinker A7. You can't use software serial here either because it does not support the required speed of 115200 baud.

Now, I have a arduino Mega2560 which have 4 hardware serial ports, can you correct my sketch please ? :slight_smile:

Choose which serial port you are gong to use on the mega (e.g. Serial1) for this device and connect the device to the appropriate pins. Remove this statement: SoftwareSerial ss(RXPin, TXPin); change all occurrences of ss. to Serial1. (if you choose to use Serial1)

If it doesn't work, say why and post your new code.