Friday, April 12, 2024

ESP32 (Non-Standard) GPS Receiver

Comment errors or corrections found for this circuit, and get the chance to win big!


GNSS – GG-1802 ($5 a piece)

Sometimes things do not fall in place and we curse ourselves for taking the wrong turn or making the wrong choices. But in P B Shelly’s word the real perspective later for those situations could be like this…

We look before and after / And pine for what is not / Our sincerest laughter with some pain is fraught / Our sweetest songs are those that tell about our saddest thoughts.

Once I bought a pair of Arduino compatible GPS receivers from an online electronic store at a throwaway price and then the whole problem started. The GPS receiver do not talk to any standard programs. No Arduino programs – AdafruitGPS, NeoGPS, TinyGPS, TinyGPS++, or the oldest GPS could talk to the module to decipher data. Frustrated me finally raise the dispute for refund of money – stating the reason that the GPS receiver is non-compatible with Arduino [That’s what they were sold primarily].

The seller immediately made the tiny refund and I simply set them aside to finally put them in the wastebasket someday.

- Advertisement -

A couple of months later

ESP32 the wonder MCU

I was experimenting with a project where precise time keeping was necessary and I lay my eyes on these small good-for-nothing GPS receivers. I picked one of them and using an USB-to-Serial FTDI board. I connected the module to the raw serial terminal of my computer [3.3V+Gnd+Tx+Rx pins used]. I set the terminal speed as 9600-8N1 and I find all those NMEA sentences arriving at the GTK terminal of my Ubuntu PC.

[NMEA = National Marine Electronics Association]

$GNGGA,172549.00,,,,,0,00,99.99,,,,,,*74 $GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E $GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E $GPGSV,1,1,01,31,,,26*7E $GLGSV,1,1,01,,,,26*60 $GNGLL,,,,,172549.00,V,N*58 $GNRMC,172550.00,V,,,,,,,030719,,,N*6B $GNVTG,,,,,,,,,N*2E $GNGGA,172550.00,,,,,0,00,99.99,,,,,,*7C $GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E $GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E $GPGSV,1,1,01,31,,,26*7E $GLGSV,1,1,01,,,,27*61 $GNGLL,,,,,172550.00,V,N*50

- Advertisement -

Though the sentences are not very clear for what is what but a close look shows that the colored figures are UPC [United Pacific Time string] and Date string.

For a better picture I connected the module with the Serial2 hardware port of ESP32 and it now arrived very clearly on the arduino terminal. Now look carefully – all those GPS receiver data are available in those incomprehensible sentences Lattitude, A(=active or fixed), Longitude, date,No-of-satellite-in-view, Speed, mean-sea-level etc. All these data are arriving at fixed position with fix frequencies.

$GNRMC,173206.00,A,2405.32467,N,08238.89017,E,0.177,,030719,,,D*66 $GNVTG,,T,,M,0.177,N,0.328,K,D*30 $GNGGA,173206.00,2405.32467,N,08238.89017,E,2,12,0.69,281.5,M,-53.1,M,,0000*69 $GNGSA,A,3,31,10,14,32,20,18,25,01,11,26,22,40,1.30,0.69,1.11*1A $GNGSA,1,14,295,25,12,06,051,*74 $GPGSV,4,2,16,14,53,338,26,18,36,296,29,20,31,120,32,21,04,161,23*7F $GPGSV,4,3,16,22,09,315,21,25,24,085,27,26,12,175,25,27,02,221,18*71 $GPGSV,4,4,16,31,74,205,26,32,49,013,25,40,48,232,28,41,62,179,*7A $GLGSV,3,1,09,69,13,088,,70,42,031,,71,26,329,,73,50,161,29*66 $GLGSV,3,2,09,74,11,188,,79,02,026,,80,47,053,,85,21,230,17*63 $GLGSV,3,3,09,86,22,290,*59 $GNGLL,2405.32467,N,08238.89017,E,173206.00,A,D*72

A different type of NMEA sentences started arriving on the Serial2 port of the ESP32. The signal is different from the normal NEMA sentences and that for reasons justified normal GPS programs could not decipher them at all.

After a few cursory studies of the sentences that are arriving, I find that the first few important parameter like – Lattitude, Longitude, hhmmss [Hour Minute Seconds] , ddmmyy [Day Month Year], altitude, no-of-satellites-in-view, fix, km/hour speed can be located easily in the sentences.

