我目前正在构建一个小型 GPS 盒,它应该可以跟踪我的位置并将完整的 NMEA 语句写入 SD 卡。
(我想在我的电脑上解析它)
我正在使用 Arduino Nano 和NEO-6M GPS 模块来获取数据。
工作原理:从模块中获取 NMEA 数据,写入 SD 卡。
通过 Serial.write 将数据输出到串行输出可以正常工作。
现在我遇到的问题是 Arduino 无法将数据足够快地写入 SD 卡并且与 GPS 模块不同步。这偶尔会产生这样的事情:$G3,3,09,32,20,248,*4D
我对如何解决这个问题有一些想法:
1. 更快地写入数据
2. 始终等到数据完全写入后再获取下一个定位
点 3. 每隔一秒写入一次 GPS 定位点
4. 首先,写入缓冲区,然后写入一去SD卡
我试图实现这些,但每次都失败了(对不起,我是新手)。
这是我当前的代码:
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
SoftwareSerial GPS_Serial(4, 3); // GPS Module’s TX to D4 & RX to D3
File GPS_File;
int NBR = 1; //file number
void setup() {
Serial.begin(9600);
GPS_Serial.begin(9600);
SD.begin(5);
//write data to a new file
bool rn = false;
while (rn == false) {
if (SD.exists(String(NBR) + ".txt")) {
NBR = NBR + 1;
}
else {
GPS_File = SD.open(String(NBR) + ".txt", FILE_WRITE);
GPS_File.write("START\n");
GPS_File.close();
rn = true;
}
}
}
void loop() {
GPS_File = SD.open(String(NBR) + ".txt", FILE_WRITE);
while (GPS_Serial.available() > 0) {
GPS_File.write((byte)GPS_Serial.read());
}
GPS_File.close();
}