4 SENSORS + GPS LOGGER SHIELD

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cbausmart
 
Posts: 8
Joined: Wed Nov 21, 2012 7:34 pm

4 SENSORS + GPS LOGGER SHIELD

Post by cbausmart »

GPS) and some sensors. I have followed all the adafruit tutorials, and the GPS works perfectly, and I can log the data in the SD card. But I don't know how to add the sensor data logging in the code. (I'm not very good at writing Arduino code). I have been following some other Arduino codes I found around in the net, but they are not updated. When I tried to compile the sketch with the new arduino 1.0.2 version it says That "Serialprint" strings have to be changed. and I don't know very well how to deal with that... CAN ANY BODY HELP ME, AND GIVE ME SOME CLUES!
I would be grateful!

This is the code i'm following:

Code: Select all

 uint8_t sensorCount = 4; //numero de sensores analogicos a loguear

// Librerias para la SD
#include <SdFat.h>
#include <SdFatUtil.h>
#include <avr/pgmspace.h>

#define isdigit(x) ( x >= '0' && x <= '9')

//extern uint16_t _end;

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile f;

#define led1Pin 2          // LED de estado en el pin 7
 

#define BUFFSIZE 73         // se mete en el buffer una sentencia NMEA cada vez, 73bytes es mas grande que la longitud maxima
char buffer[BUFFSIZE];      
char buffer2[12];

uint8_t bufferidx = 0;
uint32_t tmp;

//////////////CONFIGURACION DEL MODULO GPS (VER MANUAL DE REFERENCIA NMEA)///////////////////////////
#define LOG_RMC  1      // Datos de localizacion esenciales RMC
#define RMC_ON   "$PSRF103,4,0,1,1*21\r\n"  // BANNED que se manda para activar RMC (1 hz)
#define RMC_OFF  "$PSRF103,4,0,0,1*20\r\n"  // BANNED que se manda para desactivar RMC

#define LOG_GGA  0      // contains fix, hdop & vdop data
#define GGA_ON   "$PSRF103,0,0,1,1*25\r\n"   // BANNED que se manda para activar GCA (1 hz)
#define GGA_OFF  "$PSRF103,0,0,0,1*24\r\n"   // BANNED que se manda para desactivar GGA

#define LOG_GSA 0      // satellite data
#define GSA_ON   "$PSRF103,2,0,1,1*27\r\n"   // BANNED que se manda para activar GSA (1 hz)
#define GSA_OFF  "$PSRF103,2,0,0,1*26\r\n"   // BANNED que se manda para desactivar GSA

#define LOG_GSV  0      // detailed satellite data
#define GSV_ON   "$PSRF103,3,0,1,1*26\r\n"  // BANNED que se manda para activar GSV (1 hz)
#define GSV_OFF  "$PSRF103,3,0,0,1*27\r\n"  // BANNED que se manda para desactivar GSV

#define LOG_GLL 0      // Loran-compatibility 

#define USE_WAAS   1     // Util para conseguir mas precision, pero mas BANNED y consume mas bateria
#define WAAS_ON    "$PSRF151,1*3F\r\n"       // BANNED que se manda para activar WAAS
#define WAAS_OFF   "$PSRF151,0*3E\r\n"       // BANNED que se manda para desactivar WAAS

#define LOG_RMC_FIXONLY 1  // loguear solo cuando tenemos la posicion fijada en el RMC?
uint8_t fix = 0; // dato actual de fijacion de posicion
//////////////////////////////////////////////////////////////////////////////////////////////////////
// macros to use PSTR
#define putstring(str) SerialPrint_P(PSTR(str))
#define putstring_nl(str) SerialPrintln_P(PSTR(str))

// lee un valor hexadecimal y devuelve su valor decimal
uint8_t parseHex(char c) {
    if (c < '0')  return 0;
    if (c <= '9') return c - '0';
    if (c < 'A')  return 0;
    if (c <= 'F') return (c - 'A')+10;
}

