Hello everyone!
I have some troubles with my GPS logger project. At the begin here is what i use:
-Arduino Uno
-GPS NEO-6M uBlox
-SD card module
Code what i use:
#include <TinyGPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <SPI.h>
File logger;
#define RX_PIN 10
#define TX_PIN 9
#define SD_CS 4
TinyGPS GPS;
SoftwareSerial mySerial(TX_PIN, RX_PIN);
char filename[16];
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
Serial.println("SD card checking..");
if (!SD.begin(SD_CS)){
Serial.println("Failure");
return;
}
Serial.println("SD card ready");
// make it long enough to hold your longest file name, plus a null terminator
int n = 0;
snprintf(filename, sizeof(filename), "data%03d.txt", n); // includes a three-digit sequence number in the file name
while(SD.exists(filename)) {
n++;
snprintf(filename, sizeof(filename), "data%03d.txt", n);
}
logger = SD.open(filename,FILE_READ);
Serial.println(n);
Serial.println(filename);
logger.close();
//now filename[] contains the name of a file that doesn't exist
}
void loop() {
while (mySerial.available()){
int var = mySerial.read();
logger = SD.open(filename,FILE_WRITE);
if (GPS.encode(var))
{
long lat, lon;
unsigned long fix_age;
GPS.get_position(&lat, &lon, &fix_age);
Serial.print("Szerokosc:");
Serial.println(lat);
Serial.print("Dlugosc:");
Serial.println(lon);
logger.print(lat);
logger.print(":");
logger.print(lon);
logger.println();
}
logger.close();
}
}
The method of file creation I found on forum, and I was hoping it will works, but no...
The problem is, the GPS getting position as I want, file is creating as it should. When I insert the SD card port monitor is getting freeze at:
SD card checking -> SD card ready -> show file name and there is freeze, nothing happen
but when I take the SD card out, automatically port monitor show position...
And now the question what I do wrong? I know in code is some messy, but is only a sketch i will make it better when it start work.