Final stages of my project!!

Ok so with the help of the tech community local and online I have Frankensteined my way into writing a successful project and now in the final stages. It’s for a weather balloon project where the arduino will record its alt,long,lat,and date/time to a txt file on an sd and every 5 minutes it will send me a text message where its current location is. I want to shrink my code so it will run more efficient and hopefully have enough space to take snapshots with a camera shield I have. (camera is a novelty at this stage but eventually will be adding one) Also ideas for a housing. I was going to try to find a plastic container of sorts and put foam all around the duino. That plastic housing will be attached to a parachute and net where the helium filled balloons will be. getting weather balloons from amazon… So thats my thoughts I’m open to suggestions of any sort and now the fun part…the code! XD

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <String.H>
#include <SD.h>


/*
   This code demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object,SD, and GPRS.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 3(rx) and 2(tx), an Sd card on pin 10, and GPRS set up on pins 7(rx) and 8(tx). Using AT commands to send wanted data.
*/
const int chipSelect = 10;
static const int gsmRXPin = 7, gsmTXPin = 8;
static const int RXPin = 3, TXPin = 2;
static const uint32_t GPSBaud = 4800;
static char dtostrfbuffer[20];
unsigned long Iterations;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS and GPRS device
SoftwareSerial ss(RXPin, TXPin);
SoftwareSerial mySerial(gsmRXPin, gsmTXPin);

String gsm_date = "invalid";
String gsm_lat = "invalid";
String gsm_lon = "invalid";
String gsm_alt = "invalid";
String dataString ="";

void setup()
{
  mySerial.begin(19200);
  Serial.begin(115200);
  ss.begin(38400);
  ss.print("$PUBX,41,1,0007,0003,4800,0*13\r\n"); // I had to change the GPS baudrate so it will get data correctly... refer to your GPS datasheet
  ss.flush();
  delay(50);
  ss.begin(4800); // reset SoftwareSerial baudrate
  ss.flush();
  delay(50);
  Serial.println("Card Initializing");
  pinMode(10,OUTPUT);
  if (!SD.begin(chipSelect)){
    Serial.println ("Card failed or not present");
    return;
  }
  
  Iterations = 0;
  delay(25);

  Serial.println(F("GPRS_txt_2loc"));
  Serial.println(F("TinyGPS++ and GPRS"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart and Jefe!!"));
  Serial.println();
  Serial.println(F("Sats HDOP Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum"));
  Serial.println(F("          (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail"));
  Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop()
{
  dataString = gsm_date + "," + gsm_lat + "," + gsm_lon + "," + gsm_alt;
  if (Serial.available())
    switch(Serial.read())
   {
     case 't':
       SendTextMessage();
       break;
     case 'd':
       DialVoiceCall();
       break;
     
   } 
  if (mySerial.available())
    Serial.write(mySerial.read());
    
  Iterations++;
  
 if (Iterations % 300 == 0)
    {
      getupdate();
      Serial.println (dataString);
    } 
 
   File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile)
  {
    dataFile.println (dataString);
  }
    dataFile.close();
  


  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

  printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
  printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
  printFloat(gps.location.lat(), gps.location.isValid(), 11, 6,1);
  printFloat(gps.location.lng(), gps.location.isValid(), 12, 6,2);
  printInt(gps.location.age(), gps.location.isValid(), 5);
  printDateTime(gps.date, gps.time);
  printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2,3);
  printFloat(gps.course.deg(), gps.course.isValid(), 7, 2,0);
  printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2,0);
  printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.value()) : "*** ", 6);

  unsigned long distanceKmToLondon =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON) / 1000;
  printInt(distanceKmToLondon, gps.location.isValid(), 9);

  double courseToLondon =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON);

  printFloat(courseToLondon, gps.location.isValid(), 7, 2,0);

  const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);

  printStr(gps.location.isValid() ? cardinalToLondon : "*** ", 6);

  printInt(gps.charsProcessed(), true, 6);
  printInt(gps.sentencesWithFix(), true, 10);
  printInt(gps.failedChecksum(), true, 9);
  Serial.println();
 
  
  smartDelay(1000);
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec, int gsm_val)
{
  if (!valid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    if (gsm_val == 1) gsm_lat = dtostrf(val,10,5,dtostrfbuffer);
    else if (gsm_val == 2) gsm_lon = dtostrf(val,10,5,dtostrfbuffer);
    else if (gsm_val == 3) gsm_alt = dtostrf(val,10,5,dtostrfbuffer);
    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 printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = "*****************";
  if (valid)
    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 printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F("********** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
    gsm_date = sz;
  }
  
  if (!t.isValid())
  {
    Serial.print(F("******** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}
void SendTextMessage()
{
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+1**********\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  mySerial.println(dataString);//the content of the message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}
 
///DialVoiceCall
///this function is to dial a voice call
void DialVoiceCall()
{
  mySerial.println("ATD + +1*********;");//dial the number
  delay(100);
  mySerial.println();
}
 
void ShowSerialData()
{
  while(mySerial.available()!=0)
    Serial.write(mySerial.read());
}

void getupdate()
{
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+1*********\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  mySerial.println(dataString);//the content of the message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

Maybe I am reading between the lines here but I don't see you asking for project guidance . If you are not in need of project guidance then perhaps the best place for your post is in the Exhibition /Gallery.

SoftwareSerial ss(RXPin, TXPin);
SoftwareSerial mySerial(gsmRXPin, gsmTXPin);

So, you’ve connected an ss and a mySerial to the Arduino. Stupid names!

woejefe:
I want to shrink my code so it will run more efficient and hopefully have enough space …

I think you probably want to write your actual sketch and get it working correctly before you worry about optimising it to enable potential future enhancements. If and when you do eventually need to optimise it, you need to know what resource it is running out of and how much extra you need to gain. In other words, write the image-grabbing version, and if it turns out to need more program memory or SRAM than you have available, then look for ways to solve that problem.

PeterH.....The code is working fine or else I wouldn't have said

I have Frankensteined my way into writing a successful project

. I wanted guidance on ideas for a plastic housing and if anyone can help give me ideas on shrinking the code(it is working)....And as for the names PaulS, thanks for the input but maybe some positive non antagonist feedback may be better? (though I did end up changing it to the actual devices they are connected to if that's the point you were trying to make) And this definitely still falls in this topic as I'm not finished with my project.... just trying to learn, please keep giving positive and constructive criticism!

They sell arduino UNO cases online. If you need a custom case I know someone who has a plastic vacuum forming machine.

Post the a drawing with dimensions of what you want .