Hi Guys,
I have some difficulties and I'm new to Arduino programming... I want to read a serial data string similar to the NMEA Protocol:
(for example: $GPRMC,154653,V,4428.2011,N,00440.5161,W,000.5,342.8,050407,,,N*7F) without using the tinygps.h library and store the data between the ',' in variables such as float or int to do some further calculations with them.
However, the code from the arduino-gps tutorial is already close
(Arduino Playground - GPS)
But in case of Serial.print the data, I want to store them in my veriables ![]()
Any ideas?
void loop() {
digitalWrite(ledPin, HIGH);
byteGPS=Serial.read(); // Read a byte of the serial port
if (byteGPS == -1) { // See if the port is empty yet
delay(100);
} else {
linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer
conta++;
Serial.print(byteGPS, BYTE);
if (byteGPS==13){ // If the received byte is = to 13, end of transmission
digitalWrite(ledPin, LOW);
cont=0;
bien=0;
for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR
if (linea[i]==comandoGPR[i-1]){
bien++;
}
}
if(bien==6){ // If yes, continue and process the data
for (int i=0;i<300;i++){
if (linea[i]==','){ // check for the position of the "," separator
indices[cont]=i;
cont++;
}
if (linea[i]=='*'){ // ... and the "*"
indices[12]=i;
cont++;
}
}
Serial.println(""); // ... and write to the serial port
Serial.println("");
Serial.println("---------------");
for (int i=0;i<12;i++){
switch(i){
case 0 :Serial.print("Time in UTC (HhMmSs): ");break;
case 1 :Serial.print("Status (A=OK,V=KO): ");break;
...
case 12 :Serial.print("Checksum: ");break;
}
for (int j=indices[i];j<(indices[i+1]-1);j++) // <- I think what I need is in here... but I don't know how to put the data in variables
{
Serial.print(linea[j+1]);
}
Serial.println("");
}
Serial.println("---------------");
}
conta=0; // Reset the buffer
for (int i=0;i<300;i++){ //
linea[i]=' ';
}
}
}
}

