0
votes

I'm new to arduino and trying to extract gps coordinate using neo 6m module using arduino but the loop is running till infinity. Can you please help me why it is not breaking.

void gpsEvent()
{
    gpsString = "";
    while (1)
    {
        while (gps.available() > 0)  //Serial incoming data from GPS
        {
            char inChar = (char)gps.read();
            gpsString += inChar;//store incoming data from GPS to temparary string str[]
            i++;
            // Serial.print(inChar);
            if (i < 7)                      
            {
                if (gpsString[i-1] != test[i-1])    //check for right string
                {
                    i = 0;
                    gpsString = "";
                }
            }

            if (inChar == '\r')
            {
                if (i > 60)
                {
                    gps_status = 1;
                    break;
                }
                else
                {
                    i = 0;
                }
            }
        }

        if (gps_status)
            break;
     }
}

void get_gps()
{
    gps_status = 0;
    int x = 0;
    while (gps_status == 0)
    {
        gpsEvent();
        int str_lenth = i;
        coordinate2dec();
        i = 0;
        x = 0;
        str_lenth = 0;
    }
}

I have called get_gps(); in the void setup() loop to initialize the system but the gpsEvent function which is used to extract the correct string from data is running till infinite can you pls help. The reference of the code is from https://circuitdigest.com/microcontroller-projects/arduino-based-accident-alert-system-using-gps-gsm-accelerometer but have made few changes of my own but not in the programming for the gps module.

1

1 Answers

0
votes

I think one of the errors is gpsString += inChar;.

This is not Python. You are adding the value of a character to a string pointer.

You should create a buffer with a maximum length, insert a char and check buffer overflow.

Also i seems not be defined. And in C is very bad practice to use global variables as you are doing. Keep one i in the function. Check again the string length.

In general, it seems you are using a language you do not know enough to write simple programs (string manipulation is basic on C). Either learn better C or look for a python implementation (or just link) of the gps library.