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.