uint8_t i;

// Parpadea el LED si hay un error
void error(uint8_t errno) {
  if (card.errorCode()) {
    putstring("Error en la SD: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
   while(1) {
     for (i=0; i<errno; i++) {    
       digitalWrite(led1Pin, HIGH);
       Serial.println("error");
       delay(100);
       digitalWrite(led1Pin, LOW);     
       delay(100);
     }
     for (; i<10; i++) {
       delay(200);
     }      
   } 
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
  Serial.begin(4800);  //a esta frecuencia funciona el GPS
  pinMode(10, OUTPUT); //esencial para que funcione la microSD shield !!!
  putstring_nl("GPSlogger BricoGeek");
  pinMode(led1Pin, OUTPUT);      // sets the digital pin as output
   pinMode(13, OUTPUT); 
  if (!card.init()) {
    putstring_nl("La inicializacion de la SD ha fallado!"); 
    error(1);
  }
  if (!volume.init(card)) {
    putstring_nl("No hay particion!"); 
    error(2);
  }
  if (!root.openRoot(volume)) {
        putstring_nl("No se puede abrir el directorio raiz"); 
    error(3);
  }
  strcpy(buffer, "GPSLOG00.CSV"); //empezara a escribir en 00, si ya hay un archivo previo incrementa la cuenta
  for (i = 0; i < 100; i++) {
    buffer[6] = '0' + i/10;
    buffer[7] = '0' + i%10;
    if (f.open(root, buffer, O_CREAT | O_EXCL | O_WRITE)) break;
  }
  
  if(!f.isOpen()) {
    putstring("No se ha podido crear "); Serial.println(buffer);
    error(3);
  }
  putstring("escribiendo en "); Serial.println(buffer);
  putstring_nl("Preparado!");

  // escritura de la cabecera
  if (sensorCount > 6) sensorCount = 6;
  strncpy_P(buffer, PSTR("time,lat,long,speed,date,sens0,sens1,sens2,sens3,sens4,sens5"), 24 + 6*sensorCount);
  Serial.println(buffer);
  // clear print error
  f.writeError = 0;
  f.println(buffer);
  if (f.writeError || !f.sync()) {
    putstring_nl("no se pudo escribir la cabecera!");
    error(5);
  }
  
  delay(1000);
//Aqui se hace la configuracion del gps que definimos mas arriba
   putstring("\r\n");
#if USE_WAAS == 1 
   putstring(WAAS_ON); // on WAAS
#else
  putstring(WAAS_OFF); // on WAAS
#endif

#if LOG_RMC == 1
  putstring(RMC_ON); // on RMC
#else
  putstring(RMC_OFF); // off RMC
#endif

#if LOG_GSV == 1 
  putstring(GSV_ON); // on GSV
#else
  putstring(GSV_OFF); // off GSV
#endif

#if LOG_GSA == 1
  putstring(GSA_ON); // on GSA
#else
  putstring(GSA_OFF); // off GSA
#endif

#if LOG_GGA == 1
 putstring(GGA_ON); // on GGA
#else
 putstring(GGA_OFF); // off GGA
#endif
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()                     
{
  //Serial.println(Serial.available(), DEC);
  char c;
  uint8_t sum;
  
  // lee una linea NMEA del GPS
  if (Serial.available()) {
    c = Serial.read();
    //Serial.print(c, BYTE);
    if (bufferidx == 0) {
      while (c != '$')
        c = Serial.read(); // espera que nos llegue un $
    }
    buffer[bufferidx] = c;

    //Serial.print(c, BYTE);
    if (c == '\n') {
      //putstring_nl("EOL");
      //Serial.print(buffer);
      buffer[bufferidx+1] = 0; // termina
     
      if (buffer[bufferidx-4] != '*') {
        // no hay checksum?
        Serial.print('*', BYTE);
        bufferidx = 0;
        return;
      }
      // calcula checksum
      sum = parseHex(buffer[bufferidx-3]) * 16;
      sum += parseHex(buffer[bufferidx-2]);
      
      // comprueba checksum 
      for (i=1; i < (bufferidx-4); i++) {
        sum ^= buffer[i];
      }
      if (sum != 0) {
        //putstring_nl("error de checksum");
        Serial.print('~', BYTE);
        bufferidx = 0;
        return;
      }
      // tenemos datos!
      //Serial.println(buffer);
      if (strstr(buffer, "GPRMC")) {
        // buscamos si tenemos la posicion fijada
        char *p = buffer;
        p = strchr(p, ',')+1;
        p = strchr(p, ',')+1;       // vamos a el tercer dato
        
        if (p[0] == 'V') {
          digitalWrite(led1Pin, LOW);  // no tenemos fijada la posicion
          fix = 0;
        } 
        else {
          digitalWrite(led1Pin, HIGH); // tenemos fijada la posicion
          fix = 1;
        }
      }

#if LOG_RMC_FIXONLY
      if (!fix) {
          Serial.print('_', BYTE); //aqui esperamos si lo hemos configurado para que solo coja datos con la posicion fijada
          bufferidx = 0;
          return;
      } 
#endif
      
      Serial.println();
      Serial.print("Secuencia NMEA recibida: ");
      Serial.print(buffer);
  
      // buscando los datos
      // encuentra el tiempo
      char *p = buffer;
      p = strchr(p, ',')+1;
      buffer[0] = p[0];
      buffer[1] = p[1];
      buffer[2] = ':';
      buffer[3] = p[2];
      buffer[4] = p[3];
      buffer[5] = ':';
      buffer[6] = p[4];
      buffer[7] = p[5];
      // ignoramos milisegundos
      buffer[8] = ',';
      
      p = strchr(buffer+8, ',')+1;

      p = strchr(p, ',')+1;
      // encuentra latitud
      p = strchr(p, ',')+1;

      buffer[9] = '+';
      buffer[10] = p[0];
      buffer[11] = p[1];
      buffer[12] = ' ';
      strncpy(buffer+13, p+2, 7);
      buffer[20] = ',';
      
      p = strchr(buffer+21, ',')+1;
      if (p[0] == 'S')
        buffer[9] = '-';
      
      // encuentra longitud
      p = strchr(p, ',')+1;
      buffer[21] = '+';
      buffer[22] = p[0];
      buffer[23] = p[1];
      buffer[24] = p[2];
      buffer[25] = ' ';
      strncpy(buffer+26, p+3, 7);
      buffer[33] = ',';
      
      p = strchr(buffer+34, ',')+1;
      if (p[0] == 'W')
        buffer[21] = '-';
      
      // encuentra velocidad
      p = strchr(p, ',')+1;
      tmp = 0;
      if (p[0] != ',') {
        // convertimos la velocidad (viene en nudos)
        while (p[0] != '.' && p[0] != ',') {
          tmp *= 10;
          tmp += p[0] - '0';
          p++;       
        }
        tmp *= 10;
        if (isdigit(p[1])) 
          tmp += p[1] - '0';
        tmp *= 10;
        if (isdigit(p[2])) 
        tmp += p[2] - '0';

        tmp *= 185; //la convertimos en km/h


      } 
      tmp /= 100;
      
      buffer[34] = (tmp / 10000) + '0';
      tmp %= 10000;
      buffer[35] = (tmp / 1000) + '0';
      tmp %= 1000;
      buffer[36] = (tmp / 100) + '0';
      tmp %= 100;
      buffer[37] = '.';
      buffer[38] = (tmp / 10) + '0';
      tmp %= 10;
      buffer[39] = tmp + '0';
       
      buffer[40] = ',';
      p = strchr(p, ',')+1;
      // skip past bearing
      p = strchr(p, ',')+1;
      //mod para evitar problemas cuando falta algun dato (bill greiman)
      uint8_t date[6];
      for (uint8_t id = 0; id < 6; id++) date[id] = p[id];
      // formatea la fecha asi 2001-01-31
      buffer[41] = '2';
      buffer[42] = '0';  // en el año 2100 esto no funcionara XD
      buffer[43] = date[4];
      buffer[44] = date[5];
      buffer[45] = '-';
      buffer[46] = date[2];
      buffer[47] = date[3];
      buffer[48] = '-';
      buffer[49] = date[0];
      buffer[50] = date[1];
      buffer[51] = 0;
 
      if(f.write((uint8_t *) buffer, 51) != 51) {
         putstring_nl("no se ha podido escribir fix!");
	       return;
      }
      Serial.print("Datos escritos en la SD: ");
      Serial.print(buffer);
      
      f.writeError = 0;      
///////////////////////////////////////////////AQUI SE AÑADE LA INFORMACION DE LOS SENSORES///////////////////////////////////////////////////////////////////////////////////////////////////////////////
      for (uint8_t ia = 0; ia < sensorCount; ia++) {
        Serial.print(',');   //escribimos por serie
        f.print(',');        //escribimos en el archivo
        uint16_t data = analogRead(ia);
        Serial.print(data);  //escribimos por serie
        f.print(data);       //escribimos en el archivo
      }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////      
      
      Serial.println();
      f.println();
      if (f.writeError || !f.sync()) {
         putstring_nl("no se ha podido escribir el dato!");
         error(4);
      }
      bufferidx = 0;
      return;
    }
    bufferidx++;
    if (bufferidx == BUFFSIZE-1) {
       Serial.print('!', BYTE);
       bufferidx = 0;
    }
  }
}
 

User avatar
cbausmart
 
Posts: 8
Joined: Wed Nov 21, 2012 7:34 pm

Re: 4 SENSORS + GPS LOGGER SHIELD

Post by cbausmart »

Surfing around I have found this tutorial, but it has the same problem with the code. Is not updated. How could I mix the GPS data logging code, with this one showed at this tutorial?? http://www.ladyada.net/make/logshield/lighttemp.html

Thanks for your attention!!

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: 4 SENSORS + GPS LOGGER SHIELD

Post by adafruit_support_bill »

If you post the exact text of the error message, it will be easier for us to figure out the problem.

User avatar
cbausmart
 
Posts: 8
Joined: Wed Nov 21, 2012 7:34 pm

Re: 4 SENSORS + GPS LOGGER SHIELD

Post by cbausmart »

That is the text of error message. It looks like a version of Ladyada's logger modified by Bill Greiman to use the SdFat library...



In file included from BricoGeek_SdFatGPS_CSVSensorLogger.ino:16:
C:\Arduino-1.0.2\libraries\SdFat/SdFat.h:294: error: conflicting return type specified for 'virtual void SdFile::write(uint8_t)'
C:\Arduino-1.0.2\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
BricoGeek_SdFatGPS_CSVSensorLogger.ino: In function 'void loop()':
BricoGeek_SdFatGPS_CSVSensorLogger:212: error: 'BYTE' was not declared in this scope

As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.

BricoGeek_SdFatGPS_CSVSensorLogger:226: error: 'BYTE' was not declared in this scope

As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.

BricoGeek_SdFatGPS_CSVSensorLogger:250: error: 'BYTE' was not declared in this scope

As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.

BricoGeek_SdFatGPS_CSVSensorLogger:389: error: 'BYTE' was not declared in this scope

As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.
Attachments
ERROR ARDUINO.jpg
ERROR ARDUINO.jpg (155.81 KiB) Viewed 2003 times

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: 4 SENSORS + GPS LOGGER SHIELD

Post by adafruit_support_bill »

Are you using the most recent version of the SD library? https://github.com/adafruit/SD
It was updated for Arduino 1.0 some time ago.

User avatar
cbausmart
 
Posts: 8
Joined: Wed Nov 21, 2012 7:34 pm

Re: 4 SENSORS + GPS LOGGER SHIELD

Post by cbausmart »

yes! I did it, but the problem still remain in the Serial.print('*', BYTE) sentence... How can I migrate it, (in order to make it work in the new arduino version)?. The arduino website says that I have to chenge the 'BYTE' keyword because is no longer supported, and I have to use Serial.write() instead. I found several websites where they tell you to change it writing instead...

- Serial.print(0, BYTE) by Serial.write( byte(0) )
- Serial.print(1, BYTE) by Serial.write( byte(1) )
- and all Serial.print(xxxx, BYTE) by Serial.write(xxxx).

I tried all this sentences but It doesn't work.

how can I migrate this sentence?? Serial.print('*', BYTE)

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: 4 SENSORS + GPS LOGGER SHIELD

Post by adafruit_support_bill »

Make sure you only have one copy of the SD library. Check both your sketchbook "Libraries" folder and the "Libraries" folder in your Arduino install. It is not sufficient to rename the folder. You must remove the unused library.

User avatar
cbausmart
 
Posts: 8
Joined: Wed Nov 21, 2012 7:34 pm

Re: 4 SENSORS + GPS LOGGER SHIELD

Post by cbausmart »

Done! I have even re-installed Arduino. I delleted the SD old library folder And I have pasted the new version of it...

And Still have the same error, :(

what else coul I do with the "BYTE" sentence ?

User avatar
cbausmart
 
Posts: 8
Joined: Wed Nov 21, 2012 7:34 pm

Re: 4 SENSORS + GPS LOGGER SHIELD

Post by cbausmart »

ok! I have read the post "HOWTO get help with your arduino project" and I will remake my question to solve my doubts....

I have this part of one code that allows you to store simple sensor data into an SD card... and...

Code: Select all

      for (uint8_t ia = 0; ia < sensorCount; ia++) {
        Serial.print(',');   //escribimos por serie
        f.print(',');        //escribimos en el archivo
        uint16_t data = analogRead(ia);
        Serial.print(data);  //escribimos por serie
        f.print(data);       //escribimos en el archivo
      }
////////////////////////////////////////////////////////////////////////////////////////    
      
      Serial.println();
      f.println();
      if (f.writeError || !f.sync()) {
         putstring_nl("no se ha podido escribir el dato!");
         error(4);
      }
      bufferidx = 0;
      return;
    }
    bufferidx++;
    if (bufferidx == BUFFSIZE-1) {
       Serial.print('!', BYTE);
       bufferidx = 0;
    }
  }
}
... what I want is to add it to the Ladyada's "SD-Basic-GPS-logger-master"

Code: Select all

// Ladyada's logger modified by Bill Greiman to use the SdFat library

// this is a generic logger that does checksum testing so the data written should be always good
// Assumes a sirf III chipset logger attached to pin 2 and 3

#include <SD.h>
#include <avr/sleep.h>
#include "GPSconfig.h"

// If using Arduino IDE prior to 1.0,
// make sure to install newsoftserial from Mikal Hart
// http://arduiniana.org/libraries/NewSoftSerial/
#if ARDUINO >= 100
 #include <SoftwareSerial.h>
#else
 #include <NewSoftSerial.h>
#endif

// power saving modes
#define SLEEPDELAY 0    /* power-down time in seconds. Max 65535. Ignored if TURNOFFGPS == 0 */
#define TURNOFFGPS 0    /* set to 1 to enable powerdown of arduino and GPS. Ignored if SLEEPDELAY == 0 */
#define LOG_RMC_FIXONLY 0  /* set to 1 to only log to SD when GPD has a fix */

// what to log
#define LOG_RMC 1 // RMC-Recommended Minimum Specific GNSS Data, message 103,04
#define LOG_GGA 0 // GGA-Global Positioning System Fixed Data, message 103,00
#define LOG_GLL 0 // GLL-Geographic Position-Latitude/Longitude, message 103,01
#define LOG_GSA 0 // GSA-GNSS DOP and Active Satellites, message 103,02
#define LOG_GSV 0 // GSV-GNSS Satellites in View, message 103,03
#define LOG_VTG 0 // VTG-Course Over Ground and Ground Speed, message 103,05



// Use pins 2 and 3 to talk to the GPS. 2 is the TX pin, 3 is the RX pin
#if ARDUINO >= 100
 SoftwareSerial gpsSerial =  SoftwareSerial(2, 3);
#else
 NewSoftSerial gpsSerial =  NewSoftSerial(2, 3);
#endif
// Set the GPSRATE to the baud rate of the GPS module. Most are 4800
// but some are 38400 or other. Check the datasheet!
#define GPSRATE 4800

// Set the pins used 
#define powerPin 4
#define led1Pin 5
#define led2Pin 6
#define chipSelect 10


#define BUFFSIZE 90
char buffer[BUFFSIZE];
uint8_t bufferidx = 0;
bool fix = false; // current fix data
bool gotGPRMC;    //true if current data is a GPRMC strinng
uint8_t i;
File logfile;

// read a Hex value and return the decimal equivalent
uint8_t parseHex(char c) {
  if (c < '0')
    return 0;
  if (c <= '9')
    return c - '0';
  if (c < 'A')
    return 0;
  if (c <= 'F')
    return (c - 'A')+10;
}

// blink out an error code
void error(uint8_t errno) {
/*
  if (SD.errorCode()) {
    putstring("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  */
  while(1) {
    for (i=0; i<errno; i++) {
      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, HIGH);
      delay(100);
      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, LOW);
      delay(100);
    }
    for (; i<10; i++) {
      delay(200);
    }
  }
}

