Show Posts
Pages: 1 [2] 3
16  Using Arduino / Project Guidance / gps logger 10hz on: December 05, 2012, 05:19:59 pm
Hi everyone, I have a little proyect for making a gps logger, so far I have set the venus gps at 10hz and I succesfull meke a sketch for log the information to a sd shiel. However it has a little problem, sometimes it logs the information with strange characters.
Here es the sketch.
Code:
#include <SD.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include "I2Cdev.h"
#include "MPU6050.h"

SoftwareSerial gpsSerial(6, 5); // RX, TX (TX not used)
const int sentenceSize = 312;
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

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()
{
  Wire.begin();
  Serial.begin(38400);
  gpsSerial.begin(38400);
 
  Serial.println("Iniciando MPU");
  accelgyro.initialize();
  Serial.println("Iniciando SD");
  // 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("Fallo de SD");
    return;
  }
  Serial.println("Inicio Correcto");
  Serial.println("Testeando MPU");
  Serial.println(accelgyro.testConnection() ? "Conexion MPU6050 exitosa" : "Error de Conexion a MPU");
 
 
  // 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);
      accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  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");
   
    Serial.print("Long: ");
    getField(field, 5);  // number
    Serial.print(field);
    logfile.print(field);
    logfile.print("\t");

    Serial.print("Velocidad: ");
    getField(field, 7);
    Serial.print(field);
    logfile.print(field);
   
    Serial.print("a/g:\t");
    Serial.print(ax); Serial.print("\t");
    logfile.print(ax);
    logfile.print("\t");
    Serial.print(ay); Serial.print("\t");
    logfile.print(ay);
    logfile.print("\t");
    Serial.print(az); Serial.print("\t");
    logfile.print(az);
    logfile.print("\t");
    Serial.print(gx); Serial.print("\t");
    logfile.print(gx);
    logfile.print("\t");
    Serial.print(gy); Serial.print("\t");
    logfile.print(gy);
    logfile.print("\t");
    Serial.println(gz);
    logfile.println(gz);
    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 changing this value in the line // const int sentenceSize = 312; the sketch woks better or worse according that value, nontheless it always log in some point a line of data with strange characters.
Like this

115948.000   2400.0000   12100.0000   000.0-5948   2372   -15384   -266   70   -1
115948.200   24˜0.0000   12100.0000   000.0-6132   2260   -15532   -235   35   -4

The second line has a weir character there, it happens, according to the value, more or less often.
There is anyone who can help with this glitch?
17  Using Arduino / Project Guidance / Re: gps viewer + venus gps on: December 04, 2012, 06:43:12 pm
Code:
Just get to conect the gps to the gps viewer, now I put it in 10hz and it gets to 38400 of baudrate, now my problem is that I can`t get to work with arduino, does anyone have any clue for this?

#include <SD.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include "I2Cdev.h"
#include "MPU6050.h"

SoftwareSerial gpsSerial(6, 5); // RX, TX (TX not used)
const int sentenceSize = 80;

MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

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()
{
  Wire.begin();
  Serial.begin(38400);
  gpsSerial.begin(38400);
 
  Serial.println("Iniciando MPU");
  accelgyro.initialize();
  Serial.println("Iniciando SD");
  // 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("Fallo de SD");
    return;
  }
  Serial.println("Inicio Correcto");
  Serial.println("Testeando MPU");
  Serial.println(accelgyro.testConnection() ? "Conexion MPU6050 exitosa" : "Error de Conexion a MPU");
 
 
  // 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;
     char field[20];
      getField(field, 0);
      accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  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.print(field);
    logfile.print(field);
   
    Serial.print("a/g:\t");
    Serial.print(ax); Serial.print("\t");
    logfile.print(ax);
    logfile.print("\t");
    Serial.print(ay); Serial.print("\t");
    logfile.print(ay);
    logfile.print("\t");
    Serial.print(az); Serial.print("\t");
    logfile.print(az);
    logfile.print("\t");
    Serial.print(gx); Serial.print("\t");
    logfile.print(gx);
    logfile.print("\t");
    Serial.print(gy); Serial.print("\t");
    logfile.print(gy);
    logfile.print("\t");
    Serial.println(gz);
    logfile.println(gz);
    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';
}
/code]

it logs but only a few lines, then it jumps to another file.
18  Using Arduino / Project Guidance / Re: gps viewer + venus gps on: November 30, 2012, 02:03:27 pm
One more thing, my gps is conected to mi arduino uno in pins 5 and 6 as tx an rx, to conect to the gps viewer I just have to conect mi arduino to my pc and then in the gps viewer select the serial port that my arduino is conected to right?
19  Using Arduino / Project Guidance / Re: gps viewer + venus gps on: November 30, 2012, 01:59:48 pm
Thanks a lot for the information
20  Using Arduino / Project Guidance / Re: gps viewer + venus gps on: November 30, 2012, 10:49:57 am
Can you guide me please to do it, since I don`t have a clue.
21  Using Arduino / Networking, Protocols, and Devices / Re: Gps logger on: November 29, 2012, 10:31:02 pm
And why is that?
22  Using Arduino / Project Guidance / gps viewer + venus gps on: November 29, 2012, 06:17:03 pm
Does anyone know how to conect and cofigure the venus gps in 10 hz with the gps viewer?
23  Using Arduino / Project Guidance / Re: Gps logger 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

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;
     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?
24  Using Arduino / Networking, Protocols, and Devices / Re: Gps logger on: November 29, 2012, 06:10:25 pm
I have solved the problem, I just moved the function void gpsdisplay into the void loop and replace the logfile.close() with the function logfile.flush().
Now it works just fine, thank to all for the help.

Here is the code for anyone to use it

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;
     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';
}
25  Using Arduino / Project Guidance / Re: Gps logger 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.
26  Using Arduino / Networking, Protocols, and Devices / Re: Gps logger on: November 29, 2012, 10:52:27 am
If I do that, it will log several files with diferent names with only one line of data, I have allready tryed.
27  Using Arduino / Project Guidance / Re: Gps logger on: November 29, 2012, 10:39:36 am
Code:
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';
} ]
28  Using Arduino / Project Guidance / Re: Gps logger on: November 28, 2012, 04:27:40 pm
ok, thaks a lot for your time
29  Using Arduino / Project Guidance / Re: Gps logger on: November 28, 2012, 04:23:00 pm
same result, it logs only the first line
30  Using Arduino / Project Guidance / Re: Gps logger on: November 28, 2012, 04:12:53 pm
no, nothing at all, just logs the filename with nothing on it
Pages: 1 [2] 3