This PIC project shows how to interface PIC16F887 microcontroller with GPS module in order to receive data from satellites where the GPS module used in this project is u-blox NEO-6M (other modules also should work). With the NEO-6M GPS module we can measure position (latitude and longitude), altitude, time (UTC), date, speed and some other data. The compiler used in this project is mikroElektronika mikroC PRO for PIC. — GPS: Global Positioning System —
In this project I’ll send information of latitude, longitude, altitude, time (UTC), date, speed and course serially (using serial port) to the laptop (PC). Data are sent to the laptop after receiving it from the GPS module. The laptop displays all data with serial monitor software such as Windows hyper terminal, Arduino IDE serial monitor, mikroElektronika USART Terminal (Tools –> USART Terminal or shortly Ctrl + T) …
The NEO-6M GPS module which I’m using is similar to the one shown below:
Generally the NEO-6M GPS module has 4 pins: VCC (3.3V or 5V), RX, TX and GND. It uses serial communication (UART protocol) to communicate with the microcontroller where RX/TX pins are for receiving/transmitting data from/to the microcontroller.
GPS Library for mikroC PRO for PIC compiler:
To simplify this project I wrote a small library for GPS modules, this library decodes (parses) GPS NMEA sentences (the GPS module serially sends NMEA sentences to the MCU, these sentences contain all data we need, but they need to be decoded). This library extracts all data from 2 sentences: RMC ($GPRMC) and GGA ($GPGGA). — NMEA: National Marine Electronics Association —
The GPS library decodes the RMC sentence which gives latitude, longitude, time, date, speed and course. It also decodes the GGA sentence in order to get altitude and number of satellites used by the module.
$GPRMC: Recommended minimum specific GPS/Transit data
$GPGGA: Global Positioning System Fix Data
GPS Library for mikroC PRO for PIC compiler can be downloaded from the link below, its full name is “GPS_mikroc.c“:
mikroC GPS Library download
after the download, add the library file (GPS_mikroc.c) to project folder.
Hardware Required:
- PIC16F887 microcontroller
- NEO-6M GPS module
- USB to serial converter (such as FT232RL)
- 5V source
- Breadboard
- Jumper wires
NEO-6M GPS module interfacing with PIC16F887 MCU circuit:
The following image shows the circuit diagram of the project.
(All grounded terminals are connected together)
The NEO-6M GPS module board has 4 pins connected as follows:
GND (Ground) pin connected to circuit GND
TX pin goes to PIC16F887 RX (RC7) pin (pin #26)
RX pin is not connected (there is no need to send data from the microcontroller to the GPS module)
VCC pin goes to circuit +5V pin.
To be able to send data from the microcontroller to the laptop we need a USB-to-Serial converter module. In this project I used the FT232RL module (the main component is FT232RL chip from FTDI), other modules can be used including the Arduino boards.
The GND pin of the USB-to-Serial converter is connected to circuit ground and RX pin is connected to PIC16F887 TX (RC6) pin (pin #25).
In this project the PIC16F887 microcontroller runs with its internal oscillator @ 8 MHz, MCLR pin is configured as an input pin.
NEO-6M GPS module interfacing with PIC16F887 C code:
The following C code is for mikroC PRO for PIC compiler.
With the code below we can get the following data from the NEO-6M GPS module:
latitude, longitude, altitude, time (UTC), date , speed, course and number of satellites in use. The image below shows my result (I used mikroElektronika USART terminal):
The function void byte_to_str(unsigned short nub, char *str) converts a byte of 2 digits (0 – 99) into string of 3 characters (with string terminator ‘\0’), if the byte number is less than 10 the first character will be 0. For example 7 becomes “07”.
The function void float_to_str(float f_number, char *f_str, short size) converts a float number into string where f_number is the float number we want to convert, f_str is the string we want to store data in and size is number of digits after the floating point.
Full mikroC code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | /************************************************************************************** Interfacing PIC16F887 microcontroller with NEO-6M GPS module C Code for mikroC PRO for PIC compiler internal oscillator used @ 8MHz Configuration words: CONFIG1 = 0x2CD4 CONFIG2 = 0x0700 This is a free software with NO WARRANTY. http://simple-circuit.com/ ***************************************************************************************/ // include GPS mikroC library #include <GPS_mikroc.c> char txt[15]; unsigned short sats; float f_res = 0; // convert byte to string void byte_to_str(unsigned short nub, char *str) { str[0] = nub / 10 + '0'; str[1] = nub % 10 + '0'; str[2] = '\0'; } // convert float number to string void float_to_str(float f_number, char *f_str, short size) { uint8_t i = 0; int16_t i_part = f_number; if(i_part < 0){ i_part = fabs(i_part); f_str[0] = '-'; i++; } if(i_part > 99) f_str[i++] = i_part / 100 + '0'; if(i_part > 9) f_str[i++] = (i_part / 10) % 10 + '0'; f_str[i++] = i_part % 10 + '0'; f_str[i++] = '.'; while (size-- > 0){ f_number -= (int16_t)f_number; f_number *= 10; f_str[i++] = (uint8_t)(f_number) % 10 + '0'; } f_str[i] = '\0'; } char* codetxt_to_ramtxt(const char* ctxt) { static char text_[20]; char i; for(i = 0; text_[i] = ctxt[i]; i++); return text_; } // main function void main() { OSCCON = 0X70; // set internal oscillator to 8MHz UART1_Init(9600); while(1) { if (UART1_Data_Ready() == 1) if(GPSRead()) { // Time UART1_Write_Text(codetxt_to_ramtxt("\r\nTime (UTC): ")); byte_to_str(GPSHour(), txt); UART1_Write_Text(txt); UART1_Write_Text(":"); byte_to_str(GPSMinute(), txt); UART1_Write_Text(txt); UART1_Write_Text(":"); byte_to_str(GPSSecond(), txt); UART1_Write_Text(txt); //Date UART1_Write_Text(codetxt_to_ramtxt("\r\nDate : ")); byte_to_str(GPSDay(), txt); UART1_Write_Text(txt); UART1_Write_Text("/"); byte_to_str(GPSMonth(), txt); UART1_Write_Text(txt); UART1_Write_Text("/20"); byte_to_str(GPSYear(), txt); UART1_Write_Text(txt); // Latitude UART1_Write_Text(codetxt_to_ramtxt("\r\nLatitude : ")); f_res = Latitude(); float_to_str(f_res, txt, 6); UART1_Write_Text(txt); // Longitude UART1_Write_Text(codetxt_to_ramtxt("\r\nLongitude : ")); f_res = Longitude(); float_to_str(f_res, txt, 6); UART1_Write_Text(txt); // Altitude UART1_Write_Text(codetxt_to_ramtxt("\r\nAltitude : ")); f_res = Altitude(); float_to_str(f_res, txt, 1); UART1_Write_Text(txt); UART1_Write_Text(codetxt_to_ramtxt(" meters")); // Number of satellites in use UART1_Write_Text(codetxt_to_ramtxt("\r\nSatellites: ")); sats = Satellites(); byte_to_str(sats, txt); UART1_Write_Text(txt); // Speed in kmph UART1_Write_Text(codetxt_to_ramtxt("\r\nSpeed : ")); f_res = Speed(); float_to_str(f_res, txt, 1); UART1_Write_Text(txt); UART1_Write_Text(codetxt_to_ramtxt(" kmph")); // Course in degrees UART1_Write_Text(codetxt_to_ramtxt("\r\nCourse : ")); f_res = Course(); float_to_str(f_res, txt, 1); UART1_Write_Text(txt); UART1_Write_Text(codetxt_to_ramtxt(" degrees\r\n")); } } } // End of code |
The simulation of this project with Proteus should give a result similar to the one shown in the following video where PIC16F877A microcontroller is used:
Related Project:
GPS Clock with PIC microcontroller and NEO-6M module | mikroC Projects
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.
Maybe [ ; ] is absent at the end of the sentence [ if (UART1_Data_Ready() == 1) ]
No, that’s not right!
Maybe [ { ] is absent at the end of the sentence [ if (UART1_Data_Ready() == 1) ]
And in the file “GPS_mikroc.c“ contains two declare lines: float Latitude();
How do i get the code for MICROCONTROLLER BASED SATELLITE DISH POSITIONING
SYSTEM