void setup() {
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = 0;
  Serial.begin(9600);
  Serial.println("\r\nGPSlogger");
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(powerPin, OUTPUT);
  digitalWrite(powerPin, LOW);

  // 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 init. failed!");
    error(1);
  }

  strcpy(buffer, "GPSLOG00.TXT");
  for (i = 0; i < 100; i++) {
    buffer[6] = '0' + i/10;
    buffer[7] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(buffer)) {
      break;
    }
  }

  logfile = SD.open(buffer, FILE_WRITE);
  if( ! logfile ) {
    Serial.print("Couldnt create "); Serial.println(buffer);
    error(3);
  }
  Serial.print("Writing to "); Serial.println(buffer);
  
  // connect to the GPS at the desired rate
  gpsSerial.begin(GPSRATE);
  
  Serial.println("Ready!");
  
  gpsSerial.print(SERIAL_SET);
  delay(250);

#if (LOG_DDM == 1)
     gpsSerial.print(DDM_ON);
#else
     gpsSerial.print(DDM_OFF);
#endif
  delay(250);
#if (LOG_GGA == 1)
    gpsSerial.print(GGA_ON);
#else
    gpsSerial.print(GGA_OFF);
#endif
  delay(250);
#if (LOG_GLL == 1)
    gpsSerial.print(GLL_ON);
