Putting 3 working codes together....

Hello everyone, would like to say thank you for reading this.
I Have GPS, GYRO,and GSM shield 900 codes that are separately working well. I need to use my gsm shield and working code to upload values from the other sensors on to a dweet. I have configured gsm that it works sending test variable and it does. Now i need to add gps and gyro code in to it. I have tried few different methods and so far no luck, the gsm code works send dweets but variables are empty as it appears the other codes are not working.
I am using Arduino Mega 2560 and SoftwareSerial, tried with AltSoftserial nothing and tried with NewSoftSerial, which apparently does work with Mega 2560. Or does it?

Is there a structure that someone can recommend I use to make them all work together or one at a time?

P.s I know arduino mega has lots serial ports, but honestly i have no idea how to activate them without changing already working code and libs.

Thank you in advance.....

I have tried few different methods and so far no luck, the gsm code works send dweets but variables are empty as it appears the other codes are not working.

But, you didn't post any code for us to look, to see why that might be the case. Well, good luck with your problem.

Give up using soft Serial libraries and get the hardware ones working. It is not difficult. Use them just like you would a soft serial port but with different pins. How many soft serial ports are you trying to use ?

Sorry guys, the code is rather long so did not think u need to see it. If i were to use Hardware serial, would it be able to talk to 3 different sensors?
gsp code

#include <SoftwareSerial.h>
#include <TinyGPS.h>
TinyGPS gps;
SoftwareSerial ss(12, 13);


/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 5d1(Tx) and 4d2(Rx).
*/


static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);

void setup()
{
 
  
  Serial.begin(115200);
  
  Serial.print("Testing Adafruit GPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println(" Oleg Savchuk");
  Serial.println();
  Serial.println("Sats HDOP Latitude  Longitude  Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum");
  Serial.println("          (deg)     (deg)      Age                      Age  (m)    --- from GPS ----  ---- to Orlando  ----  RX    RX        Fail");
  Serial.println("-------------------------------------------------------------------------------------------------------------------------------------");
  
  ss.begin(9600);
}

void loop()
{
 
  float flat, flon;
  Serial.println(flat);
  Serial.println(flon);
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  static const double LONDON_LAT = 28.5383, LONDON_LON = -81.3792;
      
  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
  print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  print_date(gps);
  print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 7, 2);
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
  print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0xFFFFFFFF : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
  print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? TinyGPS::GPS_INVALID_F_ANGLE : TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);
//************************************************************
  gps.stats(&chars, &sentences, &failed);
  print_int(chars, 0xFFFFFFFF, 6);
  print_int(sentences, 0xFFFFFFFF, 10);
  print_int(failed, 0xFFFFFFFF, 9);
  Serial.println();
  

 
  smartdelay(1000);
}

static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void print_float(float val, float invalid, int len, int prec)
{
  if (val == invalid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartdelay(0);
}

static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartdelay(0);
}

static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  if (age == TinyGPS::GPS_INVALID_AGE)
    Serial.print("********** ******** ");
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
        month, day, year, hour, minute, second);
    Serial.print(sz);
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  smartdelay(0);
}

static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartdelay(0);
}

and here is my GSM Gprs code

#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(10, 11);

void setup()
{
  //////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
  gprsSerial.begin(9600);
  Serial.begin(9600);

  Serial.println("Con");
  delay(2000);
  Serial.println("Done!...");
  gprsSerial.flush();
  Serial.flush();


  // Is GPRS attached?
  gprsSerial.println("AT+CGATT?");
  delay(1000);
  toSerial();

  // Check signal strength
  gprsSerial.println("AT+CSQ ");
  delay(1000);
  toSerial();

  // Set connection type to GPRS
  gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(2000);
  toSerial();

  // Set the APN
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"fast.t-mobile.com\"");
  delay(2000);
  toSerial();

  // Enable GPRS
  gprsSerial.println("AT+SAPBR=1,1");
  delay(10000);
  toSerial();

  // Check to see if connection is correct and get your IP address
  gprsSerial.println("AT+SAPBR=2,1");
  delay(2000);
  toSerial();
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
}


