Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to interface GPS to PC???

Status
Not open for further replies.

Eng_Girl

Newbie level 5
Newbie level 5
Joined
Feb 8, 2006
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,344
gps interfacing turbo c

Hi,

I want to ask, how can I interface my GPS receiver GARMIN through serial cable to the computer using the C compiler Dev-C++ ?

Is there any special things to do before ?

Do I need to store the GPS data first or process it directly by the program ?

If anyone have the C code for such interfacing PLZ give it to me????


Thanks,
 

gprmc sscanf c

I dont have any information about that particular
GPS receiver(Garmin) but I used Motorola Oncore
before. In it the serial port was automatically bumping
data in the format that you select.
 

Garmin GPS like most other GPS send serial data stream as NMEA protocol which is 4800baud, 8bits, no parity, 1 stop bit. The data is streamed continously so you need to configure a receive only serial port. You dont need to transmit anything.
I have done a lot of serial programming but havent used DEV-C. If you follow a DOS style program, you can use scanf to get the data stream in a string variable.
 

Thanks for replying , I kind of having a C code for parsing the GPRMC sentences ,but now I want to connect it to the serial port of my computer , how can I do that ,what libraries to use and how to determine the serial port .

any hint may help , thanks...:D
 

You can begin with a test with the hyperterminal. That will let you know which serial port is it COM1 or COM2. I dont know about DevC but in old C's like turbo-C you could read the serial port using the following
main() {
unsigned char chr;
int port_ads = 0x3f8;


_bios_serialcom(_COM_INIT, PORTNO,
_COM_9600 | _COM_STOP1 | _COM_NOPARITY | _COM_CHR8);
printf("initialized\n");

for ( ; ; ) {
if (kbhit() ) {
chr = getch();
if (chr == 27) break; // terminate on ESC
outp(port_ads, chr);
delay (10); // 10ms to respond
chr = inp(port_ads);
printf("Result = %d",chr);
putchar ('\n');
}
}
exit(0);
}

If you send me your code, maybe I can add some code for GPS in it. I have a GPS receiver and am kinda looking into learnig DevC also.
 

This is my code I first test the parsing of the GPS data to GPRMC , I define this sentence as a string array ,I run it it works,but now how can I modify it to read from the serial port instead.
can u explain to me each line of the code u provide it, please :?:



