msg_field [0] = 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:#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. 解决方案 GPGGA,095350.000,5112.1239,N,04315.0058,E,1,7,1.13,0.3,M,47.2,Here is my code:#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.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.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 withGPGGA,095350.000,5112.1239,N,04315.0058,E,1,7,1.13,0.3,M,47.2msg_field[0] = 这篇关于如何使用arduino拆分char数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 02:39