Drexel's Home Page
Webmail
Drexel One
Google

 

Paul Briedé Jr

       

HOME

RESEARCH

TUTORIALS

RESUME

       

DREXEL SAE AIRLIFT

AVIATION

PICTURES

MISCELLANEOUS


 

Interface GPS module with BS2 for data logging

Background
To be able to use the basic stamp to gather GPS waypoints, there are some connections and programming that is needed. This tutorial will go over what equipment is needed, what devices need to be connected, as well as what code to use to program the stamp. By the end of this tutorial you will be able to connect all equipment to the aircraft, run the stamp, fly the aircraft, and then download the data points to your computer to gather the flight path of the R/C plane.
 

This picture shows the Magpie AP with the stamp and Garmin GPS

 
The article that accompanies this tutorial can be found at http://www.parallax.com/dl/docs/article/rambal-gps.pdf
 
Parts List
Magpie AP
1 Basic Stamp
1 Garmin Etrex Vista
1 Serial Cable
Basic Stamp Software
1 GPS Data Cable
Zip Ties
Sticky Tape
9 Volt Battery
1 Basic Stamp with GPS Datalogger Article
Velcro
 
 
 
Step 1
Read the entire GPS Datalogger article. Understand diagrams and pictures included within the text. Also, read the basic stamp code and understand what it is saying.
 
Step 2
Ignore the code given in the above article. Insert the code below into the main window of the stamp program. I erased the line where it specifies which com port to use. In the Directive dropdown menu in the main window, select the port which you are going to use to run the stamp.

This is the basic stamp code:

' {$STAMP BS2p}
' -----[ Program Description ]---------------------------------------------
'
' This program runs in Slot 0 of a BS2p. When started, it checks to see
' if it can log and starts immediately if possible. If log data already
' exists, it will prompt the user before overwriting.

' -----[ Constants ]-------------------------------------------------------
GPSpin CON 0
RxD CON 16 ' serial input
TxD CON 16 ' serial output
T9600 CON 240 ' 9600-8-N-1 (matches DEBUG)
N4800 CON 16884
LF CON 10 ' linefeed
FirstSlot CON 1
MaxAddr CON 8-FirstSlot*2048-1
FirstAddr CON 2 ' make room for readings
LogTm CON 2 ' four seconds between readings
EST CON -5 ' Eastern Standard Time
CST CON -6 ' Central Standard Time
MST CON -7 ' Mountain Standard Time
PST CON -8 ' Pacific Standard Time
EDT CON -4 ' Eastern Daylight Time
CDT CON -5 ' Central Daylight Time
MDT CON -6 ' Mountain Daylight Time
PDT CON -7 ' Pacific Daylight Time
UTCfix CON PDT
Comma CON ","
DegSym CON 176 ' degrees symbol
MinSym CON 39 ' minutes symbol
SecSym CON 34 ' seconds symbol

' -----[ Variables ]-------------------------------------------------------
readings VAR Word
response VAR Byte
idx VAR Byte ' index into GPS data in SPRAM
flags VAR Byte
valid VAR flags.BIT7
laDeg VAR Byte
laMin VAR Byte
laSec VAR Word ' tenths of seconds
laSLo VAR laSec.LOWBYTE
laSHi VAR laSec.HIGHBYTE
laNS VAR flags.BIT0 ' 0 = N
loDeg VAR Byte
loMin VAR Byte
loSec VAR Word ' tenths of seconds
loSLo VAR loSec.LOWBYTE
loSHi VAR loSec.HIGHBYTE
loEW VAR flags.BIT1 ' 0 = E
eeBase VAR Word
eeAddr VAR Word ' flat EE address
eeData VAR Byte
slot VAR Nib ' pgm slot for storage
addr VAR Word ' address for storage
temp VAR Byte
temp2 VAR Word
rdngNum VAR Word

' -----[ EEPROM Data ]-----------------------------------------------------
'
' -----[ Initialization ]--------------------------------------------------
'
Initialize:
STORE 1
READ 0,readings.LOWBYTE ' retrieve readings from EEPROM
READ 1,readings.HIGHBYTE
IF (readings = 0) THEN Main

Has_Data:
PAUSE 250
DEBUG CLS,"WARNING! - Data (",DEC readings," readings) "
DEBUG "is stored in this device",CR,CR
DEBUG "[1] Clear datalog and start again",CR
DEBUG "[2] Append new data to current log.",CR
DEBUG "[3] Dump datalog to PC",CR,CR,"--> "
SERIN RxD,T9600,[ response]
IF (response < "1") OR (response > "3") THEN Has_Data
BRANCH (response - "1"),[Clear_Log,Main,Dump_Data]
GOTO Has_Data

Clear_Log:
readings = 0
STORE FirstSlot
WRITE 0,0
WRITE 1,0

