GPS logger


           Se trata simplemente de un módulo receptor de GPS, un Arduino Pro Mini y una lectora de tarjetas micro SD. Todos los elementos son para 3,3 voltios. Los alimentos con una pila de litio reciclada de 3,7 voltios sin problemas.
         Todas las conexiones entre los elementos son las estandar y están especificadas en el programa del Arduino que pongo al final.

          La comunicación del GPS es por puerto serie que para no usar el normal del Arduino, he usado uno por soft.


                           Estas son los pines del GPS  
Todo el montaje "empaquetado"
Registro de un recorrido en coche
#include <SPI.h>
#include <SD.h>
//SD card: MOSI - pin 11  MISO - pin 12 CLK - pin 13 CS - pin 4
const int chipSelect = 4;
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps;
SoftwareSerial ss(5, 6);  //Rx y Tx El Rx del GPS no es necesario conectarlo

int nPoint=0;
char sLat[10]; char sLng[10];
char sAlt[10];char sVel[10];
char sCur[10];
char sAge[10];
String sNMEA = "";

void setup()
{
  Serial.begin(9600);
  ss.begin(9600);

  //Serial.print("Initializing SD card...");
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  //Serial.println("card initialized."); 
  Serial.println("time,latitude,longitude,elevation,speed,course,name,date");
  sNMEA="time,latitude,longitude,elevation,speed,course,name,date";
  DatosASD(); //Graba cabecera
  sNMEA = "";
  smartDelay(4000); //Estabiliza recepcion
}

void loop(){
nPoint++;
sNMEA = "";
dtostrf(gps.location.lat(), 9, 6, sLat);
dtostrf(gps.location.lng(), 9, 6, sLng);
dtostrf(gps.altitude.meters(), 5, 2, sAlt);
dtostrf(gps.speed.kmph(), 5, 2, sVel);
dtostrf(gps.course.deg(), 5, 2, sCur);
sNMEA.concat(gps.time.value());                //tiempo hhmmsscc
sNMEA=sNMEA.substring(0, 6); sNMEA=(sNMEA+",");  //pasa a tiempo hhmmss
sNMEA.concat(sLat); sNMEA=(sNMEA+","); sNMEA.concat(sLng); sNMEA=(sNMEA+",");  //Latitud y longitud
sNMEA.concat(sAlt); sNMEA=(sNMEA+","); sNMEA.concat(sVel); sNMEA=(sNMEA+","); //Altitud y Velocidad
sNMEA.concat(sCur); sNMEA=(sNMEA+",");
sNMEA=(sNMEA+"Punto " + nPoint);sNMEA=(sNMEA+",");
sNMEA.concat(gps.date.value());
// Serial.print(sNMEA);
// Serial.println();


//GRABA DATOS A LA SD
if ((gps.location.lat(), 9, 6) > 0 && gps.satellites.value() >3) {
  DatosASD();
  Serial.print("Datos grabados con satelites: ");
  Serial.println(gps.satellites.value());
}
else{
  Serial.print("Datos no grabados. Pocos satelites: ");
  Serial.println(gps.satellites.value());
}
smartDelay(10000);  //grabar datos cada x segundos
}

// delay() que asegura recibir datos no troceados
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}


void DatosASD(){
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.println(sNMEA);
    dataFile.close();
    // print to the serial port too:
    Serial.println(sNMEA);
  }
  else {
    Serial.println("error opening datalog.txt");
  } 
Menu