Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'll read my GPS coordinates form my Arduino as a comma seperated buffer array. the data comes in as follow:

$GPGGA,095350.000,5112.1239,N,04315.0058,E,1,7,1.13,0.3,M,47.2,


Here is my code:

arduino
#include <SoftwareSerial.h>
 
SoftwareSerial SoftSerial(4, 5);
unsigned char buffer[64];
int count = 0; 

void sendGPSData() {
    if (SoftSerial.available())
    {
        while (SoftSerial.available())
        {
            char read = SoftSerial.read();

            buffer[count++] = read;

            Serial.print(String(read));

            if (count == 64) {
                break;
            }
        }

        delay(2000);
        clearBufferArray();
        count = 0;
    }
}

void clearBufferArray()
{
    for (int i = 0; i < count; i++)
    {
        buffer[i] = NULL;
    }
}


The question I've got is how can I split the buffer array so I could get the bold parts in the output above?

What I have tried:

I've tried to use this code GPS data · GitHub[^] but there are to much resources needed.
Posted
Updated 20-Aug-17 14:17pm
Comments
Richard MacCutchan 2-Dec-16 9:07am    
What language is that and does it have a string tokenizer?

I use this for my own GPS parser. I pulled it off the net or out of a book but can't remember where so I can't give proper credit to its author. You need to declare a char array to hold the GPS data which you probably already have, and then a string array, in this case msg_field[] with enough elements for each field in the char array - a field being the data between the commas. Twenty is sufficient for GPS data.

C++
byte getCSVfields()
{
    byte _sentencePos = 0;
    byte _comma_count = 0;
    msg_field[_comma_count] = "";
    while (1)
    {
        if (input_buffer[_sentencePos] == NULL) break;
        if (input_buffer[_sentencePos] == 44)
        {
            _comma_count++;
            msg_field[_comma_count] = "";
            _sentencePos++;
        }
        else
        {
            msg_field[_comma_count] += input_buffer[_sentencePos];
            _sentencePos++;
        }
    }
    return _comma_count + 1;
}


What you end up with is an array of Strings, in your case with

$GPGGA,095350.000,5112.1239,N,04315.0058,E,1,7,1.13,0.3,M,47.2

msg_field[0] = $GPGGA
msg_field[1] = 095350.000
msg_field[2] = 5112.1239
msg_field[3] = N
msg_field[4] = 04315.0058
msg_field[5] = E
msg_field[6] = 1
msg_field[7] = 7
msg_field[8] = 1.13
msg_field[9] = 0.3
msg_field[10] = M
msg_field[11] = 47.2

and the byte value returned would be 12, the number of fields. So then you would play around with fields 1 thru 5 if I see the bold correctly.

Have fun
 
Share this answer
 
Don't reinvent the wheel. These are NMEA sentences NMEA 0183 - Wikipedia[^] and there are many libraries written for parsing them.

See here: How to use GPS with Arduino - Parse and Log NMEA Sentences - Tutorial Australia[^]

and: NMEA:: Wiring library for easy decoding of GPS data[^]

and: TinyGPS++ | Arduiniana[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900