' -----[ Main Code ]-------------------------------------------------------
Main:
eeAddr = readings * 9
DEBUG CLS,"Logging...",CR,CR

DataLog:
SERIN GPSpin,N4800,[WAIT("$GPRMC"),SPSTR 65]
GOSUB Parse_GPS
' show current reading
DEBUG DEC5 (readings+1),","
DEBUG DEC2 laDeg,":",DEC2 laMin,":"
DEBUG DEC2 laSec / 10,".",DEC1 laSec // 10,Comma
DEBUG "N" + (laNS * 5),Comma
DEBUG DEC3 loDeg,":",DEC2 loMin,":"
DEBUG DEC2 loSec / 10,".",DEC1 loSec // 10,Comma
DEBUG "E" + (loEW * 18)
DEBUG CR
GOSUB Save_Reading
' put delay code here if required
GOTO DataLog
END

' -----[ Subroutines ]-----------------------------------------------------
'
' **********************************************
' Extract Latitude and Longitude from GPS string
' **********************************************
Parse_GPS:

Get_Lat:
GET 10,temp
laDeg = (temp - "0") * 10
GET 11,temp
laDeg = (temp - "0") + laDeg
GET 12,temp
laMin = (temp - "0") * 10
GET 13,temp
laMin = (temp - "0") + laMin
GET 15,temp
temp2 = (temp - "0") * 1000
GET 16,temp
temp2 = (temp - "0") * 100 + temp2
GET 17,temp
temp2 = (temp - "0") * 10 + temp2
GET 18,temp
temp2 = (temp - "0") + temp2
laSec = temp2 * 6 / 10 + 5 / 10 ' temp2 * 0.06 (with rounding)
laNS = 0
GET 20,temp
IF (temp = "N") THEN Get_Long
laNS = 1

Get_Long:
GET 22,temp
loDeg = (temp - "0") * 100
GET 23,temp
loDeg = (temp - "0") * 10 + loDeg
GET 24,temp
loDeg = (temp - "0") + loDeg
GET 25,temp
loMin = (temp - "0") * 10
GET 26,temp
loMin = (temp - "0") + loMin
GET 28,temp
temp2 = (temp - "0") * 1000
GET 29,temp
temp2 = (temp - "0") * 100 + temp2
GET 30,temp
temp2 = (temp - "0") * 10 + temp2
GET 31,temp
temp2 = (temp - "0") + temp2
loSec = temp2 * 6 / 10 + 5 / 10 ' temp2 * 0.06 (with rounding)
loEW = 0
GET 33,temp
IF (temp = "E") THEN Parse_GPS_Done
loEW = 1

Parse_GPS_Done:
RETURN

' **********************************
' Save current GPS reading to EEPROM
' **********************************
Save_Reading:
eeBase = (readings - 1) * 9 + FirstAddr
eeAddr = eeBase + 0 : eeData = flags : GOSUB WriteBigEE
eeAddr = eeBase + 1 : eeData = laDeg : GOSUB WriteBigEE
eeAddr = eeBase + 2 : eeData = laMin : GOSUB WriteBigEE
eeAddr = eeBase + 3 : eeData = laSLo : GOSUB WriteBigEE
eeAddr = eeBase + 4 : eeData = laSHi : GOSUB WriteBigEE
eeAddr = eeBase + 5 : eeData = loDeg : GOSUB WriteBigEE
eeAddr = eeBase + 6 : eeData = loMin : GOSUB WriteBigEE
eeAddr = eeBase + 7 : eeData = loSLo : GOSUB WriteBigEE
eeAddr = eeBase + 8 : eeData = loSHi : GOSUB WriteBigEE

readings = readings + 1

STORE FirstSlot ' save readings in slot 1
WRITE 0,readings.LOWBYTE
WRITE 1,readings.HIGHBYTE

RETURN

' ************************
' Dump Acquired Data To PC
' ************************
Dump_Data:
DEBUG CLS,"Press any key when ready to dump datalog..."
SERIN RxD,T9600,[response]
DEBUG CLS
PAUSE 1000

STORE FirstSlot
READ 0,readings.LOWBYTE
READ 1,readings.HIGHBYTE

FOR rdngNum = 1 TO readings
' retrieve readings from EEPROM
eeBase = (rdngNum - 1) * 9 + FirstAddr
eeAddr = eeBase + 0 : GOSUB ReadBigEE : flags = eeData
eeAddr = eeBase + 1 : GOSUB ReadBigEE : laDeg = eeData
eeAddr = eeBase + 2 : GOSUB ReadBigEE : laMin = eeData
eeAddr = eeBase + 3 : GOSUB ReadBigEE : laSLo = eeData
eeAddr = eeBase + 4 : GOSUB ReadBigEE : laSHi = eeData
eeAddr = eeBase + 5 : GOSUB ReadBigEE : loDeg = eeData
eeAddr = eeBase + 6 : GOSUB ReadBigEE : loMin = eeData
eeAddr = eeBase + 7 : GOSUB ReadBigEE : loSLo = eeData
eeAddr = eeBase + 8 : GOSUB ReadBigEE : loSHi = eeData

