GPS BS2 Code issues
spjapple31
Posts: 9
Finished testing only appear:
singnal Valid:
Local Time:
Local Date:
Latitude:
Longitude:
Altitude:
Speed:
I ask the Code issues Error??
(BS2)
singnal Valid:
Local Time:
Local Date:
Latitude:
Longitude:
Altitude:
Speed:
I ask the Code issues Error??
(BS2)
' -----[ Title ]----------------------------------------------------------- ' ' File...... Easy GPS V1.0.bsp ' Purpose... Easy GPS Interface ' Author.... Parallax, Inc. ' E-mail.... [EMAIL="support@parallax.com"]support@parallax.com[/EMAIL] ' Started... 02-26-2010 ' Updated... ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Program Description ]--------------------------------------------- ' Connect the Yellow Wire from your Parallax GPS Receiver to P0. The Black ' wire goes to VSS and the Red wire goes to VDD. All others wires should ' not be connected (I plugged mine into empty isolated breadboard slots) ' Reads NMEA data string from GPS receiver and parses data. GPS string is ' buffered into scratchpad RAM with SPSTR modifier. Once in SPRAM, data is ' parsed out based on its position. ' ' $GPRMC,POS_UTC,POS_STAT,LAT,LAT_D,LON,LON_D,SPD,HDG,DATE,MAG_VAR,MAG_REF,*CC ' ' POS_UTC - UTC of position. Hours, minutes and seconds. (hhmmss) ' POS_STAT - Position status. (A = Data valid, V = Data invalid) ' LAT - Latitude (ddmm.ffff) ' LAT_D - Latitude direction. (N = North, S = South) ' LON - Longitude (dddmm.ffff) ' LON_D - Longitude direction (E = East, W = West) ' SPD - Speed over ground. (knots) (0.0 - 999.9) ' HDG - Heading/track made good (degrees True) (x.x) ' DATE - Date (ddmmyy) ' MAG_VAR - Magnetic variation (degrees) (x.x) ' MAG_REF - Magnetic variation (E = East, W = West) ' *CC - Checksum ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- GPSpin PIN 0 ' GPS serial input ' -----[ Constants ]------------------------------------------------------- T4800 CON 188 ' Baud rate for GPS (typical) MoveTo CON 2 ' DEBUG positioning command ClrRt CON 11 ' Clear line right of cursor 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 PST ' For Rocklin, CA Comma CON "," ' Comma DegSym CON 176 ' Degrees symbol for report MinSym CON 39 ' Minutes symbol SecSym CON 34 ' Seconds symbol ' -----[ Variables ]------------------------------------------------------- index VAR Byte ' Index into GPS data in SPRAM flags VAR Byte ' Holds bit values valid VAR Flags.BIT3 ' Is data valid? numSats VAR Byte ' Number of satellites tmHrs VAR Byte ' Time fields tmMins VAR Byte tmSecs VAR Byte latDeg VAR Byte ' Latitude latMin VAR Byte latSec VAR Word latNS VAR flags.BIT0 ' 0 = N longDeg VAR Byte ' Longitude longMin VAR Byte longSec VAR Word longEW VAR flags.BIT1 ' 0 = E speed VAR Word ' In tenths of mph*************** altitude VAR Word ' In feet************************ day VAR Byte ' Day of month, 1 - 31 month VAR flags.NIB1 ' Month, 1 - 12 year VAR Byte ' Year, 00 - 99 char VAR Byte ' Byte pulled from SPRAM workVal VAR Word ' For numeric conversions eeAddr VAR workVal ' Pointer to EE data field VAR Nib ' Field # fldWidth VAR field ' Width of field ' -----[ EEPROM Data ]----------------------------------------------------- NotValid DATA "No", 0 IsValid DATA "Yes", 0 DaysInMon DATA 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 MonNames DATA "JAN",0,"FEB",0,"MAR",0,"APR",0,"MAY",0,"JUN",0 DATA "JUL",0,"AUG",0,"SEP",0,"OCT",0,"NOV",0,"DEC",0 ' -----[ Initialization ]-------------------------------------------------- Initialize: PAUSE 250 ' Let DEBUG open DEBUG CLS ' Clear the screen DEBUG "Easy GPS Interface V1.0", CR DEBUG "=======================" Draw_Ruler: FOR index = 0 TO 65 IF (index = 0) THEN Print_Ones IF (index // 10) > 0 THEN Print_Ones DEBUG MoveTo, (7 + index), 3, DEC1 (index / 10) Print_Ones: DEBUG MoveTo, (7 + index), 4, DEC1 (index // 10) Print_Ticks: IF (index // 10) > 0 THEN Next_Digit DEBUG MoveTo, (7 + index), 5, "|" Next_Digit: NEXT Draw_Data_Labels: DEBUG MoveTo, 0, 9, "Signal Valid: " DEBUG MoveTo, 0, 11, " Local Time: " DEBUG MoveTo, 0, 12, " Local Date: " DEBUG MoveTo, 0, 14, " Latitude: " DEBUG MoveTo, 0, 15, " Longitude: " DEBUG MoveTo, 0, 16, " Altitude: " DEBUG MoveTo, 0, 17, " Speed: " ' -----[ Program Code ]---------------------------------------------------- Main: ' Wait for $GPRMC string and store data in SPRAM SERIN GPSpin, T4800, 2000, No_GPS_Data, [WAIT("GPRMC,"), SKIP 65] GOSUB Parse_GPS_Data ' Extract data from SPRAM Show_GPMRC_String: DEBUG MoveTo, 0, 6, "$GPRMC," ' Print header index = 0 ' Start at position UTC Print_GPRMC_Char: ' Print the $GPRMC data string READ index, char ' Get char from SPRAM DEBUG char ' Display it IF char = "*" THEN Print_Checksum ' Look for checksum indicator index = index + 1 ' Point to next char GOTO Print_GPRMC_Char Print_Checksum: READ (index + 1), char ' Get first checksum char DEBUG char ' Display READ (index + 2), char ' Get second checksum char DEBUG char, ClrRt ' Display, clear to end of line Show_Report: DEBUG MoveTo, 14, 9 ' Was the signal valid? LOOKUP valid, [NotValid, IsValid], eeAddr' Get answer from EE GOSUB Print_Z_String ' Print it DEBUG " (", DEC numSats, " Satellites)" DEBUG ClrRt ' Clear end of line IF (valid = 0) THEN Signal_Not_Valid Get_Altitude: SERIN GPSpin, T4800, 2000, Signal_Is_Valid, [WAIT("GPGGA,"), SKIP 75] index = 45 ' Altitude GOSUB Mixed_To_Tenths ' Convert "xxx.x" To number altitude = workVal index = 38 : fldWidth = 2 ' Number of sats GOSUB String_To_Value numSats = workVal Show_GPGGA_String: DEBUG MoveTo, 0, 7, "$GPGGA," ' Print header index = 0 ' Start at position UTC Print_GPGGA_Char: ' Print the $GPRMC data string READ index, char ' Get char from SPRAM DEBUG char ' Display it IF char = "*" THEN Print_Chexum ' Look for checksum indicator index = index + 1 ' Point to next char GOTO Print_GPGGA_Char Print_Chexum: READ (index + 1), char ' Get first checksum char DEBUG char ' Display READ (index + 2), char ' Get second checksum char DEBUG char, ClrRt ' Display, clear to end of line Signal_Is_Valid: DEBUG MoveTo, 14, 11, DEC2 tmHrs, ":", DEC2 tmMins, ":", DEC2 tmSecs DEBUG MoveTo, 14, 12, DEC2 day, " " eeAddr = (month - 1) * 4 + MonNames ' get address of month name GOSUB Print_Z_String ' print it DEBUG " 20", DEC2 year DEBUG MoveTo, 14, 14, " ", DEC2 latDeg, DegSym, " ", DEC2 latMin, MinSym, " " DEBUG DEC2 (latSec / 10), ".", DEC1 (latSec // 10), SecSym, " " DEBUG "N" + (latNS * 5) DEBUG MoveTo, 14, 15, DEC3 longDeg, DegSym, " ", DEC2 longMin, MinSym, " " DEBUG DEC2 (longSec / 10), ".", DEC1 (longSec // 10), SecSym, " " DEBUG "E" + (longEW * 18) DEBUG MoveTo, 14, 16, DEC (altitude / 10), ".", DEC1 (altitude //10), " Meters", ClrRt DEBUG MoveTo, 14, 17, DEC (speed / 10), ".", DEC1 (speed // 10), " MPH " GOTO Main Signal_Not_Valid: DEBUG MoveTo, 14, 11, "?", ClrRt ' Clear all fields DEBUG MoveTo, 14, 12, "?", ClrRt DEBUG MoveTo, 14, 14, "?", ClrRt DEBUG MoveTo, 14, 15, "?", ClrRt DEBUG MoveTo, 14, 16, "?", ClrRt DEBUG MoveTo, 14, 17, "?", ClrRt GOTO Main ' -----[ Subroutines ]----------------------------------------------------- No_GPS_Data: DEBUG CLS, "Error: No GPS data detected" PAUSE 2500 GOTO Initialize ' Try again Parse_GPS_Data: index = 0 : fldWidth = 2 ' UTC hours GOSUB String_To_Value tmHrs = workVal index = 2 : fldWidth = 2 ' UTC minutes GOSUB String_To_Value tmMins = workVal index = 4 : fldWidth = 2 ' UTC seconds GOSUB String_To_Value tmSecs = workVal index = 13 : fldWidth = 2 ' Latitude degrees GOSUB String_To_Value latDeg = workVal index = 15 : fldWidth = 2 ' Latitude minutes GOSUB String_To_Value latMin = workVal index = 18 : fldWidth = 4 ' Latitude fractional minutes GOSUB String_To_Value latSec = workVal ** $0F5C ' x 0.06 --> tenths of seconds index = 25 : fldWidth = 3 ' Longitude degrees GOSUB String_To_Value longDeg = workVal index = 28 : fldWidth = 2 ' Longitude minutes GOSUB String_To_Value longMin = workVal index = 31 : fldWidth = 4 ' Longitude fractional minutes GOSUB String_To_Value longSec = workVal ** $0F5C ' x 0.06 --> tenths of seconds ' Get non-numeric data Get_Valid: READ 11, char valid = 1 ' Assume valid IF (char = "A") THEN Get_Lat_Dir ' It is, so skip valid = 0 ' Set to 0 if not valid Get_Lat_Dir: latNS = 0 ' Assume North READ 19, char ' Check it IF (char = "N") THEN Get_Long_Dir ' Confirm latNS = 1 ' Set to 1 if South Get_Long_Dir: longEW = 0 ' Assume East READ 33, char ' Check it IF (char = "E") THEN Get_Speed ' Confirm longEW = 1 ' Set to 1 if West ' Get variable length data Get_Speed: index = 38 GOSUB Mixed_To_Tenths ' Convert "xxx.x" To number ' speed = workVal ' Speed in knots (tenths) speed = workVal + (workVal ** $2699) ' x 1.1507771555 for mph ' Get date ' -- past variable data, so we need to use field search Get_Date: field = 8 ' Set field to find GOSUB Move_To_Field ' Go get position READ 125, index ' Save date position fldWidth = 2 GOSUB String_To_Value day = workVal ' UTC day, 1 - 31 READ 125, index ' Get stored position index = index + 2 : fldWidth = 2 GOSUB String_To_Value month = workVal ' UTC month, 1 - 12 READ 125, index ' Get stored position index = index + 4 : fldWidth = 2 GOSUB String_To_Value year = workVal ' UTC year, 0 - 99 ' Adjust date for local position Correct_Local_Time_Date: workVal = tmHrs + UTCfix ' Add UTC offset IF (workVal < 24) THEN Adjust_Time ' Midnight crossed? workVal = UTCfix ' Yes, so adjust date BRANCH workVal.BIT15, [Location_Leads, Location_Lags] Location_Leads: ' East of Greenwich day = day + 1 ' No, move to next day eeAddr = DaysInMon * (month - 1) ' Get days in month READ eeAddr, char IF (day <= char) THEN Adjust_Time ' In same month? month = month + 1 ' No, move to next month day = 1 ' First day IF (month < 13) THEN Adjust_Time ' In same year? month = 1 ' No, set to January year = year + 1 // 100 ' Add one to year GOTO Adjust_Time Location_Lags: ' West of Greenwich day = day - 1 ' Adjust day IF (day > 0) THEN Adjust_Time ' Same month? month = month - 1 IF (month > 0) THEN Adjust_Time ' Same year? month = 1 ' No, set to January eeAddr = DaysInMon * (month - 1) READ eeAddr, day ' Get new day year = year + 99 // 100 ' Set to previous year Adjust_Time: tmHrs = tmHrs + (24 + UTCfix) // 24 ' Localize hours RETURN ' ********************************************* ' Convert string data (nnnn) to numeric value ' -- index - location of first digit in data ' -- fldWidth - width of data field (1 to 5) ' -- workVal - returns numeric value of field ' ********************************************* String_To_Value: workVal = 0 IF (fldWidth = 0) OR (fldWidth > 5) THEN String_To_Value_Done Get_Field_Digit: READ index, char ' Get digit from field workVal = workVal + (char - "0") ' Convert, add into value fldWidth = fldWidth - 1 ' Decrement field width IF (fldWidth = 0) THEN String_To_Value_Done workVal = workVal * 10 ' Shift result digits left index = index + 1 ' Point to next digit GOTO Get_Field_Digit String_To_Value_Done: RETURN ' ***************************************************** ' Convert string data (nnn.n) to numeric value (tenths) ' -- index - location of first digit in data ' -- workVal - returns numeric value of field ' ***************************************************** Mixed_To_Tenths: workVal = 0 Get_Mixed_Digit: READ index, char ' Read digit from speed field IF (char = ".") THEN Get_Mixed_Last ' Skip decimal point workVal = (workVal + (char - "0")) * 10' Add digit, move data left index = index + 1 ' Point to next digit GOTO Get_Mixed_Digit Get_Mixed_Last: READ (index + 1), char workVal = workVal + (char - "0") ' Speed in knots RETURN ' ************************************************************ ' Find field location after variable-length data (i.e., speed) ' -- field - field number ' -- index - returns position of first digit in field ' ************************************************************ Move_To_Field: index = 0 IF (field = 0) THEN Move_To_Field_Done' If zero, we're there Get_Char: READ index, char ' Get char from SPRAM IF (char = Comma) THEN Found_Comma ' Is it a comma? index = index + 1 ' No, move to next char GOTO Get_Char Found_Comma: field = field - 1 ' Was comma, dec field coutner index = index + 1 ' Point to next char IF (field = 0) THEN Move_To_Field_Done' If field = 0, we're there GOTO Get_Char Move_To_Field_Done: RETURN ' ********************************************* ' Print Zero-terminated string stored in EEPROM ' -- eeAddr - starting character of string ' ********************************************* Print_Z_String: READ eeAddr, char ' Get char from EE IF (char = 0) THEN Print_Z_String_Done' If zero, we're done DEBUG char ' Print the char eeAddr = eeAddr + 1 ' Point to the next one GOTO Print_Z_String Print_Z_String_Done: RETURN
Comments
(I have modified the change but did not comment)
I was using BS2P sample program modified to BS2
For the price of a BS2P you can buy two USB Propeller Project Boards. The propeller has many more resources than the BS2 or BS2P, more memory, faster, and can perform 8 simultaneous tasks. Plus you have quite a few options for programming, SPIN, PASM, BASIC, C, C++, several FORTH's. (I wonder if anyone is looking into COBOL?)
You changed it to which also waits for string "GPRMC" but then SKIPs the next 65 characters, period. Nothing was stored , just skipped.
Just about the same for the SERIN... statement under "Get_Altitude:".
The BS2P has a 128 byte Scratchpad ram memory, the BS2 does not. This program requires the BS2P because it has the Scratchpad.
The BS2 has NOWHERE to put 65 or 75 incoming characters except possibly in EEPROM, which would wear out rather quickly in this application.
In short, changing various statements in order to compile for a BS2 does not alter the fact that the BS2 does not have the resources that this program needs.
' {$PBASIC 2.5}
LatDeg VAR Byte
LatMin VAR Byte
LatMinD VAR Word
LatSign VAR Byte
LatDir VAR Byte
LonDeg VAR Byte
LonMin VAR Byte
LonMinD VAR Word
LonSign VAR Byte
LonDir VAR Byte
wVal VAR Word
'Baud rates (non-inverted):
n4800 CON 188
n9600 CON 84
Main:
'Get GPSRMC statement from pin 0
SERIN 0, n4800, [WAIT("RMC,"),SKIP 13,
DEC2 LatDeg, DEC2 LatMin, SKIP 1, DEC LatMinD, SKIP 1, LatSign,
DEC3 LonDeg, DEC2 LonMin, SKIP 1, DEC LonMinD, SKIP 1, LonSign]
GOSUB AddSign
PAUSE 760
wVal = (LatMin * 1000 / 6) + (LatMinD / 60) 'convert to min/seconds
SEROUT 16, n9600, [REP "-"\LatDir, DEC LatDeg, ".", DEC4 wVal, ", "]
wVal = (LonMin * 1000 / 6) + (LonMinD / 60) 'convert to min/seconds
SEROUT 16, n9600, [REP "-"\LonDir, DEC LonDeg, ".", DEC4 wVal, CR]
GOTO Main
DEBUG CR ' Show empty debug window if GPS does not respond
AddSign:
IF LatSign = "S" THEN
LatDir = 1
ELSE
LatDir = 0
ENDIF
IF LonSign = "W" THEN
LonDir = 1
ELSE
LonDir = 0
ENDIF
RETURN
Debug Terminal ?
Why not show the numerical?
Page 169 of the current Stamp manual states that is the same as $4054 is Hex for 16468. The signal has to be inverted since it goes through an RS232 level driver which is an inverter.
Change the constant declaration from n9600 CON 84 to i9600 CON 16468. Don't forget to change all the SEROUT statements. You could leave the name as n9600 but the n denotes non-inverted and could cause confusion later on.
Also you need to correct the following error;
Any statement following a GOTO... statement must have a label which is used in another part of the program or else the statement is unreachable.
You did a marvelous job in reducing the BS2P program to work in a BS2. Let us know if it works out.
I do not understand what you mean.
We tried to modify it still does not show the latitude and longitude.
This is stuff we use.
Can you please re-post your code with your latest changes?
Just get rid of the DEBUG CR statement that follows the GOTO..., it will never execute. More important, your SERIN statement in MAIN: is missing the timeout parameter. Without it, your program will stall, waiting for the GPS to send the "RMC" string. You need to add the timeout parameters as was done in the BS2P version. " SERIN GPSpin, T4800, 2000, No_GPS_Data, [WAIT("GPRMC,"), SKIP 65] ". You need to add those two items into the SERIN statement and then write a small block of code labelled No_GPS_Data to handle the error in case the GPS stops working. Something similar from the earlier program...
Good luck
Hal
Go to the following web site, it has everything you need for your particular GPS module. I found it by Google searching GPS modules by image, and came across the one you picture, and its web site. It also has a BS2 demo program. One thing that stood out is that with the RAW pin unconnected the GPS is in command mode where you have to send a command out to receive anything from the receiver.
http://www.grandideastudio.com/portfolio/gps-receiver/
I can see where the OP had problems getting the code.
It could have been gotten off of classic.parallax.com, but now that is in the ether.
Parallax, Inc. was the exclusive manufacturer of the GPS Receiver Module. The module has been discontinued as of December 15, 2011.
From the pictures on the site, the site link is printed on the back of the module. OP could have saved himself a lot of work by simply looking at the board.
Yes, but they had full documentation on the old Parallax site while it was being sold, and when it was discontinued.
I tried to back up the old Parallax site, but could not. The Wayback Machiche can not access the old site because of robot.txt.
Connect the pin labelled /RAW to Vss (GND).
OK .However, only two orientations should I go to increase