Show Posts
|
|
Pages: 1 [2]
|
|
17
|
Using Arduino / Project Guidance / Re: Gps logger
|
on: November 28, 2012, 03:56:40 pm
|
|
Data continues going out, the thing is that it no longer logs to the sd card, if I hit the restart button in the arduino it generates another file but it does the same thing again, it logs the first line.
|
|
|
|
|
18
|
Using Arduino / Networking, Protocols, and Devices / Re: Gps logger
|
on: November 28, 2012, 03:48:21 pm
|
here is the code #include <SD.h>
#include <SoftwareSerial.h>
SoftwareSerial gpsSerial(6, 5); // RX, TX (TX not used) const int sentenceSize = 80;
char sentence[sentenceSize];
#define LOG_INTERVAL 100
const int chipSelect = 10; File logfile; long idd = 0; long ids = 0; long idm = 0; long idh = 0;
void error(char *str) { Serial.print("error: "); Serial.println(str);
while(1); }
void setup() { Serial.begin(9600); gpsSerial.begin(9600); Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT); // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card Failed or not present"); return; } Serial.println("card initialized."); // create a new file char filename[] = "LOGGER00.CSV"; for (uint8_t i = 0; i < 100; i++) { filename[6] = i/10 + '0'; filename[7] = i%10 + '0'; if (! SD.exists(filename)) { // only open a new file if it doesn't exist logfile = SD.open(filename, FILE_WRITE); break; // leave the loop! } } if (! logfile) { error("couldnt create file"); } Serial.print("Logging to: "); Serial.println(filename); }
void loop() { static int i = 0; if (gpsSerial.available()) { char ch = gpsSerial.read(); if (ch != '\n' && i < sentenceSize) { sentence[i] = ch; i++; } else { sentence[i] = '\0'; i = 0; displayGPS(); } } }
void displayGPS() { char field[20]; getField(field, 0); if (strcmp(field, "$GPRMC") == 0) { Serial.print("Tiempo: "); getField(field, 1); Serial.println(field); logfile.print(field); logfile.print("\t"); Serial.print("Lat: "); getField(field, 3); // number Serial.print(field); logfile.print(field); logfile.print("\t"); getField(field, 4); // N/S Serial.println(field); logfile.print(field); logfile.print("\t"); Serial.print("Long: "); getField(field, 5); // number Serial.print(field); logfile.print(field); logfile.print("\t"); getField(field, 6); // E/W Serial.println(field); logfile.print(field); logfile.print("\t"); Serial.print("Velocidad: "); getField(field, 7); Serial.println(field) * 1.854; logfile.println(field); logfile.close(); } }
void getField(char* buffer, int index) { int sentencePos = 0; int fieldPos = 0; int commaCount = 0; while (sentencePos < sentenceSize) { if (sentence[sentencePos] == ',') { commaCount ++; sentencePos ++; } if (commaCount == index) { buffer[fieldPos] = sentence[sentencePos]; fieldPos ++; } sentencePos ++; } buffer[fieldPos] = '\0'; }
|
|
|
|
|
19
|
Using Arduino / Project Guidance / Re: Gps logger
|
on: November 28, 2012, 03:46:34 pm
|
|
In the serial monitor it comes the data just fine, I get position, time and speed, the thing is I don`t get that info in the sd. Someone said that I open the file in the setup, and then imediately close after the first line when I put logfile.close();... the thing is that if I remove that comand it doesn`t log anything at all, just the filename in the sd card but without data on it.
|
|
|
|
|
21
|
Using Arduino / Project Guidance / Re: Gps logger
|
on: November 28, 2012, 03:37:11 pm
|
|
203042.987 3424.8937 S 05835.1069 W 000.0 This is what it logs, the information is correct, it is what I need to log but I need to log the rest of the datalines and not just one. It seems to me that the part that logs shoul be on the loop and not in the void gpsdisplay but I don`t know how to do that.
|
|
|
|
|
22
|
Using Arduino / Project Guidance / Re: Gps logger
|
on: November 28, 2012, 03:20:30 pm
|
It only writes the first line of data, the it close the file, if you hit restart in the arduino it opens anotrher file and do the same thing, just the first line of information. void displayGPS() { char field[20]; getField(field, 0); if (strcmp(field, "$GPRMC") == 0) { Serial.print("Tiempo: "); getField(field, 1); logfile.print(field); logfile.print("\t"); Serial.println(field); Serial.print("Lat: "); getField(field, 3); // number logfile.print(field); logfile.print("\t"); Serial.print(field); getField(field, 4); // N/S logfile.print(field); logfile.print("\t"); Serial.println(field); Serial.print("Long: "); getField(field, 5); // number logfile.print(field); logfile.print("\t"); Serial.print(field); getField(field, 6); // E/W logfile.print(field); logfile.print("\t"); Serial.println(field); Serial.print("Velocidad: "); getField(field, 7); logfile.println(field); logfile.close(); // this is the command that think is doing that problem, the thing is that if I take it off it doesn`t log anything, just the file name Serial.println(field) * 1.854; } }
|
|
|
|
|
23
|
Using Arduino / Project Guidance / Re: Gps logger
|
on: November 28, 2012, 03:07:01 pm
|
|
What I`m saying is that part of the sketch is fine, I think that the problem is that the logfile command is the void gpsdisplay and I think it should be in the loop as you said, but I can`t get the way to put that part there
|
|
|
|
|
24
|
Using Arduino / Project Guidance / Re: Gps logger
|
on: November 28, 2012, 03:04:13 pm
|
|
Sorry, next time I`ll post it that way. And thanks for replying, let me tell that the way you told me is not coming along, it says that it can`t create the file
|
|
|
|
|
25
|
Using Arduino / Networking, Protocols, and Devices / Gps logger
|
on: November 28, 2012, 02:31:25 pm
|
|
Hi my name is Leonardo and I was wondering if anyone can help with my gps logger. I have made a sketch but I only get to log the first line of data to my sd card and I can`t find the problem. The sketch is the problem, both the gps and the sd shield are ok.
#include <SD.h>
#include <SoftwareSerial.h>
SoftwareSerial gpsSerial(6, 5); // RX, TX (TX not used) const int sentenceSize = 80;
char sentence[sentenceSize];
#define LOG_INTERVAL 100
const int chipSelect = 10; File logfile; long idd = 0; long ids = 0; long idm = 0; long idh = 0;
void error(char *str) { Serial.print("error: "); Serial.println(str);
while(1); }
void setup() { Serial.begin(9600); gpsSerial.begin(9600); Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT); // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card Failed or not present"); return; } Serial.println("card initialized."); // create a new file char filename[] = "LOGGER00.CSV"; for (uint8_t i = 0; i < 100; i++) { filename[6] = i/10 + '0'; filename[7] = i%10 + '0'; if (! SD.exists(filename)) { // only open a new file if it doesn't exist logfile = SD.open(filename, FILE_WRITE); break; // leave the loop! } } if (! logfile) { error("couldnt create file"); } Serial.print("Logging to: "); Serial.println(filename); }
void loop() { static int i = 0; if (gpsSerial.available()) { char ch = gpsSerial.read(); if (ch != '\n' && i < sentenceSize) { sentence = ch; i++; } else { sentence = '\0'; i = 0; displayGPS(); } } }
void displayGPS() { char field[20]; getField(field, 0); if (strcmp(field, "$GPRMC") == 0) { Serial.print("Tiempo: "); getField(field, 1); logfile.print(field); logfile.print("\t"); Serial.println(field); Serial.print("Lat: "); getField(field, 3); // number logfile.print(field); logfile.print("\t"); Serial.print(field); getField(field, 4); // N/S logfile.print(field); logfile.print("\t"); Serial.println(field); Serial.print("Long: "); getField(field, 5); // number logfile.print(field); logfile.print("\t"); Serial.print(field); getField(field, 6); // E/W logfile.print(field); logfile.print("\t"); Serial.println(field); Serial.print("Velocidad: "); getField(field, 7); logfile.println(field); logfile.close(); Serial.println(field) * 1.854; } }
void getField(char* buffer, int index) { int sentencePos = 0; int fieldPos = 0; int commaCount = 0; while (sentencePos < sentenceSize) { if (sentence[sentencePos] == ',') { commaCount ++; sentencePos ++; } if (commaCount == index) { buffer[fieldPos] = sentence[sentencePos]; fieldPos ++; } sentencePos ++; } buffer[fieldPos] = '\0'; }
|
|
|
|
|
26
|
Using Arduino / Project Guidance / Gps logger
|
on: November 28, 2012, 02:28:23 pm
|
|
Hi, my name is Leonardo and I`m trying to make a gps logger but I have a little problem. The gps data comes ok from the serial port, I got position and time, but at the time to log data to the sd card it only logs the first line, here is the sketch, I think the problem is in the part of the logfile commands but I can`t figer out the problem. Sd shield and gps works just fine, the problem is in the sketch.
#include <SD.h>
#include <SoftwareSerial.h>
SoftwareSerial gpsSerial(6, 5); // RX, TX (TX not used) const int sentenceSize = 80;
char sentence[sentenceSize];
#define LOG_INTERVAL 100
const int chipSelect = 10; File logfile; long idd = 0; long ids = 0; long idm = 0; long idh = 0;
void error(char *str) { Serial.print("error: "); Serial.println(str);
while(1); }
void setup() { Serial.begin(9600); gpsSerial.begin(9600); Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT); // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card Failed or not present"); return; } Serial.println("card initialized."); // create a new file char filename[] = "LOGGER00.CSV"; for (uint8_t i = 0; i < 100; i++) { filename[6] = i/10 + '0'; filename[7] = i%10 + '0'; if (! SD.exists(filename)) { // only open a new file if it doesn't exist logfile = SD.open(filename, FILE_WRITE); break; // leave the loop! } } if (! logfile) { error("couldnt create file"); } Serial.print("Logging to: "); Serial.println(filename); }
void loop() { static int i = 0; if (gpsSerial.available()) { char ch = gpsSerial.read(); if (ch != '\n' && i < sentenceSize) { sentence = ch; i++; } else { sentence = '\0'; i = 0; displayGPS(); } } }
void displayGPS() { char field[20]; getField(field, 0); if (strcmp(field, "$GPRMC") == 0) { Serial.print("Tiempo: "); getField(field, 1); logfile.print(field); logfile.print("\t"); Serial.println(field); Serial.print("Lat: "); getField(field, 3); // number logfile.print(field); logfile.print("\t"); Serial.print(field); getField(field, 4); // N/S logfile.print(field); logfile.print("\t"); Serial.println(field); Serial.print("Long: "); getField(field, 5); // number logfile.print(field); logfile.print("\t"); Serial.print(field); getField(field, 6); // E/W logfile.print(field); logfile.print("\t"); Serial.println(field); Serial.print("Velocidad: "); getField(field, 7); logfile.println(field); logfile.close(); Serial.println(field) * 1.854; } }
void getField(char* buffer, int index) { int sentencePos = 0; int fieldPos = 0; int commaCount = 0; while (sentencePos < sentenceSize) { if (sentence[sentencePos] == ',') { commaCount ++; sentencePos ++; } if (commaCount == index) { buffer[fieldPos] = sentence[sentencePos]; fieldPos ++; } sentencePos ++; } buffer[fieldPos] = '\0'; }
|
|
|
|
|