' send To PC in comma-delimited format
DEBUG DEC4 rdngNum, " "
DEBUG DEC2 laDeg," ",DEC2 laMin," "
DEBUG DEC2 laSec / 10,".",DEC1 laSec // 10,Comma
DEBUG "N" + (laNS * 5),Comma
DEBUG DEC3 loDeg," ",DEC2 loMin," "
DEBUG DEC2 loSec / 10,".",DEC1 loSec // 10,Comma
DEBUG "E" + (loEW * 18),CR
NEXT
END

' *************************************
' Big EEPROM Management
' -- uses available slots as big EEPROM
' *************************************
WriteBigEE:
IF (eeAddr > MaxAddr) THEN NoWrite ' check for bad eeAddr
slot = (eeAddr / 2048) + FirstSlot ' calc pgm slot
addr = eeAddr // 2048 ' calc address in slot
STORE slot
WRITE addr,eeData

NoWrite:
RETURN

ReadBigEE:
IF (eeAddr > MaxAddr) THEN NoRead ' check for bad eeAddr
slot = (eeAddr / 2048) + FirstSlot ' calc pgm slot
addr = eeAddr // 2048 ' calc address in slot
STORE slot
READ addr,eeData

NoRead:
RETURN

 
Step 3
Once you copy and paste this code in the program, the code portion of this project will be complete. The next thing you have to worry about is the stamp and the Garmin Etrex Vista GPS. To connect the GPS to the stamp, splice the GPS data cable connected to the GPS. Split it into a black wire and a white wire. Attach a connector to the two wires so you can then connect these to the ground and pin zero of the basic stamp. The black wire serves as the ground wire for the GPS and the white wire serves as the wire that transfers data from the GPS to the basic stamp. Once the wires are connected to the stamp, attach a 9 volt battery to the stamp to power it. Next you want to attach the basic stamp and GPS to the Magpie AP. To do this, connect the GPS to the camera bay on the Magpie AP with zip ties and then attach the basic stamp to the top of the camera bay above the GPS with sticky tape and velcro. Make sure the GPS data cable is still connected to the basic stamp.
 

 
Step 4
Now that everything is connected together and mounted on the Magpie AP, flying the R/C airplane and gathering GPS waypoints is possible. To start, attach the serial cable to the stamp and the computer (make sure the stamp is powered by the 9 volt battery). Turn the GPS on and make sure the screen shows the present GPS location (longitude and latitude). Once the stamp is powered, the GPS is powered and connected to the stamp, connect the serial cable to the stamp and connect the other end to the serial com port in the computer. After this is done, run the program and select [1] Clear datalog and start again. Once this is done, the aircraft will be ready to fly and you will be ready to gather GPS data points. After the desired flight path is obtained and the GPS points collected, the data will be stored in the memory of the basic stamp. To get this data back, run the program and select [3] Dump datalog to PC. This will show all the data points collected during the flight. Copy and paste this information into an excel spreadsheet to be able to make a graph of the actual flight path. Below is an example of this done.
 

 

This is a video of the Magpie AP flying while collecting GPS waypoints

Example Excel Format:
Waypoint Degrees Minutes Seconds Hemisphere Degrees Minutes Seconds Hemisphere Latitude Longitude
1 39 57 15.3 N 75 11 9.1 W 39.95425 75.1858611
2 39 57 15.3 N 75 11 9.2 W 39.95425 75.1858889
3 39 57 15.3 N 75 11 9.2 W 39.95425 75.1858889
4 39 57 15.3 N 75 11 9.2 W 39.95425 75.1858889
5 39 57 15.2 N 75 11 9.2 W 39.95422222 75.1858889

When copying and pasting the coordinates into Excel, format the cells so they breakdown the coordinate to degrees, minutes, and seconds. To make this into a graphical number, use the formula:

Degrees + (Minutes * 1/60) + (Seconds * 1/60 * 1/60)
 
For each longitude and latitude, insert the different number into the formula. Make sure this formula is copied and pasted into the ending cell named Latitude and Longitude. After this is done, highlight the longitude and latitude and graph them in a scatter plot.
 
Conclusion
After this is complete, you can see in a graph the actual flight path of the aircraft. Just like the aircraft can fly to different locations and collect waypoint info, the aircraft can do the opposite. It can have GPS waypoints stored into the GPS and by following a route, the stamp will control the servo's to fly in the desired direction (in the direction of the waypoint).