I'm taking in data from a GPS module, but the data comes in one character at a time.
I want to take each character and add add it to a string, so that the string gets bigger and bigger until I am done collecting the data.
strcat(Latitude, DATAIN) doesn't work for me (if DataIn is the character)
So what can I do?
Just in case this helps:
#include <string.h>
#include <ctype.h>
int ledPin = 13; // LED test pin
int rxPin = 0; // RX PIN
int txPin = 1; // TX TX
int byteGPS=-1;
char data[300] = "";
char GPRString[7] = "$GPRMC";
int count=0;
int ready=0;
int counta=0;
int info[13];
char Latitude[50];
char Storage;
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(4800);
for (int i=0;i<300;i++){ // Initialize a buffer for received data
data[i]=' ';
}
}
void loop() {
getGPS();
}
void getGPS(){
byteGPS=Serial.read(); // Read a byte of the serial port
if (byteGPS == -1) { // See if the port is empty yet
delay(100);
} else {
data[counta]=byteGPS; // If there is serial port data, it is put in the buffer
counta++;
if (byteGPS==13){ // If the received byte is = to 13, end of transmission
count=0;
ready=0;
for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR
if (data[i]==GPRString[i-1]){
ready++;
}
}
if(ready==6){ // If yes, countinue and process the data
for (int i=0;i<300;i++){
if (data[i]==','){ // check for the position of the "," separator
info[count]=i;
count++;
}
if (data[i]=='*'){ // ... and the "*"
info[12]=i;
count++;
}
}
for (int i=0;i<12;i++){
switch(i){
case 0 :;break;
case 1 :;break;
case 2 :for (int j=info[i];j<(info[i+1]-1);j++){Storage = data[j+1]; strcat(Latitude,Storage);};break;
case 3 :;break;
case 4 :;break;
case 5 :;break;
case 6 :;break;
case 7 :;break;
case 8 :;break;
case 9 :;break;
case 10 :;break;
case 11 :;break;
case 12 :;break;
}
}
}
counta=0; // Reset the buffer
for (int i=0;i<300;i++){ //
data[i]=' ';
}
}
}
}