Go Down

Topic: Serial monitor and SD card show different data (Read 1 time) previous topic - next topic

PaulS

Quote
Does this make any sense? As always, thanks to everyone that has been patient with my noobness.

Yes, it does. There are two things that you could do, depending on what you want to accomplish. You could get output like this:
1,0,125,995,-16,-88,224429,A,3607.0164,N,07946.2195,W,000.0,091.8,290212,008.1,
1,0,126,995,
1,0,126,995,
1,0,126,995,
2,0,127,996,-16,-88,224430,A,3607.0164,N,07946.2196,W,000.0,091.8,290212,008.1,
2,0,126,995,
2,0,126,995,
2,0,126,995,
3,0,126,993,-16,-88,224431,A,3607.0164,N,07946.2194,W,000.0,091.8,290212,008.1,
3,0,126,995,
3,0,126,995,
3,0,126,995,

Or, you could get output like this:
1,0,125,995,-16,-88,224429,A,3607.0164,N,07946.2195,W,000.0,091.8,290212,008.1,
1,0,125,995,-16,-88,224429,A,3607.0164,N,07946.2195,W,000.0,091.8,290212,008.1,
1,0,125,995,-16,-88,224429,A,3607.0164,N,07946.2195,W,000.0,091.8,290212,008.1,
1,0,125,995,-16,-88,224429,A,3607.0164,N,07946.2195,W,000.0,091.8,290212,008.1,
2,0,127,996,-16,-88,224430,A,3607.0164,N,07946.2196,W,000.0,091.8,290212,008.1,
2,0,127,996,-16,-88,224430,A,3607.0164,N,07946.2196,W,000.0,091.8,290212,008.1,
2,0,127,996,-16,-88,224430,A,3607.0164,N,07946.2196,W,000.0,091.8,290212,008.1,
2,0,127,996,-16,-88,224430,A,3607.0164,N,07946.2196,W,000.0,091.8,290212,008.1,
3,0,126,993,-16,-88,224431,A,3607.0164,N,07946.2194,W,000.0,091.8,290212,008.1,
3,0,126,993,-16,-88,224431,A,3607.0164,N,07946.2194,W,000.0,091.8,290212,008.1,
3,0,126,993,-16,-88,224431,A,3607.0164,N,07946.2194,W,000.0,091.8,290212,008.1,
3,0,126,993,-16,-88,224431,A,3607.0164,N,07946.2194,W,000.0,091.8,290212,008.1,

In the first case, the GPS data is only printed if there is new data. In the second case, the old data is printed if there is no new data.

In either case, you need to move the code to get the analog values and the sprintf() call and the code to write to the file outside of the if(Serial.available() > 0) block.

Because the code to write to the file is inside that block, the writes only happen when there is data to write.

Code: [Select]
void loop()
{
   bool gpsComplete = false;
   if(Serial.available() > 0)
   {
     // Collect serial data
     // if complete, set gpsComplete to true
   }

   // Collect other sensor data

   if(millis() - lastWriteTime > 250) // write every 250 milliseconds
   {
      if(gpsComplete)
      {
         // sprintf sensor and GPS data
      }
      else
      {
         // sprintf just sensor data
      }

      // write to sd card
   }
}


Something like this, if you only want to write gps data once per packet, when new data is available. If you want to write old gps data with each packet, remove the gpsComplete flag and test.

Go Up