void loop()
{
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
  float x=10;
  float y=11;
   // initialize http service
   gprsSerial.println("AT+HTTPINIT");
   delay(2000); 
   toSerial();

   // set http param value
   // ToDO : send dynamic value
   gprsSerial.println(String("AT+HTTPPARA=\"URL\",\"http://www.dweet.io/dweet/for/Smart-Helmet?lat="+ String(x)+"&lon="+ String(y)+"\""));
   delay(4000);
   toSerial();

   // set http action type 0 = GET, 1 = POST, 2 = HEAD
   gprsSerial.println("AT+HTTPACTION=0");
   delay(6000);
   toSerial();

   // read server response
   gprsSerial.println("AT+HTTPREAD"); 
   delay(1000);
   toSerial();

   //gprsSerial.println("");
   gprsSerial.println("AT+HTTPTERM");
   toSerial();
   delay(300);

   gprsSerial.println("");
   delay(10000);
   //////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
}
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
void toSerial()
{
  while(gprsSerial.available()!=0)
  {
    Serial.write(gprsSerial.read());
  }
}
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////

So, you are trying to use 2 soft Serial ports. This can only work under specific circumstances so I suggest that the first thing you do is to use the spare hardware serial ports in the individual programs. Once they work you can consider combining them.

While you are at it, get rid of the delay()s in loop()

Thank you…
I just got the GPS working on serial1. Cant seems to figure out how to do the same for gsm code… I am terrible at programming and learning as I go, so please forgive me my ignorance:)

//#include <SoftwareSerial.h>
//SoftwareSerial gprsSerial(10, 11);

void setup()
{
  //////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
  
  Serial.begin(9600);
  Serial2.begin(9600);
  gprsSerial.begin(9600);
  
  Serial.println("Con");
  delay(2000);
  Serial.println("Done!...");
  gprsSerial.flush();
  Serial.flush();


  // Is GPRS attached?
  gprsSerial.println("AT+CGATT?");
  delay(1000);
  toSerial();

  // Check signal strength
  gprsSerial.println("AT+CSQ ");
  delay(1000);
  toSerial();

  // Set connection type to GPRS
  gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(2000);
  toSerial();

  // Set the APN
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"fast.t-mobile.com\"");
  delay(2000);
  toSerial();

  // Enable GPRS
  gprsSerial.println("AT+SAPBR=1,1");
  delay(10000);
  toSerial();

  // Check to see if connection is correct and get your IP address
  gprsSerial.println("AT+SAPBR=2,1");
  delay(2000);
  toSerial();
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
}


