Queens, New York
Online
Edison Member
Karma: 29
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #15 on: November 28, 2012, 04:06:17 pm » |
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #16 on: November 28, 2012, 04:12:53 pm » |
no, nothing at all, just logs the filename with nothing on it
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 29
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #17 on: November 28, 2012, 04:16:50 pm » |
I wonder if display GPS is not returning back to the loop after it writes the data, try this. 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; } return; //[b] MAKE THIS CHANGE[/b] }
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #18 on: November 28, 2012, 04:23:00 pm » |
same result, it logs only the first line
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 29
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #19 on: November 28, 2012, 04:26:03 pm » |
Ok well then Im stumped, try the link I posted and copy and paste what you need to get data from the GPS onto the SD card.
Maybe someone else can figure out what is wrong with your code. I can't figure it out.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #20 on: November 28, 2012, 04:27:40 pm » |
ok, thaks a lot for your time
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 313
Posts: 35502
Seattle, WA USA
|
 |
« Reply #21 on: November 28, 2012, 05:17:46 pm » |
You need to open the file, write to it, and close the file ALL IN ONE FUNCTION. Show the code where you are doing that!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #22 on: November 29, 2012, 10:39:36 am » |
Here is the code [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'; } ]
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 29
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #23 on: November 29, 2012, 10:50:12 am » |
Ohhh, I see what PaulS is saying, ok look at this sample code again: http://arduino.cc/en/Tutorial/Dataloggermore to the point this part: File dataFile = SD.open("datalog.txt", FILE_WRITE); //[b]Right here it opens the file[/b] // if the file is available, write to it: if (dataFile) { //[b]Does some work[/b] dataFile.println(dataString); //[b]It then writes the data to that file[/b] dataFile.close(); //[b]Then right after, it closes the file, all in one shot![/b] // print to the serial port too: Serial.println(dataString); } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); }
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #24 on: November 29, 2012, 10:57:33 am » |
I have seen it, the thing is that this part of the sketch is in the loop, that is my problem, I can`t get to put the log command in the loop. Do you have some idea for parsing the gps data on a string and put it on the loop? Because if I open the file in the void gpsdisplay it generates lots of diferent files with only one line of data.
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 29
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #25 on: November 29, 2012, 11:30:59 am » |
Also this is more like what you need to do, STUDY THE CODE CAREFULLY!!! http://arduino.cc/en/Tutorial/FilesRE-EDIT: From what I see, you dont need to have the logfile.open in your SETUP, what you can try is to make the change I said above and just comment // out the one you have in your setup and see if the data goes in properly.
|
|
|
|
« Last Edit: November 29, 2012, 11:39:23 am by HazardsMind »
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 29
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #26 on: November 29, 2012, 12:21:05 pm » |
OK you tried to put logfile.open() in displayGPS, and that created many files, all with one line in them. You want just ONE file with multiple lines.
well it seems that because the logfile.close() is being done when the code HAS AVAILABLE data, it only writes one line then closes the file and does NOT reopen it. You need to take that .close line out and put it somewhere when there is NO available data. That way it will still write the data to the SD card and only close when there is no data. You may need to tell it to close with a button when you go to shut down the ARD.
I'm not sure if Arduino has a way to update the file when it is created instead of constantly creating new files each time. Look into that.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Queens, New York
Online
Edison Member
Karma: 29
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #27 on: November 29, 2012, 12:46:25 pm » |
I found this for you, look at what it puts into the file. www.ladyada.net/products/microsd/Also one last look at your code,
void displayGPS() { char field[20]; logfile.println(); //CHANGE: I think you had it correct the first time but it was not being told to make a new line getField(field, 0); //when there was new data, so it put everything back to back. 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; } return; //[b] MAKE THIS CHANGE[/b] }
|
|
|
|
« Last Edit: November 29, 2012, 12:51:10 pm by HazardsMind »
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 313
Posts: 35502
Seattle, WA USA
|
 |
« Reply #28 on: November 29, 2012, 06:08:12 pm » |
This code: // 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! } } determines the name of a file that does not already exist, and leaves that file open. Move char filename[] out of the setup() function, to make it a global variable. Then, after the SD.open(), before the break, close the file. Then, copy the SD.open() statement to displayGPS(). This will open the same file, not create a new one.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #29 on: November 29, 2012, 06:14:39 pm » |
Thanks to all, I have solved the problem, I just replace the function logfile.close() with logfile.flush() I post the code if anyone likes to use it #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; char field[20]; getField(field, 0); if (strcmp(field, "$GPRMC") == 0) { Serial.print("Tiempo: "); getField(field, 1); Serial.print(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.print(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.print(field); logfile.print(field); logfile.print("\t"); Serial.print("Velocidad: "); getField(field, 7); Serial.println(field) * 1.854; logfile.println(field); logfile.flush(); } } } }
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'; }
Now does anyone know how to configure the venus gps in 10hz with the gps viewer?
|
|
|
|
|
Logged
|
|
|
|
|
|