Javascript API/GPS data logger test

CaptureAn example of a KML I made using an Arduino hooked up to a data logger and a GPS module(MTK3339) from Adafruit. I turned it on when I went to/from work, the accuracy is pretty good for something that was still on a breadboard, in a box, and with no external antenna attached.
http://www.benty.org/Java/java2.html

I made up a little Fritzing schematic, not shown in this is the SD Datalogger shield from Adafruit, since there’s no schematic for it in Fritzing. The datalogging shield sits right on top of the Arduino so the connections are all the same.

Parts list:
Arduino Uno
SD Datalogging Shield
MTK3339 GPS module(There’s also a breakout board for this that would make the connections easier, since the pads on the sensor are small and solderings a bit difficult)
TMP36 analog temp sensor
Parallax Serial LCD(has 3 connections, RX/Vin/GND)
6XAA battery holder

gps_breadboarding_bb gps_logger

Here’s the code I used, I added in some comments but haven’t cleaned out the junk code I used when testing. The code calling the analog pin can be removed if there’s no temperature sensor
attached.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <TinyGPS++.h>
#include
#include
#include
#include <avr/sleep.h>

static const int RXPin =0, TXPin = 1; //Tx and Rx connected to the GPS module.
static const uint32_t GPSBaud = 9600;
const int TxLcdPin = 6;

#define tempPin 1 // analog 1
#define BANDGAPREF 14 // special indicator that we want to measure the bandgap
#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter!
#define bandgap_voltage 1.1 // this is not super guaranteed but its not -too- off
SoftwareSerial mySeriallcd = SoftwareSerial(255, TxLcdPin); //Using software serial to connect to the Parallax Serial LCD(on pin 6 of the arduino)

TinyGPSPlus gps;
const int chipSelect = 10; //Chip select for the Adafruit datalogging shield http://www.adafruit.com/products/1141
float temperatureF;

SoftwareSerial ss(RXPin, TXPin);

void setup()
{
pinMode(TxLcdPin, OUTPUT); //Set the Tx pin for the LCD to high
digitalWrite(TxLcdPin, HIGH);
mySeriallcd.begin(9600);
Serial.begin(115200);
ss.begin(GPSBaud);
pinMode(10, OUTPUT); //Set the output to the SD datalogging shield to pin 10
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");

return;
}
Serial.println("card initialized."); //code from the TinyGPS ++ library
Serial.println(F("FullExample.ino"));
Serial.println(F("An extensive example of many interesting TinyGPS++ features"));
Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
Serial.println(F("by Mikal Hart"));
Serial.println();
Serial.println(F("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum"));
Serial.println(F(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail"));
Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}

void printGPS()
{
pinMode(TxLcdPin, OUTPUT);
digitalWrite(TxLcdPin, HIGH);
mySeriallcd.write(12); //Clears the LCD screen, part of the LCD library for the parallax LCD

mySeriallcd.print("Lat ");mySeriallcd.println(gps.location.lat(),4); //Printing to the LCD
mySeriallcd.write(13); //Moves the cursor to the next line, using just the println caused some randomness with the LCD
mySeriallcd.print("Lon ");mySeriallcd.println(gps.location.lng(),4);
delay(2000);

}

void getTemp() { //The Adafruit datalogging shield came with a temperature sensor, I left it in for this
analogRead(tempPin);
int tempReading = analogRead(tempPin); //Read the analog pin connected to the sensor
float voltage = tempReading * aref_voltage / 1024;
float temperatureC = (voltage - 0.5) * 100 ;
temperatureF = (temperatureC * 9 / 5) + 32;

}

void loop()
{
getTemp(); //Call the getTemp function
String dataString = "";
File dataFile = SD.open("datalog.txt", FILE_WRITE);
//The below prints to the serial monitor for debugging
printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
printInt(gps.location.age(), gps.location.isValid(), 5);
printDateTime(gps.date, gps.time);
printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.value()) : "*** ", 6);
float mylat=gps.location.lat();
float mylon=gps.location.lng();

printGPS();
if (dataFile){ //If the datalogging shield is found, writes to the card.
//This output creates a new placemark for every GPS point taken. This could be done once the data is taken
//off the SD card and plopped on the PC, but I just did it here. The needs to be added to the
//text file before saving as a KML
dataFile.print("");dataFile.print("");dataFile.print(temperatureF);
dataFile.print("");
dataFile.print("");dataFile.print("");
dataFile.print(gps.location.lng(),7);dataFile.print(",");
dataFile.print(gps.location.lat(),7);dataFile.print(",");
dataFile.print(gps.altitude.meters(),7);dataFile.print("");
dataFile.print("");
dataFile.println("");
dataFile.close();
Serial.print(mylat);Serial.print(" mylat ");Serial.println(temperatureF);
}else {
Serial.println("error opening datalog.txt");
}

printInt(gps.charsProcessed(), true, 6);
printInt(gps.sentencesWithFix(), true, 10);
printInt(gps.failedChecksum(), true, 9);
Serial.println();

smartDelay(1000);

if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F("No GPS data received: check wiring"));
}

// The below functions are not needed if just writing to the datalogger as they're only used in printing to the serial
//monitor
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms); } static void printFloat(float val, bool valid, int len, int prec) { if (!valid) { while (len-- > 1)
Serial.print('*');
Serial.print(' ');
}
else
{
Serial.print(val, prec);
int vi = abs((int)val);
int flen = prec + (val < 0.0 ? 2 : 1); // . and - flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i<len; ++i)
Serial.print(' ');
}
smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
char sz[32] = "*****************";
if (valid)
sprintf(sz, "%ld", val);
sz[len] = 0;
for (int i=strlen(sz); i<len; ++i) sz[i] = ' '; if (len > 0)
sz[len-1] = ' ';
Serial.print(sz);
smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
if (!d.isValid())
{
Serial.print(F("********** "));
}
else
{
char sz[32];
sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
Serial.print(sz);
}

if (!t.isValid())
{
Serial.print(F("******** "));
}
else
{
char sz[32];
sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
Serial.print(sz);
}

printInt(d.age(), d.isValid(), 5);
smartDelay(0);
}

static void printStr(const char *str, int len)
{
int slen = strlen(str);
for (int i=0; i<len; ++i)
Serial.print(i smartDelay(0);
}

You may also like...