Data generated not properly

Why my GPS modules logs data like this? I want the GPS location every one seconds. but I get data for every 7 8 secs. When I try executing the sarandard examples it works fine. but my own program it does not work as I expect.

Latitude,Longitude,Time
48.772453,11.380930,13:22:34
48.772453,11.380930,13:22:34
48.772224,11.380901,13:22:37
48.772224,11.380901,13:22:37
48.772186,11.380884,13:22:39
48.772186,11.380884,13:22:39
48.772186,11.380884,13:22:39
48.772186,11.380884,13:22:39
48.772186,11.380884,13:22:39
48.772186,11.380884,13:22:39
48.772075,11.380890,13:22:46
48.772075,11.380890,13:22:46
48.772048,11.380926,13:22:48
48.772048,11.380926,13:22:48
48.772048,11.380926,13:22:48
48.772048,11.380926,13:22:48
48.772048,11.380926,13:22:48
48.772048,11.380926,13:22:48
48.772064,11.380880,13:22:55
48.772064,11.380880,13:22:55
48.772068,11.380877,13:22:57
48.772068,11.380877,13:22:57
48.772068,11.380877,13:22:57
48.772068,11.380877,13:22:57
48.772068,11.380877,13:22:57
48.772068,11.380877,13:22:57
48.771968,11.381054,13:23:4
48.771968,11.381054,13:23:4
48.772056,11.380922,13:23:6
48.772056,11.380922,13:23:6
48.772056,11.380922,13:23:6
48.772056,11.380922,13:23:6
48.772056,11.380922,13:23:6
48.772121,11.380867,13:23:12
48.772121,11.380867,13:23:12
48.772121,11.380867,13:23:12
48.772121,11.380867,13:23:12
48.772121,11.380867,13:23:12
48.772121,11.380867,13:23:12
48.772121,11.380867,13:23:12
48.772121,11.380867,13:23:12
48.772247,11.380781,13:23:21
48.772247,11.380781,13:23:21
48.772247,11.380781,13:23:21
48.772247,11.380781,13:23:21
48.772247,11.380781,13:23:21
48.772247,11.380781,13:23:21
48.772289,11.380819,13:23:28
48.772289,11.380819,13:23:28
48.772285,11.380814,13:23:30
48.772285,11.380814,13:23:30
48.772285,11.380814,13:23:30
48.772285,11.380814,13:23:30
48.772285,11.380814,13:23:30
48.772285,11.380814,13:23:35
48.772319,11.380855,13:23:37
48.772319,11.380855,13:23:37
48.772365,11.380864,13:23:39
48.772365,11.380864,13:23:39
48.772365,11.380864,13:23:39
48.772365,11.380864,13:23:39
48.772365,11.380864,13:23:39
48.772365,11.380864,13:23:39
48.772506,11.380843,13:23:46
48.772506,11.380843,13:23:46
48.772518,11.380827,13:23:48
48.772518,11.380827,13:23:48
48.772518,11.380827,13:23:48
48.772518,11.380827,13:23:48
48.772518,11.380827,13:23:48
48.772518,11.380827,13:23:48
48.772518,11.380827,13:23:48
48.772579,11.380825,13:23:56
48.772579,11.380825,13:23:56
48.772605,11.380821,13:23:58
48.772605,11.380821,13:23:58
48.772605,11.380821,13:23:58
48.772605,11.380821,13:23:58
48.772605,11.380821,13:23:58
48.772605,11.380821,13:23:58
48.772682,11.380812,13:24:5
48.772682,11.380812,13:24:5
48.772697,11.380810,13:24:7
48.772697,11.380810,13:24:7
48.772697,11.380810,13:24:7
48.772697,11.380810,13:24:7
48.772697,11.380810,13:24:7
48.772697,11.380810,13:24:7
48.772769,11.380812,13:24:14
48.772769,11.380812,13:24:14
48.772796,11.380803,13:24:16
48.772796,11.380803,13:24:16
48.772796,11.380803,13:24:16
48.772796,11.380803,13:24:16
48.772796,11.380803,13:24:16
48.772865,11.380773,13:24:22
48.772865,11.380773,13:24:22
48.772876,11.380762,13:24:24
48.772876,11.380762,13:24:24
48.772876,11.380762,13:24:24
48.772876,11.380762,13:24:24
48.772876,11.380762,13:24:24
48.772876,11.380762,13:24:24

Here is my code as well.


#include <TinyGPS++.h>
#include <SD.h>

File dataFile; // create a File object to write to the SD card

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  SD.begin(53); // initialize the SD card on pin 53
  dataFile = SD.open("data.txt", FILE_WRITE); 
  dataFile.println("Latitude,Longitude,Time"); 
  dataFile.flush(); // make sure the header is written to the SD card
}

void loop() {
  while (Serial1.available() > 0) {
    if (gps.encode(Serial1.read())) {
      if (gps.location.isValid() && gps.time.isValid()) {
        // get latitude, longitude, and time from GPS module
        float lat = gps.location.lat();
        float lon = gps.location.lng();
        int hour = gps.time.hour();
        int minute = gps.time.minute();
        int second = gps.time.second();
        // write latitude, longitude, and time to SD card
        dataFile.print(lat, 6);
        dataFile.print(",");
        dataFile.print(lon, 6);
        dataFile.print(",");
        dataFile.print(hour);
        dataFile.print(":");
        dataFile.print(minute);
        dataFile.print(":");
        dataFile.println(second);
        dataFile.flush(); 
        delay(1000); 
      }
    }
  }
}

That bit means that for every GPS sentence received your saving the location data to SD card.

Problem is on most GPSs, there are around 8 sentences a second, and only two of them have the location data. So your saving the location to SD around 8 times more often than you need to.

Its likely that with so much writing to SD your missing characters from the GPS.

Your code is not complete, post the code you are actually using.

2 Likes

The whole code is there in the question above only. Can you please improve my code.

No its not, that code wont even compile.

You said the SD log was from your program, but if the code wont compile, how can it write to SD ?

How do you expect it to work, exactly?

This is bad idea:

A much better idea is to use millis() for timing, and write location data at reasonable intervals, or whenever the location has significantly changed.

At a glance, the delay() makes your claim for the output produced impossible.

So, if you did not, please post the actual code you ran that did.

a7

No no. The data that you see is from the file that is created in the SD card.

I want to log the GPS location every 1 second but it is happening every 2 seconds sometime 5, 6 seconds.

I realise that.

The code you posted will not compile, it cannot be working code.

While your 'delay(1000)' is running, the GPS is being ignored. See reply #6.

Yes, and I can see why.

You probably won't be able to collect locations every second, when writing to the SD card, because the SD I/O will interfere with GPS data collection.

And, of course, delay() is the worst thing you can do.

When the GPS puts out the two sentences needed for the location to be updated (hint to OP) you have around 800mS (why the delay is a problem) to get back to reading the GPS, before the next actual location update.

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