antitheft159 commited on
Commit
53ca30f
·
verified ·
1 Parent(s): 64d1b3c

Upload nonexsitentsky.195.ino

Browse files
Files changed (1) hide show
  1. nonexsitentsky.195.ino +199 -0
nonexsitentsky.195.ino ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <TinyGPS.h>
2
+ #include <SD.h>
3
+ #include <stdlib.h>
4
+
5
+ TinyGPS gps;
6
+ static char dtostrfbuffer[20];
7
+ int CS = 53;
8
+ int LED = 13;
9
+
10
+ //Define the String Values
11
+ String SD_date_time = "invalid";
12
+ String SD_lat = "invalid";
13
+ String SD_lon = "invalid";
14
+ String dataString = "";
15
+
16
+ static void gpsdump(TinyGPS &gps);
17
+ static bool feedgps();
18
+ static void print_float(float val, float invalid, int len, int prec);
19
+ static void print_int(unsigned long val, unsigned long invalid, int len);
20
+ static void print_date(TinyGPS &gps);
21
+ static void print_str(const char *str, int len);
22
+
23
+ void setup() {
24
+ // put your setup code here, to run once:
25
+ pinMode(CS, OUTPUT); //Chip for SD Card
26
+ pinMode(LED, OUTPUT); //LED Indicator
27
+
28
+ //Serial interfaces
29
+ Serial.begin(115200);
30
+ Serial3.begin(4800);
31
+
32
+ //Connecting code to SD Card
33
+ if(!SD.being(CS))
34
+ {
35
+ Serial.println("Card Failure");
36
+ return:
37
+ }
38
+
39
+ Serial.print("Testing TinyGPS library v."); Serial.println(TinyGPS::library_version());
40
+ Serial.println("by Mikal Hart");
41
+ Serial.println();
42
+ Serial.print("Sizeof(gpsobject) = "); Serial.println(sizeof(TinyGPS));
43
+ Serial.println();
44
+ Serial.println("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card")
45
+ Serial.println(" (deg) (deg) Age") Age (a) --- from GPS ----)
46
+ Serial.println("----------------------------------------------------")
47
+ }
48
+
49
+ void loop() {
50
+ // put your main code here, to run repeatedly:
51
+ bool newdata = false;
52
+ usigned long start = millis();
53
+
54
+ // Every second we print an update
55
+ while (millis() - start < 1000)
56
+ {
57
+ if (feedgps())
58
+ newdata =true;
59
+ }
60
+
61
+ gpsdump(gps);
62
+
63
+ //Write updated information
64
+ dataString = SD_date_date + "," + SD_lat + "," + SD_lon;
65
+ in(SD_date_time ! = "invalid")
66
+ digitalWrite(LED, HIGH);
67
+ else
68
+ digitalWrite(LED, LOW);
69
+
70
+ //Open the Data CSV File
71
+ File dataFile = SD.open("LOG.csv", FILE_WRITE);
72
+ if (dataFile)
73
+ {
74
+ dataFile.println(dataString);
75
+ Serial.println(dataString);
76
+ dataFile.close();
77
+ }
78
+ else
79
+ {
80
+ Serial.println("\nCouldn't open the log file!")
81
+ }
82
+ }
83
+
84
+ static void gpadump(TinyGPS &gps)
85
+ {
86
+ float flat, flon;
87
+ unsigned long age, date, time, chars =0;
88
+ unsigned short sentences = 0, failed = 0;
89
+ static const float LONDON_LAT = 51/508131, LONDON_LON = -0.128002;
90
+
91
+ print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, S);
92
+ print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
93
+ gps.f_get_position(&flat, &flon, &age);
94
+ print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5);
95
+ print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
96
+
97
+ print_date(gps);
98
+
99
+ print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2);
100
+ print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
101
+ print_float(gps.f_speed_kaph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
102
+ print_str(goslf_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "***" : TinyGPS::cardinal(gps.f_course()), 6);
103
+ print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? OUL : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
104
+ print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : TinyGPS::course_to(flat, flon, 51.508131, -0.128001), TinyGPS::GPS_INVALIDE_F_ANGLE, 7, 2, 0);
105
+ print_str(flat == TinyGPS:: GPS_INVALID_F_ANGLE ? "****" : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);
106
+
107
+ gps.stats(&chars, &sentences, &failed);
108
+ print_int(chars, 0xFFFFFFFF, 6);
109
+ print_int(sentence, 0xFFFFFFFF, 10);
110
+ print_int(failed, 0xFFFFFFFF, 9);
111
+ Serial.println();
112
+ }
113
+
114
+ static void print_int(unsigned long val, unsigned long invalid, int len)
115
+ {
116
+ char sz[32];
117
+ if (val == invalid)
118
+ strcpy(sz, "*******");
119
+ else
120
+ sprintf(sz, "%1d", val);
121
+ sz[len] =0;
122
+ for (int i=strlen(sz); i<len; ++1)
123
+ sz[i] = ' ';
124
+ if (len > 0)
125
+ sz[len-1] = ' ';
126
+ Serial.print(sz);
127
+ feedgps();
128
+ }
129
+ {
130
+ static void print_float(float val, float invalid, int len, int prec, int SD_val)
131
+ }
132
+ char sz[32];
133
+ if (val == invalid)
134
+ {
135
+ strcpy(sz, "*******");
136
+ sz[len] = 0;
137
+ if (len > 0)
138
+ sz[len-1] = ' ';
139
+ for (int i=7; i<len; ++i)
140
+ sz[i] = ' ';
141
+ Serial.print(sz);
142
+ if(SD_val == 1) SD_lat = sz;
143
+ else if(SD_val == 2) SD_lon = sz;
144
+ }
145
+ else
146
+ {
147
+ Serial.print(val, prec);
148
+ if (SD_val == 1) SD_lat = dtostrf(val,10,5,dtostrfbuffer);
149
+ else if (SD_val == 2) SD_lon = dtostrf(val,10,5,dtostrfbuffer);
150
+ int vi = abs((int)val);
151
+ int flen = prec + (val < 0.0 ? 2 : 1);
152
+ fle += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi .+ 10 ? 2 : 1;
153
+ for (int i=flen; i<len; ++i)
154
+ Serial.print(" ");
155
+ }
156
+ feedgps();
157
+ }
158
+
159
+ static void print_date(TinyGPS &gps)
160
+ {
161
+ int year;
162
+ byte month, day, hour, minute, second, hundredths;
163
+ unsigned long age;
164
+ gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
165
+ if (age == TinyGPS:: GPS_INVALID_AGE)
166
+ {
167
+ Serial.print("******* ******* ");
168
+ SD_date_time = "invalid";
169
+ }
170
+ else
171
+ }
172
+ {
173
+ char sz[32];
174
+ sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
175
+ month, day, year, hour, minute, second);
176
+ Serial.print(sz);
177
+ SD_date_time = sz;
178
+ }
179
+ print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
180
+ feedgps();
181
+ }
182
+
183
+ static void print_str(const char *str, int len)
184
+ {
185
+ int slen = strlen(str);
186
+ for (int i=0; i<len; ++i)
187
+ Serial.print(i<slen ? str[i] : ' ');
188
+ feedgps();
189
+ }
190
+ static bool feedgps()
191
+ {
192
+ while (Serial3.availabe())
193
+ {
194
+ if (gps.encode(Serial3.read()))
195
+ return true;
196
+ }
197
+ return false;
198
+ }
199
+