Here is the code adapted from adafruit gps examples:
Code: Select all
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <SD.h>
#define TFT_CS 16
#define TFT_RST 17
#define TFT_DC 18
#define SD_CS 19
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_GPS GPS(&Serial);
void setup()
{
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
if (!SD.begin(SD_CS))
tft.println("sdErr");
}
uint32_t timer = millis();
void loop()
{
char c = GPS.read();
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA()))
return;
}
if (timer > millis())
timer = millis();
if (millis() - timer > 5000) {
timer = millis();
if (GPS.fix) {
File dataFile = SD.open("nmea.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(GPS.lastNMEA());
dataFile.close();
}
}
}
}