void loop()
{
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
  float x=10;
  float y=11;
   // initialize http service
   gprsSerial.println("AT+HTTPINIT");
   delay(2000); 
   toSerial();

   // set http param value
   // ToDO : send dynamic value
   gprsSerial.println(String("AT+HTTPPARA=\"URL\",\"http://www.dweet.io/dweet/for/MYTHINGNAME
   delay(4000);
   toSerial();

   // set http action type 0 = GET, 1 = POST, 2 = HEAD
   gprsSerial.println("AT+HTTPACTION=0");
   delay(6000);
   toSerial();

   // read server response
   gprsSerial.println("AT+HTTPREAD"); 
   delay(1000);
   toSerial();

   //gprsSerial.println("");
   gprsSerial.println("AT+HTTPTERM");
   toSerial();
   delay(300);

   gprsSerial.println("");
   delay(10000);
   //////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
}
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
void toSerial()
{
  while(gprsSerial.available()!=0)
  {
    Serial.write(gprsSerial.read());
  }
}
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////

The error is now gprsSerial is not declared…
How do I declare it using Serial2???..
Thank you!

#define  gprsSerial Serial2 would be one simple but very unsophisticated way

Thank you, did so and it compiled. but it does not work.

//#include <SoftwareSerial.h>
//SoftwareSerial gprsSerial(10, 11);
#define gprsSerial Serial2


void setup()
{
  //////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
  
  Serial.begin(19200);
  Serial2.begin(9600);
  //gprsSerial.begin(9600);
  
  Serial.println("Con");
  delay(2000);
  Serial.println("Done!...");
  gprsSerial.flush();
  Serial.flush();


  // Is GPRS attached?
  gprsSerial.println("AT+CGATT?");
  delay(1000);
  toSerial();

  // Check signal strength
  gprsSerial.println("AT+CSQ ");
  delay(1000);
  toSerial();

  // Set connection type to GPRS
  gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(2000);
  toSerial();

  // Set the APN
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"fast.t-mobile.com\"");
  delay(2000);
  toSerial();

  // Enable GPRS
  gprsSerial.println("AT+SAPBR=1,1");
  delay(10000);
  toSerial();

  // Check to see if connection is correct and get your IP address
  gprsSerial.println("AT+SAPBR=2,1");
  delay(2000);
  toSerial();
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
}


void loop()
{
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
  float x=10;
  float y=11;
   // initialize http service
   gprsSerial.println("AT+HTTPINIT");
   delay(2000); 
   toSerial();

   // set http param value
   // ToDO : send dynamic value
   gprsSerial.println(String("AT+HTTPPARA=\"URL\",\"http://www.dweet.io/dweet/for/Smart-Helmet?lat="+ String(x)+"&lon="+ String(y)+"\""));
   delay(4000);
   toSerial();

   // set http action type 0 = GET, 1 = POST, 2 = HEAD
   gprsSerial.println("AT+HTTPACTION=0");
   delay(6000);
   toSerial();

   // read server response
   gprsSerial.println("AT+HTTPREAD"); 
   delay(1000);
   toSerial();

   //gprsSerial.println("");
   gprsSerial.println("AT+HTTPTERM");
   toSerial();
   delay(300);

   gprsSerial.println("");
   delay(10000);
   //////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
}
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////
void toSerial()
{
  while(gprsSerial.available()!=0)
  {
    Serial.write(gprsSerial.read());
  }
}
//////////////////////////////////////////////////////GSM CONNECTION/////////////////////////////////////////////////////////////////////////////

Serial.begin successful but nothing after, am I missing something>?
Thank you!

Did you wire it to the Serial2 pins? And a ground?

Yes, and I guess yes…//??? Do u mean if i grounded my GSM Shield>?
I have tried different ways and nothing seems to work, in the serial monitor I see serial is connected and then just a bunch of gibberish coming out. I though it was a baud rate problem but its not i tried every possible baud rate in the code and in the serial monitor. Besides it does not dweet, so the code dont work on serial1 or serial2, i tried both. I i were to resort to using working codes on software serial is there a way i can organised them so the can work together?
I am thinking something of this sort:

#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(10, 11);
SoftwareSerial GPSSerial(12, 13);

void setup()
{
Serial.begin(9600);
gprsSerial.begin(9600);
GPSSerial.begin(9600);
//SOME CODE THAT NEEDS TO BE USED HERE
}
void loop
{
 gprsfunction();
 gpsfunction();
}

void gprsfunction()
{
//gprscode here
}
void gpsfunction()
{
//gpdcode here
}

I would like fot the gps gets its values first and then gprs send it…Any ideas.
Thank you in advance for all your help.

No, I mean you must connect 3 wires for the 2-wire serial connection to work. TX, RX and GND. Connect TX and RX to the appropriate pins on the MEGA for Serial1.

You got something. Gibberish is actually good progress. It usually means you are connected correctly but the baud rate is wrong.

One thing you can use with SoftwareSerial is you only need one instance of it to listen at one time. You can tell one of them to listen and the others will be deaf.

Gibberish is actually good progress. It usually means you are connected correctly but the baud rate is wrong.

..
Or you've got an inversion

Thank you all for responding, I am using part serial software and part hardware, seems to be working.
I have a question about the code is there a way for me to set a priority to function in the loop?

void loop() {
  
  readLocation();
  gsmFunction();

  recordAccelRegisters();
  recordGyroRegisters();
 

}

I would like to get the Gyro and Accel. data first, than GPS, then send it via gsm , but it looks like it connects to the GSM first and it takes way to long to get GYRO data.

oid setup() {
 #
  Serial.begin(9600);
  gprsSerial.begin(9600);
  Serial.println("Startinggprs");
  Wire.begin();
  setupMPU();
  
  
  Serial1.begin(9600); 
  startMillis = millis();
  Serial.println("StartingGPS");

 
  Serial.println("Con");
  delay(2000);
  Serial.println("Done!...");
  gprsSerial.flush();
  Serial.flush();

  
   // Is GPRS attached?
  gprsSerial.println("AT+CGATT?");
  delay(1000);
  toSerial();

  // Check signal strength
  gprsSerial.println("AT+CSQ ");
  delay(1000);
  toSerial();

  // Set connection type to GPRS
  gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(2000);
  toSerial();

  // Set the APN
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"fast.t-mobile.com\"");
  delay(2000);
  toSerial();

This part is in void set up cause i only need to connect ones, and part of the code that dweets data is in loop gsmfunction.

Thank you in advance for all your help....

I have a question about the code is there a way for me to set a priority to function in the loop?

Code is executed in the order in which it is encountered.

  readLocation();
  gsmFunction();

Swap the order of these two function calls if that is what you want.