Arduino Memory Usage and Local Variable Usage

I've been making a flight computer for a rocket I'd like to include a gps logger. I've found the attached script. It compiles fine, but only leaves 95 bytes for local variables. I've already moved most of the string out puts to flash memory. My problem/question is will the leftover memory be enough for local variables. If not, then is there a way I, a beginner, can further realistically optimize the memory usage so I have enough memory for local variables?

Sorry if my syntax or terminology is bad, I'm very much out of my element. Thank you for the help.

edit: Sorry here is the code posted correctly after using auto format
<
#include "SPI.h"
#include <SD.h>
#include "Adafruit_GPS.h"
#include "SoftwareSerial.h"
#define convLong()
#define convLati()
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);

String NMEA1;
String NMEA2;
char c;
float deg;
float degWhole;
float degDec;

int chipSelect = 4;
File mySensorData;

void readGPS() {
clearGPS();
while (!GPS.newNMEAreceived()) {
c = GPS.read();
}
GPS.parse(GPS.lastNMEA());
NMEA1 = GPS.lastNMEA();

while (!GPS.newNMEAreceived()) {
c = GPS.read();
}
GPS.parse(GPS.lastNMEA());
NMEA2 = GPS.lastNMEA();

Serial.println(NMEA1);
Serial.println(NMEA2);
}

void clearGPS() {
while (!GPS.newNMEAreceived()) {
c = GPS.read();
}
GPS.parse(GPS.lastNMEA());
while (!GPS.newNMEAreceived()) {
c = GPS.read();
} // while(!GPS.newNMEAreceived()) {
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());

while (!GPS.newNMEAreceived()) {
c = GPS.read();
}
GPS.parse(GPS.lastNMEA());
}

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
GPS.begin(9600);

//Send commands to the GPS module
GPS.sendCommand("$PGCMD,33,0*6D");
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
delay(1000);

//only if your SD module's CS pin isn't on pin D10

pinMode(10, OUTPUT);
SD.begin(chipSelect);

readGPS();
if (SD.exists("NMEA.txt")) {
mySensorData = SD.open("NMEA.txt", FILE_WRITE);
mySensorData.println(F("<----------------------- New session ----------------------->"));
mySensorData.print(F("*** "));
mySensorData.print(GPS.day);
mySensorData.print(F("."));
mySensorData.print(GPS.month);
mySensorData.print(F("."));
mySensorData.print(GPS.year);
mySensorData.print(F(" -- "));
mySensorData.print(GPS.hour);
mySensorData.print(F(":"));
mySensorData.print(GPS.minute);
mySensorData.print(F(":"));
mySensorData.print(GPS.seconds);
mySensorData.println(F(" ***"));
mySensorData.close();
}
}
void loop() {
// put your main code here, to run repeatedly:
readGPS();
// Condizione if che controlla se l'antenna ha segnale. Se si, procede con la scrittura dei dati.
if (GPS.fix == 1) { //Only save data if we have a fix
mySensorData = SD.open("NMEA.txt", FILE_WRITE); //Apre il file per le frasi NMEA grezze
mySensorData.println(NMEA1); //Scrive prima NMEA sul file
mySensorData.println(NMEA2); //Scrive seconda NMEA sul file
mySensorData.close(); //Chiude file!!

mySensorData = SD.open("GPSData.txt", FILE_WRITE);
// Converte e scrive la longitudine
convLong();
mySensorData.print(deg, 4); // Scrive le coordinate in gradi sul file
mySensorData.print(F(",")); // Scrive una virgola per separare i dati
Serial.print(deg);
Serial.print(F(","));
// Converte e scrive la latitudine
convLati();
mySensorData.print(deg, 4); // Scrive le coordinate in gradi sul file
mySensorData.print(F(",")); // Scrive una virgola per separare i dati
Serial.print(deg);
Serial.print(F(","));
// Scrive l'altitudine
mySensorData.print(GPS.altitude);
mySensorData.print(F(" "));
Serial.println(GPS.altitude);
mySensorData.close();
}
}

gpslogger2.ino (3.85 KB)

More members will see your code if posted properly.

Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.

Take a look at the TinyGPS library as a replacement for your AdaFruit version.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.