#else
    gpsSerial.print(GLL_OFF);
#endif
  delay(250);
#if (LOG_GSA == 1)
    gpsSerial.print(GSA_ON);
#else
    gpsSerial.print(GSA_OFF);
#endif
  delay(250);
#if (LOG_GSV == 1)
    gpsSerial.print(GSV_ON);
#else
    gpsSerial.print(GSV_OFF);
#endif
  delay(250);
#if (LOG_RMC == 1)
    gpsSerial.print(RMC_ON);
#else
    gpsSerial.print(RMC_OFF);
#endif
  delay(250);

#if (LOG_VTG == 1)
    gpsSerial.print(VTG_ON);
#else
    gpsSerial.print(VTG_OFF);
#endif
  delay(250);

#if (USE_WAAS == 1)
    gpsSerial.print(WAAS_ON);
#else
    gpsSerial.print(WAAS_OFF);
#endif
}

void loop() {
  //Serial.println(Serial.available(), DEC);
  char c;
  uint8_t sum;

  // read one 'line'
  if (gpsSerial.available()) {
    c = gpsSerial.read();
#if ARDUINO >= 100
    //Serial.write(c);
#else
    //Serial.print(c, BYTE);
#endif
    if (bufferidx == 0) {
      while (c != '$')
        c = gpsSerial.read(); // wait till we get a $
    }
    buffer[bufferidx] = c;

#if ARDUINO >= 100
    //Serial.write(c);
#else
    //Serial.print(c, BYTE);
#endif
    if (c == '\n') {
      //putstring_nl("EOL");
      //Serial.print(buffer);
      buffer[bufferidx+1] = 0; // terminate it

      if (buffer[bufferidx-4] != '*') {
        // no checksum?
        Serial.print('*');
        bufferidx = 0;
        return;
      }
      // get checksum
      sum = parseHex(buffer[bufferidx-3]) * 16;
      sum += parseHex(buffer[bufferidx-2]);

      // check checksum
      for (i=1; i < (bufferidx-4); i++) {
        sum ^= buffer[i];
      }
      if (sum != 0) {
        //putstring_nl("Cxsum mismatch");
        Serial.print('~');
        bufferidx = 0;
        return;
      }
      // got good data!

      gotGPRMC = strstr(buffer, "GPRMC");
      if (gotGPRMC) {
        // find out if we got a fix
        char *p = buffer;
        p = strchr(p, ',')+1;
        p = strchr(p, ',')+1;       // skip to 3rd item
        
        if (p[0] == 'V') {
          digitalWrite(led1Pin, LOW);
          fix = false;
        } else {
          digitalWrite(led1Pin, HIGH);
          fix = true;
        }
      }
      if (LOG_RMC_FIXONLY) {
        if (!fix) {
          Serial.print('_');
          bufferidx = 0;
          return;
        }
      }
      // rad. lets log it!
      
      Serial.print(buffer);    //first, write it to the serial monitor
      Serial.print('#');
      
      if (gotGPRMC)      //If we have a GPRMC string
      {
        // Bill Greiman - need to write bufferidx + 1 bytes to getCR/LF
        bufferidx++;

        digitalWrite(led2Pin, HIGH);      // Turn on LED 2 (indicates write to SD)

        logfile.write((uint8_t *) buffer, bufferidx);    //write the string to the SD file
        logfile.flush();
        /*
        if( != bufferidx) {
           putstring_nl("can't write!");
           error(4);
        }
        */

        digitalWrite(led2Pin, LOW);    //turn off LED2 (write to SD is finished)

        bufferidx = 0;    //reset buffer pointer

        if (fix) {  //(don't sleep if there's no fix)
          
          if ((TURNOFFGPS) && (SLEEPDELAY)) {      // turn off GPS module? 
          
            digitalWrite(powerPin, HIGH);  //turn off GPS

            delay(100);  //wait for serial monitor write to finish
            sleep_sec(SLEEPDELAY);  //turn off CPU
  
            digitalWrite(powerPin, LOW);  //turn on GPS
          } //if (TURNOFFGPS) 
         
        } //if (fix)
        
        return;
      }//if (gotGPRMC)
      
    }
    bufferidx++;
    if (bufferidx == BUFFSIZE-1) {
       Serial.print('!');
       bufferidx = 0;
    }
  } else {

  }

}

void sleep_sec(uint16_t x) {
  while (x--) {
     // set the WDT to wake us up!
    WDTCSR |= (1 << WDCE) | (1 << WDE); // enable watchdog & enable changing it
    WDTCSR = (1<< WDE) | (1 <<WDP2) | (1 << WDP1);
    WDTCSR |= (1<< WDIE);
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 //   sleep_enable();
    sleep_mode();
//    sleep_disable();
  }
}

SIGNAL(WDT_vect) {
  WDTCSR |= (1 << WDCE) | (1 << WDE);
  WDTCSR = 0;
}

/* End code */
The question Is: how can I do it? Is it possible you could help me to mix them?
Thank you very much for your attention
Carlos

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”