Once I know where these data are located in those junk like serial NMEA data stream, I made an attempt to pluck out those useful data for the project.

In an Arduino for connecting any normal UART module, it’s always good to avoid the native Rx & Tx [D0 and D1 ] pins as these two pins are used while uploading a sketch from a computer. One has to make those pins free while uploading the sketch else it will not upload. Therefore it’s most convenient to connect any UART device to some other GPIOs and for that people mostly use software serial or no serial like programs. Unfortunately, those software do not work on ESP32.


ESP32 has 3 hardware serials and any pins can be set for the task and for that no extra header files required.

Serial1.begin(9600, SERIAL_8N1, RXD1, TXD1); // 16,15,13,34 pins are OK Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); // 17,12,4,35 pins are OK

You can set any pins for the Tx and Rx ports. One more interesting fact about the NMEA sentence is that the data that arrives endlessly are all in CSV form. Therefore, separating them on CSV is easy! For invoking the hardware serial of ESP2 & getting the data in CSV format just follow the following simple commands.

Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); //RXD2=16, TXD2=17
while (Serial2.available() ) {
String val +=Serial2.readStringUntil(‘\r\n’);

That’s the few line of commands in arduino which plucks out the comma separated NEMA sentences out of the whole lot.


Well till now we have got the CSV strings of the NMEA data and now we have to segregate them and then use it for our purpose. We are going to develop a small GPS clock on ESP32 using this procedure. Once you master this trick, you can connect any UART device to any MCU.

//for(i=0;i<=j-1;i++) list[i]= getValue(val,’,’,i); // unnecessary loads memory for(i=0;i<=200;i++) list[i]= getValue(val,’,’,i); // 200 variable is enough!

The data once acquired in the String named ‘val’ is now to be stripped in comma-separated array variable named list[]. The NEMA sentences happen to be quite big and collecting so much data is really not making any senses besides it overloads the memory. Therefore, it’s quite prudent to restrict the number of CSV variables into 200 or less. Therefore, the next line of the program is used instead, commenting out the previous one.

Local time

Now after getting the handful CSV values in list[] variable, we start our local calculations. First we set an active or fix block to ensure that the GPS receiver is ready and active by the following command. Two variable defined at the top of the programs to offset for the local time. list[1] is time, list[2] is active when it is ‘A’ so are the other important variables. The detail of the sketch can be followed very easily.

If (list[0]==”$GNRMC” && list[2]==”A”) { ….. do all the calculations here …. }
const int timezonehh = 5; //Timezone hour offset
const int timezonemm = 30; //Timezone minute offset

We have used a TFT colour display which is entirely controlled by the program TFT_ILI9163C.h any other display can also be used instead of this display with suitable header files. The location of the header files that are used in this program are linked below. However, I’m attaching the zip file as well for the header file as well as the Arduino sketch.

1> TFT_ILI9163 library 2> Adafruit Graphics library



GPS Receiver Schematic
GPS Receiver Schematic

The TFT ILI9161 works on just 5 pins other than the VCC, LED and GND pins. SCK, SDA pins are fixed type [18 & 23] while the AD, CS & RST can be connected to any GPIO pins. For finding out the day-of-week, I’ve used a small function – calcDayOfWeek(int d, int m, int y) which finds out the day-of-week from the dd, mn and yy values. It’s so easy!


1. GPS module – $4 to $5 a piece. 2. ILI 9161: 1.44 TFT – $3 a piece. 3. ESP32 – $4 to $7 [Depending upon which model you buy, the bare minimum is $4 while the USB programmable is $7 ]


With the restoration of these cheap GPS modules by reading their UART data it’s rather very easy to decipher then, discarding the fancy ready-made programs that the Arduino galaxy is replete with [GPS, Adafruit-GPS, NEOGPS, TinyGPS, TinyGPS++ ,NEMAGPS etc]. I can now go ahead with the gas pipeline detection project with spare GPS module and whenever required can peep into more UART devices in future before looking out for a ready-made header programs in the Internet.

Finally, I called the guy at the store for a repay offer of those throw-away prices which he once refunded me on my lodging of disputes. All he sent me was a big thank-you note and requested me to send him the Arduino-Sketch!




Unique DIY Projects

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components