Hey everyone, I am trying to make a basic gps route logger. I am using a nano every, an adafruit gps module and a sd card module. I want to log the route and save that route on a file on my sd card. That way i can look at the route in google maps after uploading it.
Now the problems that i have are:
- The file doesn't get created
- The gps coordinates(longitude and latitude) are always empty(or never found)
If anyone knows how to fix it then i would be forever greatfull for you. I will attach the code under this.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SD.h>
#define GPS_RX_PIN 0
#define GPS_TX_PIN 1
#define chipSelect 8
TinyGPSPlus gps;
SoftwareSerial gpsSerial(GPS_RX_PIN, GPS_TX_PIN);
void setup() {
Serial.begin(9600);
gpsSerial.begin(9600);
if (!SD.begin(chipSelect)) {
Serial.println("Initialisatie mislukt!");
return;
File dataFile = SD.open("GpsData.kml", FILE_WRITE);
if (!dataFile) {
Serial.println("Bestand GpsData.kml maken mislukt!");
return;
}
}
Serial.println("Initialisatie succesvol.");
}
void loop() {
String stringLatitude = "";
String stringLongitude = "";
if (gps.location.isValid()) {
stringLatitude = String(gps.location.lat(), 6);
stringLongitude = String(gps.location.lng(), 6);
File dataFile = SD.open("GpsData.kml", FILE_WRITE);
if (dataFile) {
dataFile.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
dataFile.println("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
dataFile.println("<Document>");
dataFile.println("<Placemark>");
dataFile.print("<name>");
dataFile.print("GPS Location");
dataFile.println("</name>");
dataFile.println("<Point>");
dataFile.print("<coordinates>");
dataFile.print(stringLongitude);
dataFile.print(",");
dataFile.print(stringLatitude);
dataFile.println("</coordinates>");
dataFile.println("</Point>");
dataFile.println("</Placemark>");
dataFile.println("</Document>");
dataFile.println("</kml>");
dataFile.close();
} else {
Serial.println("Mislukt om bestand te openen");
}
} else {
Serial.println("Locatie: Niet Beschikbaar");
}
if (millis() > 300000 && gps.charsProcessed() < 10) {
Serial.println("Geen GPS gedetecteerd");
while (true);
}
Serial.println("GPS Coördinaten:");
Serial.print("Latitude: ");
Serial.println(stringLatitude);
Serial.print("Longitude: ");
Serial.println(stringLongitude);
Serial.println();
delay(1000);
}
wiring diagram:
components:
gps module - Flora Wearable Ultimate GPS Module : ID 1059 : Adafruit Industries, Unique & fun DIY electronics and kits
sd card module - 3.3V Micro SD card module voor ESP32 | ESP8266 - OTRONIC
If you have any questions let me know!
Thank you in advance <3
