 
 
 void WriteDataToLogger(float Temperature, float Pressure, float Altitude, float Latitude, float Longitude) {
-  DataLogger.listen();
+  if(!DataLogger.isListening()) { DataLogger.listen(); }
+
   DataLogger.print(Temperature, 2);
   DataLogger.print(",");
   DataLogger.print(Pressure, 0);


// *********************************************************************
// GPS Receiver subroutines
void GetGPSData() 
{
  int i = 0;
  gpsSerial.listen();
  char ch = gpsSerial.read();
  while (ch != '\n' && i < sentenceSize)
  {
    sentence[i] = ch;
    i++;
  }

  sentence[i] = '\0';
}


void getField(char* buffer, int index)
{
  int sentencePos = 0;



// *********************************************************************
// GPS receiver settings/variables
SoftwareSerial gpsSerial(10, 9); // RX, TX (TX not used)
const int sentenceSize = 80;
char sentence[sentenceSize];
float CurrentLatitude;
float CurrentLongitude;
boolean ShouldRecordGPSData;


void setup(void) {
  Serial.begin(9600);
  
  Wire.begin();
  RawTemp = -1000.0;
  CurrentTemp = 0.0;
  
  CalibratePressureSensor();

  DataLogger.begin(9600);

  gpsSerial.begin(9600);
  CurrentLatitude = 0.0;
  CurrentLongitude = 0.0;
  ShouldRecordGPSData = false;
}


void loop(void) {
  
  // TODO: Get GPS coordinates
  static int i = 0;
  if(!gpsSerial.isListening()) { gpsSerial.listen(); }
  if (gpsSerial.available())
  {
    char ch = gpsSerial.read();

    if(ch == '$' && !ShouldRecordGPSData) 
    { 
      ShouldRecordGPSData = true; 
      i = 0;
    }

    if(ShouldRecordGPSData) {
      if (ch != '\n' && i < sentenceSize)
      {
        sentence[i] = ch;
        i++;
      }
      else
      {
        sentence[i] = '\0';
        ShouldRecordGPSData = false;
        i = 0;
    
        char field[20];
        getField(field, 0);
        if(strcmp(field, "$GPRMC") == 0)
        {
          getField(field, 3);
          CurrentLatitude = atof(field);
          getField(field, 5);
          CurrentLongitude = atof(field);
        }

        // Now that we have a good GPS reading, grab the
        // rest of the data from the other sensors.
        RawTemp = GetTemp();
        if(RawTemp > -1000) { CurrentTemp = RawTemp; }
        float CurrentPressure = GetPressure(bmp085ReadUT(), bmp085ReadUP());
        float CurrentAltitude = CalculateAltitude(CurrentPressure);
        
        PrintToSerialOutput(CurrentTemp, CurrentPressure, CurrentAltitude, CurrentLatitude, CurrentLongitude);
        WriteDataToLogger(CurrentTemp, CurrentPressure, CurrentAltitude, CurrentLatitude, CurrentLongitude);

      }
    }
  }
  

  
  // TODO: What data do we write to the radio?
  // TODO: How frequently should we write data to the radio?
  // TODO: Write data to radio
  
//  delay(SAMPLING_DELAY);
  
}

