The manufacturer does provide some sample code to help get started: here’s a copy of what’s in the Useful Links document:
#include <SD.h>
const int chipSelect = 10;
void setup()
{
Serial.begin(9600);
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
return;
}
}
void loop()
{
// make a string for assembling the data to log:
char index = 0;
char temp = 0;
String 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.
/*
while(Serial.available())
{
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if(dataFile)
{
temp = Serial.read();
dataString += String(temp);
dataFile.print(dataString);
dataString = "";
dataFile.close();
}
}
*/
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if(dataFile)
{
while(Serial.available())
{
temp = Serial.read();
dataString += String(temp);
index++;
if(index>200)
break;
}
dataFile.print(dataString);
dataFile.close();
}
}
This example is pretty simple and just logs the GPS data to an SD card. If you want to parse the data, you can use the TinyGPS library:
The base example for this board should be something like this:
#include "TinyGPS.h"
TinyGPS gps;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available())
{
int c = Serial.read();
if (gps.en code(c))
{
// process new gps info here
}
}
}
You can then put the code you want where indicated by the comment. The TinyGPS page also has some suggestions of what values you might want to retrieve.
I would like to thank you enormously for your quick reply. Although I really like this GPS there are two small points that bother me a little bit.
I would like the pins (2,3) of the arduino to be left alone as I am using it for another device.
Can I use any other pin for the GPS to communicate with the Arduino ? Can I change the code as below:
[code]#define RXPIN 6 #define TXPIN 7
SoftwareSerial nss(RXPIN, TXPIN)[/code]
Secondly I was looking at the antenna it look very big.
Could you please advice me on a GPS that could communicate with different Arduino pins than the (2,3)? Is there any GPS that can communicate for instance with SPI or IIC interface of the Arduino?
Do you also have an example code for the two GPS boards in the links below:
Glad to help. The GPS shield with EB-365 actually uses pins D0 and D1 for the serial communication, which is why I had changed the code to use the Serial object instead of nss.
The GPS shield, and the two other products you linked all use the standard NMEA protocol, so you can still use the TinyGPS library will all of them, just need to ensure you’re using the right pins for each module. Note however that your two alternate products both use 3.3V serial, so connecting them to the Arduino board would require additional circuits. For the first, you would need something like this shield, and for the other you would need logic level converter.
If you’re looking for a GPS with small antenna, there’s the Adafruit Ultimate GPS Breakout - 66 Channel MTK3339 that has an onboard chip antenna. Note that you need to ensure that it is pointing to the sky, so mounting options are limited.