Hello, this is my code I am using it for a gps, but when verifying I have an error, Could you please help me? I don't know what's wrong.
Here's the code:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>//incluimos SoftwareSerial
#include <TinyGPS.h>//incluimos TinyGPS
#include <SPI.h>
#include <SD.h>
TinyGPS gps;//Declaramos el objeto gps
SoftwareSerial serialgps(4,3);//Declaramos el pin 4 Tx y 3 Rx
//Declaramos la variables para la obtención de datos
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long chars;
unsigned short sentences, failed_checksum;
void setup()
{
And these are the messages that Arduino shows.
In file included from G:\Osvaldo\Trabajos\Tesis\GPS_Prototipe\GPSTiny_SD\GPSTiny_SD.ino:3:0:
C:\Users\Osvaldo\Documents\Arduino\libraries\TinyGPS-13/TinyGPS.h:35:0: warning: "_GPS_VERSION" redefined
#define _GPS_VERSION 13 // software version of this library
^
In file included from G:\Osvaldo\Trabajos\Tesis\GPS_Prototipe\GPSTiny_SD\GPSTiny_SD.ino:1:0:
C:\Users\Osvaldo\Documents\Arduino\libraries\TinyGPSPlus-1.0.2\src/TinyGPS++.h:34:0: note: this is the location of the previous definition
#define _GPS_VERSION "1.0.2" // software version of this library
^
GPSTiny_SD:26: error: 'Serial' does not name a type
Serial.print("Initializing SD card...");
^
GPSTiny_SD:29: error: expected unqualified-id before 'if'
if (!SD.begin(chipSelect)) {
^
GPSTiny_SD:34: error: 'Serial' does not name a type
Serial.println("card initialized.");
^
GPSTiny_SD:35: error: expected declaration before '}' token
}
^
exit status 1
'Serial' does not name a type
Serial.begin(115200);//Iniciamos el puerto serie
serialgps.begin(9600);//Iniciamos el puerto serie del gps
//Imprimimos:
Serial.println("");
Serial.println("GPS GY-GPS6MV2 Leantec");
Serial.println(" ---Buscando senal--- ");
Serial.println("");
}
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:
while (1);
}
Serial.println("card initialized.");
}
void loop()
{
while(serialgps.available())
{
int c = serialgps.read();
if(gps.encode(c))
{
float latitude, longitude;
gps.f_get_position(&latitude, &longitude);
Serial.print("Latitud/Longitud: ");
Serial.print(latitude,5);
Serial.print(", ");
Serial.println(longitude,5);
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
Serial.print("Fecha: "); Serial.print(day, DEC); Serial.print("/");
Serial.print(month, DEC); Serial.print("/"); Serial.print(year);
Serial.print(" Hora: "); Serial.print(hour, DEC); Serial.print(":");
Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);
Serial.print("."); Serial.println(hundredths, DEC);
Serial.print("Altitud (metros): "); Serial.println(gps.f_altitude());
Serial.print("Rumbo (grados): "); Serial.println(gps.f_course());
Serial.print("Velocidad(kmph): "); Serial.println(gps.f_speed_kmph());
Serial.print("Satelites: "); Serial.println(gps.satellites());
Serial.println();
gps.stats(&chars, &sentences, &failed_checksum);
}
}
void sd() {
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
for (gps.f_altitude()> 0; gps.f_altitude() < ; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// 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");
}
}
}