Code:
/******************************************************************************
*GPS.C is a program to test the parsing of the GPS sentence $GPRMC 
* and divide it into the required feilds: 
*Time ,Date, Latitude,Longitude,speed     
*******************************************************************************/     
#include <string.h>
#define paws system("PAUSE"); // to pause the output window in DEV-C++ program
#define MAXSIZE 100
#define COMMA   0x2C

 main(){ 
// char read from COM port
 
 char  charRead[]="$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A"; 
  

//	Buffer collects chars read from GPS
 char  stringRead[MAXSIZE];
	
//	Set an array for each attribute
  unsigned char  tempString[MAXSIZE];
  unsigned char  timeString[12];
  unsigned char  latitudeString[12];
  unsigned char  latitudeCardinalString[3];
  unsigned char  longitudeString[12];
  unsigned char  longitudeCardinalString[3];
  unsigned char  speedString[11];
  unsigned char  dateString[12];

//	Declare pointer
  unsigned char  *pChar;

//	Coordinated Universal Time(GMT) & Eastern Standard time
 unsigned  long utcTime, estTime;
 unsigned  long utcHour, estHour;
 unsigned  long utcMinutes, estMinutes;
 unsigned  long utcSeconds, estSeconds;
 unsigned  long date;
 unsigned  long day,month,year;

//	Sets the last comma position
 unsigned  char lastCommaPosition;

//	Sets the Latitude & Longitude
  float	latitude;
  int	latDegrees;
  float	latMinutes;

  float 	longitude;
  int	    longDegrees;
  float	    longMinutes;
  float     speed;

//	dummy variable
	unsigned int   j, k;
	
//	Number of chars read per GPS message string
	unsigned int	 i;

//	initializing the serial ports SCI0 & SCI1 

//	Enter a loop for reading char from serial port(Data Reg.)

//do {	

// checks if GPS messages start with $  char
 
if (charRead [0] == '$'){ 
              
	  i = 1;


   while(i<MAXSIZE){
	  stringRead[i] = charRead[i];  //  include each char read to the array 
	  i++;
   }  
       
 /* By this point, a complete GPS string has been read so save it*/	     
 /* Append the null terminator to the string read */
	  stringRead[i+1] = '\0';

	  /* Analyze string that we collected */
	   j = 0;
	  pChar = stringRead;     // put a pointer for the stringRead array
   while(*(pChar+j) != COMMA) {       /* COMMA  0x2C */

	       tempString[j] = *(pChar+j); //store the string before the comma
	       j++;
   }

	  tempString[j] = '\0';   // append the null to the end 

	  /* Check if string we collected is the $GPRMC message */
	  if (tempString[3] == 'R' && tempString[4] == 'M' && tempString[5] == 'C'){ 

/* Found GPRMC string. It has 11 commas total. Its NMEA sentence structure is:

$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A

Where:
     RMC          Recommended Minimum sentence C
     123519       Fix taken at 12:35:19 UTC
     A            Status A=active or V=Void.
     4807.038,N   Latitude 48 deg 07.038' N
     01131.000,E  Longitude 11 deg 31.000' E
     022.4        Speed over the ground in knots 
     084.4        Track angle in degrees True
     230394       Date - 23rd of March 1994
     003.1,W      Magnetic Variation
     *6A          The checksum data, always begins with *
*/

	pChar = stringRead;  // pointer to the String read

// (1) Get UTC time 

	      j = 7;  /* start of time field */
	      k = 0;
		  
	      while(*(pChar+j) != COMMA) { //loop until a comma is found
		   timeString[k] = *(pChar+j);   //save in the time string
		   	j++;
		   	k++;
	      }

	    lastCommaPosition = j; //  save the position of the last comma
	    timeString[k] = '\0'; // append the null to the end 

	   sscanf(timeString, "%ld", &utcTime); //save the string to the variable 

	    utcHour = (utcTime/10000); //extract Hours from long 
	    utcMinutes = (utcTime - (utcHour*10000))/100;  //extract minutes from long 
	    utcSeconds = utcTime - (utcHour*10000) -  (utcMinutes*100);  /* extract seconds from long */

	      if(utcHour >= 0 && utcHour <= 20) 
		      estHour = utcHour + 3;
		  
	      else 
              estHour = utcHour - 21;
              
	      estMinutes =  utcMinutes;
	      estSeconds =  utcSeconds;
		 
	
// (2) Empty Loop to avoid taking 'A' char

          pChar = stringRead;
	      j = lastCommaPosition + 1; //start from the next comma 
	      k = 0;
	      
	      while(*(pChar+j) != COMMA) {
		   j++;
		   k++;
	      }
	      lastCommaPosition = j;


// (3) Get lattitude 

	      pChar = stringRead;
	      j = lastCommaPosition +1; //start from the next comma 
	      k = 0;
	      while(*(pChar+j) != COMMA) {
		   latitudeString[k] = *(pChar+j); //save in the latitude string
		   j++;
		   k++;
	      }
	      lastCommaPosition = j;
	      latitudeString[k] = '\0';

	      sscanf(latitudeString, "%f", &latitude);
	      latDegrees = (int)(latitude/100);
	      latMinutes = (float)(latitude - latDegrees*100);

// (4)  Get lattitude Cardinal direction 

	      pChar = stringRead;
	      j = lastCommaPosition + 1;
	      k = 0;
		  
	      while(*(pChar+j) != COMMA) {
		   latitudeCardinalString[k] = *(pChar+j);
		   j++;
		   k++;
	      }
	      lastCommaPosition = j;
	      latitudeCardinalString[k] = '\0';
	      

// (5) Get longitude

	      pChar = stringRead;
	      j = lastCommaPosition + 1;
	      k = 0;

	      while(*(pChar+j) != COMMA) {
		   longitudeString[k] = *(pChar+j);
		   j++;
		   k++;
	      }

	      lastCommaPosition = j;
	      longitudeString[k] = '\0';

	      sscanf(longitudeString, "%f", &longitude);
	      longDegrees = (int)(longitude/100);
	      longMinutes = (float)(longitude - longDegrees*100);

// (6) Get longitude Cardinal direction 

	      pChar = stringRead;
	      j = lastCommaPosition + 1;
	      k = 0;
		  
	      while(*(pChar+j) != COMMA) {
		   longitudeCardinalString[k] = *(pChar+j);
		   j++;
		   k++;
	      }
	      lastCommaPosition = j;
	      longitudeCardinalString[k] = '\0';
	      
	
// (7) Get Speed in Knots 
      	     
          pChar = stringRead;
	      j = lastCommaPosition + 1;
	      k = 0;

	      while(*(pChar+j) != COMMA) {
		   speedString[k] = *(pChar+j);
		   j++;
		   k++;
	      }

	      lastCommaPosition = j;
	      speedString[k] = '\0';

	      sscanf(speedString, "%f", &speed);
	      speed = speed * 1.852; //convert the speed in Knots to Km/hour
	      

// (8) Empty Loop to avoid taking the Track angle 

          pChar = stringRead;
	      j = lastCommaPosition + 1; 
	      k = 0;
	      while(*(pChar+j) != COMMA) {
		   j++;
		   k++;
	      }
	      lastCommaPosition = j;


// (9) Get date 

	      pChar = stringRead;
	      j = lastCommaPosition + 1;  
	      k = 0;

	      while(*(pChar+j) != COMMA) {
		   dateString[k] = *(pChar+j);
		   j++;
		   k++;
	      }

	      lastCommaPosition = j;
	      dateString[k] = '\0';

	      sscanf(dateString, "%ld", &date);

	     day = (date/10000); //extract day from long 
	     month = (date - (day*10000))/100;  // extract month from long 
	     year = date - (day*10000) - (month*100); // extract year from long             

	 
//else not a GPRMC sentence
} 

// otherwise not a $ character... so loop back until one arrives
} 
//  } while(1);
printf(" \t GPRMC Sentence Test\n");
printf(" **********************************************************\n" );
printf(" **********************************************************\n\n" );
printf("   Time  :  %02ld:%02ld:%02ld UTC = %02ld:%02ld:%02ld EST \n\n", utcHour, utcMinutes, utcSeconds, estHour, estMinutes, estSeconds);
printf("   Date  :  %02ld:%02ld:%02ld  \n\n", day, month, year);
printf(" ----------------------------------------------------------\n" );
printf("   Latitude   :\t  %02d DEG  %2.4f MIN ", latDegrees, latMinutes);
printf(" %s \n\n", latitudeCardinalString);
printf("   Longitude  :\t %03d DEG %2.4f MIN ", longDegrees, longMinutes);
printf(" %s \n\n", longitudeCardinalString);
printf("   Speed      :  %f  Km/hour \n\n", speed );
printf(" **********************************************************\n\n" );

paws //to end the pause function declared above

} /* end of main */
 

Actually serial port access is different in different programming Environments. I had used it in DOS days of Turbo C whose code I pased. Now it has two parts.

#1 is to initialize the port to set the baud rate and other things. _bios_serialcom(...) does this part.

#2 is to get teh data from serial port into some buffer. inp(port_ads); does that part.

The functions of Dev-C would differ. You may have to search for these. I will also search and let you know if I find them.

Are you making a console application or a Window application?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top