ProgGPS
This program can be used with the Firewing GPS shield to log the date, time, position and speed to a card inserted into the shields Secure Digital (SD) slot.
Program Listing
' import gps and sd card modules... imports Gps imports SD ' format time field... function FormatTime(time as string) as string(9) return Mid(time,0,2) + ":" + Mid(time,2,2) + ":" + Mid(time,4,2) end function ' format date field... function FormatDate(date as string) as string(9) return Mid(date,0,2) + "/" + Mid(date,2,2) + "/" + Mid(date,4,2) end function ' typical sentence formats... ' $GPGGA,125554.000,5435.1610,N,00058.6233,W,1,5,2.06,72.2,M,47.3,M,,*72 ' $GPRMC,125554.000,A,5435.1610,N,00058.6233,W,0.05,58.17,041112,,,A*4F Sub Main() dim rmc as string(100) ' RMC sentence const filename = "gps.csv" ' data filename ' delete previous file from SD card, if present... dim sdAvailable as boolean = SD.Init() = errOK if SD.FileExists(filename) then SD.Delete(filename) end if ' now create a new file... if not SD.FileExists(filename) then SD.Create(filename) SD.Close() end if 'loop forever... while true ' have we got an RMC sentence - if yes, process data... if Gps.IsRMCAvailable(rmc) then dim data, bearing, speed as string dim lat,lng as string dim haveLat as boolean = false dim haveLng as boolean = false ' get latitude and longitude in WGS84 format - this format is used ' by most visualisation applications - for example, google earth - note ' that the sentence may be valid but the field may be empty... if Gps.GetField(rmc, 2, data) and Gps.GetField(rmc, 3, bearing) then lat = Gps.ConvertToWGS84(data, bearing(0)) haveLat = true end if if Gps.GetField(rmc, 4, data) and Gps.GetField(rmc, 5, bearing) then lng = Gps.ConvertToWGS84(data, bearing(0)) haveLng = true end if ' if the SD card is available and we have valid (none empty) ' latitude and longitude data... if sdAvailable and haveLat and haveLng then ' get the speed - if the first speed character is greater ' than zero then open the file and record the event... Gps.GetField(rmc, 6, speed) if speed(0) <> "0" and SD.Append(filename) = errOK then ' write the date... Gps.GetField(rmc, 8, data) SD.Write(FormatDate(data), ",") ' write the time... Gps.GetField(rmc, 0, data) SD.Write(FormatTime(data), ",") ' write lat and long... SD.Write(lat, ",", lng, ",") ' now write the speed... SD.Write(speed) ' write end of line and close the file... SD.Write(13,10) SD.Close() end if end if end if end while End Sub


