{"id":114218,"date":"2022-09-29T13:12:48","date_gmt":"2022-09-29T13:12:48","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=114218"},"modified":"2024-02-20T12:06:52","modified_gmt":"2024-02-20T12:06:52","slug":"lilygo-t-sim7000g-esp32-gps-data","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/lilygo-t-sim7000g-esp32-gps-data\/","title":{"rendered":"LILYGO T-SIM7000G ESP32: Get GPS Data (Latitude, Longitude, Altitude, and more)"},"content":{"rendered":"\n<p>In this quick guide, you&#8217;ll learn how to get GPS data with the LILYGO T-SIM7000G ESP32 board using Arduino IDE. This tutorial is also compatible with a &#8220;regular&#8221; ESP32 connected to a SIM7000G module.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-T-SIM7000-ESP32-Get-GPS-Data.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LILYGO T-SIM7000G ESP32 Get GPS Data Latitude Longitude Altitude\" class=\"wp-image-114261\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-T-SIM7000-ESP32-Get-GPS-Data.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-T-SIM7000-ESP32-Get-GPS-Data.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-T-SIM7000-ESP32-Get-GPS-Data.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-T-SIM7000-ESP32-Get-GPS-Data.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<div class=\"wp-block-group rntbox rntclgray is-vertical is-layout-flex wp-container-core-group-is-layout-8cf370e7 wp-block-group-is-layout-flex\">\n<p><strong>Compatibility<\/strong><\/p>\n\n\n\n<p>This board supports 2G, LTE CAT-M1, and NB-IoT protocols. You can go to the following links to check if any of these protocols are supported in your country:<\/p>\n\n\n\n<p><a href=\"https:\/\/1nce.com\/en-eu\/1nce-connect\/our-coverage\/2g-network\" target=\"_blank\" rel=\"noopener\" title=\"\">Check network protocols supported in your country;<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/iotcreators.com\/network\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Check NB-IoT providers in your country.<\/a><\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing the LILYGO T-SIM7000G ESP32<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/makeradvisor.com\/tools\/t-sim7000g-esp32\/\" target=\"_blank\" rel=\"noreferrer noopener\">LILYGO T-SIM7000G<\/a> is an ESP32 development board with a SIM7000G chip. This adds GPS, GPRS, LTE CAT-M1, and NB-IoT protocols to your board. This means that with this board you can send SMS, get location and time using GPS, and connect it to the internet using a SIM card data plan. This board doesn&#8217;t support phone calls.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-TSIM7000G.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LILYGO T-SIM7000G ESP32\" class=\"wp-image-114209\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-TSIM7000G.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-TSIM7000G.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Besides the SIM7000G module, the board also comes with some interesting features like a battery holder for a 18650 battery, a battery charging circuit where you can connect solar panels to recharge the battery, and a microSD card slot that can be useful for data logging projects or to save configuration settings.<\/p>\n\n\n\n<p>For a more in-depth introduction, we recommend following the getting started guide:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/lilygo-t-sim7000g-esp32-lte-gprs-gps\/\" title=\"Getting Started with LILYGO T-SIM7000G ESP32 (LTE, GPRS, and GPS)\">Getting Started with LILYGO T-SIM7000G ESP32 (LTE, GPRS, and GPS)<\/a><\/li>\n<\/ul>\n\n\n\n<p><strong>Where to buy LILYGO T-SIM7000G ESP32?<\/strong><\/p>\n\n\n\n<p>Check the following link:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/t-sim7000g-esp32\/\" target=\"_blank\" rel=\"noreferrer noopener\">LILYGO T-SIM7000G ESP32 (LTE, GPRS, and GPS) &#8211; Maker Advisor<\/a><\/li>\n<\/ul>\n\n\n\n<p>All stores in the previous link should sell the latest version, but double-check the product page, just in case the seller changes something.<\/p>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Libraries<\/h2>\n\n\n\n<p>The ESP32 communicates with the SIM7000G chip by sending AT commands via serial communication. You don&#8217;t need a library, you can simply establish a serial communication with the module and start sending AT commands. There&#8217;s a manual with all the SIM7000G AT commands:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/cdn.geekfactory.mx\/sim7000g\/SIM7000%20Series_AT%20Command%20Manual_V1.06.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">SIM7000G AT Commands Manual<\/a><\/li>\n<\/ul>\n\n\n\n<p>However, it might be more practical to use a library. For example, the <a href=\"https:\/\/github.com\/vshymanskyy\/TinyGSM\" target=\"_blank\" rel=\"noreferrer noopener\">TinyGSM<\/a> library knows which commands to send, and how to handle AT responses, and wraps that into the standard Arduino Client interface\u2014that&#8217;s the library we&#8217;ll use in this tutorial.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Installing the TinyGSM Library<\/h4>\n\n\n\n<p>Open your Arduino IDE and go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>. The Library Manager should open. Search for&nbsp;<strong>TinyGSM<\/strong>. Select the TinyGSM library by Volodymyr Shymanskyy.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"278\" height=\"307\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/Arduino-IDE-2-Install-TinyGSM-Library-using-Libraries-Manager-1.png?resize=278%2C307&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino IDE 2 Install TinyGSM Library using Libraries Manager\" class=\"wp-image-147738\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/Arduino-IDE-2-Install-TinyGSM-Library-using-Libraries-Manager-1.png?w=278&amp;quality=100&amp;strip=all&amp;ssl=1 278w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/Arduino-IDE-2-Install-TinyGSM-Library-using-Libraries-Manager-1.png?resize=272%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 272w\" sizes=\"(max-width: 278px) 100vw, 278px\" \/><\/figure><\/div>\n\n\n<p>You also need to install the StreamDebugger library. Go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>, search for <strong>StreamDebugger<\/strong>, and install it.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"275\" height=\"305\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/Arduino-IDE-2-Install-StreamDebugger-Library-using-Libraries-Manager.png?resize=275%2C305&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino IDE 2 Install StreamDebugger Library using Libraries Manager\" class=\"wp-image-148663\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/Arduino-IDE-2-Install-StreamDebugger-Library-using-Libraries-Manager.png?w=275&amp;quality=100&amp;strip=all&amp;ssl=1 275w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/Arduino-IDE-2-Install-StreamDebugger-Library-using-Libraries-Manager.png?resize=270%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 270w\" sizes=\"(max-width: 275px) 100vw, 275px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Preparing the LILYGO T-SIM7000G ESP32 Board<\/h2>\n\n\n\n<p>To get GPS data with your board, you don&#8217;t need to connect a SIM card. You only need to connect the GPS antenna to the board.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-SIM7000G-GPS-antenna-connected.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 SIM7000G GPS antenna connected\" class=\"wp-image-114224\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-SIM7000G-GPS-antenna-connected.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-SIM7000G-GPS-antenna-connected.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">LILYGO T-SIM7000G ESP32 Board\u2014Get GPS Data<\/h2>\n\n\n\n<p>Copy the following code to your Arduino IDE.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/lilygo-t-sim7000g-esp32-gps-data\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy\n  of this software and associated documentation files.\n  \n  The above copyright notice and this permission notice shall be included in all\n  copies or substantial portions of the Software.\n*\/\n\n#define TINY_GSM_MODEM_SIM7000\n#define TINY_GSM_RX_BUFFER 1024 \/\/ Set RX buffer to 1Kb\n\n#include &lt;TinyGsmClient.h&gt;\n\n\/\/ LilyGO T-SIM7000G Pinout\n#define UART_BAUD   115200\n#define PIN_DTR     25\n#define PIN_TX      27\n#define PIN_RX      26\n#define PWR_PIN     4\n\n#define LED_PIN     12\n\n\/\/ Set serial for debug console (to Serial Monitor, default speed 115200)\n#define SerialMon Serial\n\/\/ Set serial for AT commands\n#define SerialAT  Serial1\n\nTinyGsm modem(SerialAT);\n\nvoid setup(){\n  SerialMon.begin(115200);\n  SerialMon.println(&quot;Place your board outside to catch satelite signal&quot;);\n\n  \/\/ Set LED OFF\n  pinMode(LED_PIN, OUTPUT);\n  digitalWrite(LED_PIN, HIGH);\n\n  \/\/Turn on the modem\n  pinMode(PWR_PIN, OUTPUT);\n  digitalWrite(PWR_PIN, HIGH);\n  delay(300);\n  digitalWrite(PWR_PIN, LOW);\n\n  delay(1000);\n  \n  \/\/ Set module baud rate and UART pins\n  SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);\n\n  \/\/ Restart takes quite some time\n  \/\/ To skip it, call init() instead of restart()\n  SerialMon.println(&quot;Initializing modem...&quot;);\n  if (!modem.restart()) {\n    Serial.println(&quot;Failed to restart modem, attempting to continue without restarting&quot;);\n  }\n  \n  \/\/ Print modem info\n  String modemName = modem.getModemName();\n  delay(500);\n  SerialMon.println(&quot;Modem Name: &quot; + modemName);\n\n  String modemInfo = modem.getModemInfo();\n  delay(500);\n  SerialMon.println(&quot;Modem Info: &quot; + modemInfo);\n}\n\nvoid loop(){\n  \/\/ Set SIM7000G GPIO4 HIGH ,turn on GPS power\n  \/\/ CMD:AT+SGPIO=0,4,1,1\n  \/\/ Only in version 20200415 is there a function to control GPS power\n  modem.sendAT(&quot;+SGPIO=0,4,1,1&quot;);\n  if (modem.waitResponse(10000L) != 1) {\n    SerialMon.println(&quot; SGPIO=0,4,1,1 false &quot;);\n  }\n\n  modem.enableGPS();\n  \n  delay(15000);\n  float lat      = 0;\n  float lon      = 0;\n  float speed    = 0;\n  float alt     = 0;\n  int   vsat     = 0;\n  int   usat     = 0;\n  float accuracy = 0;\n  int   year     = 0;\n  int   month    = 0;\n  int   day      = 0;\n  int   hour     = 0;\n  int   min      = 0;\n  int   sec      = 0;\n  \n  for (int8_t i = 15; i; i--) {\n    SerialMon.println(&quot;Requesting current GPS\/GNSS\/GLONASS location&quot;);\n    if (modem.getGPS(&amp;lat, &amp;lon, &amp;speed, &amp;alt, &amp;vsat, &amp;usat, &amp;accuracy,\n                     &amp;year, &amp;month, &amp;day, &amp;hour, &amp;min, &amp;sec)) {\n      SerialMon.println(&quot;Latitude: &quot; + String(lat, 8) + &quot;\\tLongitude: &quot; + String(lon, 8));\n      SerialMon.println(&quot;Speed: &quot; + String(speed) + &quot;\\tAltitude: &quot; + String(alt));\n      SerialMon.println(&quot;Visible Satellites: &quot; + String(vsat) + &quot;\\tUsed Satellites: &quot; + String(usat));\n      SerialMon.println(&quot;Accuracy: &quot; + String(accuracy));\n      SerialMon.println(&quot;Year: &quot; + String(year) + &quot;\\tMonth: &quot; + String(month) + &quot;\\tDay: &quot; + String(day));\n      SerialMon.println(&quot;Hour: &quot; + String(hour) + &quot;\\tMinute: &quot; + String(min) + &quot;\\tSecond: &quot; + String(sec));\n      break;\n    } \n    else {\n      SerialMon.println(&quot;Couldn't get GPS\/GNSS\/GLONASS location, retrying in 15s.&quot;);\n      delay(15000L);\n    }\n  }\n  SerialMon.println(&quot;Retrieving GPS\/GNSS\/GLONASS location again as a string&quot;);\n  String gps_raw = modem.getGPSraw();\n  SerialMon.println(&quot;GPS\/GNSS Based Location String: &quot; + gps_raw);\n  SerialMon.println(&quot;Disabling GPS&quot;);\n  modem.disableGPS();\n\n  \/\/ Set SIM7000G GPIO4 LOW ,turn off GPS power\n  \/\/ CMD:AT+SGPIO=0,4,1,0\n  \/\/ Only in version 20200415 is there a function to control GPS power\n  modem.sendAT(&quot;+SGPIO=0,4,1,0&quot;);\n  if (modem.waitResponse(10000L) != 1) {\n    SerialMon.println(&quot; SGPIO=0,4,1,0 false &quot;);\n  }\n\n  delay(200);\n  \/\/ Do nothing forevermore\n  while (true) {\n      modem.maintain();\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/LILYGO_T-SIM7000G\/GPS_Tester.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p>Let&#8217;s take a quick look at the relevant parts of the code.<\/p>\n\n\n\n<p>First, you need to define the module you&#8217;re using. The library is compatible with many different modules. To use the SIM7000G, include the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define TINY_GSM_MODEM_SIM7000<\/code><\/pre>\n\n\n\n<p>Include the TinyGSM library.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;TinyGsmClient.h&gt;<\/code><\/pre>\n\n\n\n<p>The following lines set the board pins to control the modem:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ LilyGO T-SIM7000G Pinout\n#define UART_BAUD   115200\n#define PIN_DTR     25\n#define PIN_TX      27\n#define PIN_RX      26\n#define PWR_PIN     4\n\n#define LED_PIN     12<\/code><\/pre>\n\n\n\n<p>You need to create two Serial instances. One for the Serial Monitor which we&#8217;ll call SerialMon, and another to communicate with the modem via AT commands, which we call <span class=\"rnthl rntliteral\">SerialAT<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set serial for debug console (to Serial Monitor, default speed 115200)\n#define SerialMon Serial\n\/\/ Set serial for AT commands\n#define SerialAT  Serial1<\/code><\/pre>\n\n\n\n<p>Create a <span class=\"rnthl rntliteral\">TinyGSM<\/span> instance called modem on the <span class=\"rnthl rntliteral\">SerialAT<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>TinyGsm modem(SerialAT);<\/code><\/pre>\n\n\n\n<p>Initialize the Serial Monitor at a baud rate of 115200.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>SerialMon.begin(115200);<\/code><\/pre>\n\n\n\n<p>Turn on the modem by setting the power pin to HIGH and LOW at a specific interval.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/Turn on the modem\npinMode(PWR_PIN, OUTPUT);\ndigitalWrite(PWR_PIN, HIGH);\ndelay(300);\ndigitalWrite(PWR_PIN, LOW);<\/code><\/pre>\n\n\n\n<p>Initialize a Serial communication with the modem on the RX and TX pins we defined earlier.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);<\/code><\/pre>\n\n\n\n<p>Restart or init the modem:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Restart takes quite some time\n\/\/ To skip it, call init() instead of restart()\nSerialMon.println(\"Initializing modem...\");\nif (!modem.restart()) {\n  Serial.println(\"Failed to restart modem, attempting to continue without restarting\");\n}<\/code><\/pre>\n\n\n\n<p>Get some modem info using the <span class=\"rnthl rntliteral\">getModemName()<\/span> and <span class=\"rnthl rntliteral\">getModemInfo()<\/span> methods. These lines are optional and you don&#8217;t actually need them to get GPS data.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Print modem info\nString modemName = modem.getModemName();\ndelay(500);\nSerialMon.println(\"Modem Name: \" + modemName);\n\nString modemInfo = modem.getModemInfo();\ndelay(500);\nSerialMon.println(\"Modem Info: \" + modemInfo);<\/code><\/pre>\n\n\n\n<p>There are two versions of the LILYGO SIM7000G ESP32 board. The latest comes with active GPS antenna power control\u2014when the module GPIO 4 is not turned on the antenna consumes only the static current of the LDO. This means we need to turn GPIO 4 on before getting GPS data to power the antenna. That&#8217;s what the next lines do:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set SIM7000G GPIO4 HIGH ,turn on GPS power\n\/\/ CMD:AT+SGPIO=0,4,1,1\n\/\/ Only in version 20200415 is there a function to control GPS power\nmodem.sendAT(\"+SGPIO=0,4,1,1\");\nif (modem.waitResponse(10000L) != 1) {\n  SerialMon.println(\" SGPIO=0,4,1,1 false \");\n}<\/code><\/pre>\n\n\n\n<p>You can start GPS using the <span class=\"rnthl rntliteral\">enableGPS()<\/span> method.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>modem.enableGPS();<\/code><\/pre>\n\n\n\n<p>Then, we create variables where we&#8217;ll save the GPS data. We&#8217;ll get latitude, longitude, speed, altitude, visible satellites, used satellites, accuracy, and date and time.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>delay(15000);\nfloat lat      = 0;\nfloat lon      = 0;\nfloat speed    = 0;\nfloat alt     = 0;\nint   vsat     = 0;\nint   usat     = 0;\nfloat accuracy = 0;\nint   year     = 0;\nint   month    = 0;\nint   day      = 0;\nint   hour     = 0;\nint   min      = 0;\nint   sec      = 0;<\/code><\/pre>\n\n\n\n<p>The following line gets GPS data using the <span class=\"rnthl rntliteral\">getGPS()<\/span> method and saves the values on the right variables.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (modem.getGPS(&amp;lat, &amp;lon, &amp;speed, &amp;alt, &amp;vsat, &amp;usat, &amp;accuracy,\n                     &amp;year, &amp;month, &amp;day, &amp;hour, &amp;min, &amp;sec))<\/code><\/pre>\n\n\n\n<p>Then, we simply print the values on the Serial Monitor. Now that you have the relevant information saved on variables, it&#8217;s easy to modify this project for your own needs. For example, a GPS tracker, GPS data logger, etc.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>SerialMon.println(\"Latitude: \" + String(lat, 8) + \"\\tLongitude: \" + String(lon, 8));\nSerialMon.println(\"Speed: \" + String(speed) + \"\\tAltitude: \" + String(alt));\nSerialMon.println(\"Visible Satellites: \" + String(vsat) + \"\\tUsed Satellites: \" + String(usat));\nSerialMon.println(\"Accuracy: \" + String(accuracy));\nSerialMon.println(\"Year: \" + String(year) + \"\\tMonth: \" + String(month) + \"\\tDay: \" + String(day));\nSerialMon.println(\"Hour: \" + String(hour) + \"\\tMinute: \" + String(min) + \"\\tSecond: \" + String(sec));<\/code><\/pre>\n\n\n\n<p>You can also get all raw data returned by the GPS using the <span class=\"rnthl rntliteral\">getGPRSraw()<\/span> method. <\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String gps_raw = modem.getGPSraw();\nSerialMon.println(\"GPS\/GNSS Based Location String: \" + gps_raw);<\/code><\/pre>\n\n\n\n<p>When you&#8217;re done using GPS, you can turn it off using the <span class=\"rnthl rntliteral\">disableGPS()<\/span> method:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>modem.disableGPS();<\/code><\/pre>\n\n\n\n<p>And finally, turn off the power to the antenna by turning GPIO 4 off:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set SIM7000G GPIO4 LOW ,turn off GPS power\n\/\/ CMD:AT+SGPIO=0,4,1,0\n\/\/ Only in version 20200415 is there a function to control GPS power\nmodem.sendAT(\"+SGPIO=0,4,1,0\");\nif (modem.waitResponse(10000L) != 1) {\n  SerialMon.println(\" SGPIO=0,4,1,0 false \");\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>In your Arduino IDE, go to <strong>Tools <\/strong>&gt; <strong>Boards <\/strong>and select the <strong>ESP32 Dev Module<\/strong>. Select the COM port in <strong>Tools <\/strong>&gt; <strong>Port<\/strong>.<\/p>\n\n\n\n<p>Then, upload the code to your board.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"30\" height=\"30\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/arduino-2-0-upload-button.png?resize=30%2C30&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino 2.0 Upload Button\" class=\"wp-image-103678\"\/><\/figure><\/div>\n\n\n<p>Open the Serial Monitor at a baud rate of 115200 and press the on-board RST button to restart the board. Place your board outside or next to a window or door so that it can catch satellite signals.<\/p>\n\n\n\n<p>It may take some time until it can get some GPS data, as you can see in the screenshot of my Serial Monitor.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"580\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/GPS_tester_serial_monitor.png?resize=601%2C580&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 T-SIM7000G get GPS data\" class=\"wp-image-114221\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/GPS_tester_serial_monitor.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/GPS_tester_serial_monitor.png?resize=300%2C290&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n<p>As you can see, it gets latitude, longitude, speed, altitude, visible satellites, number of used satellites to get position, accuracy, and UTC date and time. The longitude and latitude I got were very accurate. So, in my case, it was working pretty well to get the location.<\/p>\n\n\n\n<p>It also outputs the complete GNSS navigation information parsed from NMEA sentences (that you can&#8217;t see above because the Serial Monitor window is too small). NMEA stands for National Marine Electronics Association, and in the world of GPS, it is a standard data format supported by GPS manufacturers. The output is as follows. The commas separate different values. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1,1,20220809173458.000,41.12XXXX,-8.52XXXX,140.200,0.00,237.6,1,,2.3,2.5,1.0,,20,5,1,,48,,<\/code><\/pre>\n\n\n\n<p>Here&#8217;s what each value means, in order:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>GNSS run status<\/li>\n\n\n\n<li>Fix status<\/li>\n\n\n\n<li>UTC date and time<\/li>\n\n\n\n<li>Latitude<\/li>\n\n\n\n<li>Longitude<\/li>\n\n\n\n<li>MSL altitude<\/li>\n\n\n\n<li>Speed over ground<\/li>\n\n\n\n<li>Course over ground<\/li>\n\n\n\n<li>Fix mode<\/li>\n\n\n\n<li>Reserver1<\/li>\n\n\n\n<li>HDOP<\/li>\n\n\n\n<li>PDOP<\/li>\n\n\n\n<li>VDOP<\/li>\n\n\n\n<li>Reserved2<\/li>\n\n\n\n<li>GNSS Satellites in View<\/li>\n\n\n\n<li>GPS Satellites used<\/li>\n\n\n\n<li>GLONASS Satellites used<\/li>\n\n\n\n<li>Reserver3<\/li>\n\n\n\n<li>C\/N0 max<\/li>\n\n\n\n<li>HPA<\/li>\n\n\n\n<li>VPA<\/li>\n<\/ol>\n\n\n\n<p>You can learn more about these parameters and possible values by checking the <strong>AT+CGNSINF<\/strong> AT command on the SIM7000G AT commands manual.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned how to use the LILYGO T-SIM7000G ESP32 board to get GPS data. We showed you a simple example that prints the GPS data in the Serial Monitor. The idea is to modify the example and apply it to your own projects. It should also be compatible with a &#8220;regular&#8221; ESP32 board connected to a separate SIM7000G module.<\/p>\n\n\n\n<p>The ESP32 T-SIM7000G board features will allow you to build a wide variety of projects taking into account that it can connect to the internet in remote locations using a SIM card data plan and send SMS. The fact that it can use a battery and solar panels for charging is also great, and the microSD card can also be handy for datalogging or saving configuration settings.<\/p>\n\n\n\n<p>We hope you found this tutorial useful. Have you developed any projects with this board? Let us know in the comments section below.<\/p>\n\n\n\n<p>You may also like the following tutorials (that with minor changes can be used with the SIM7000G board):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-cloud-mqtt-broker-sim800l\/\">Connect ESP32 to Cloud MQTT Broker (TTGO T-Call ESP32 SIM800L)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-sim800l-send-text-messages-sms\/\">ESP32 SIM800L: Send Text Messages (SMS Alert) with Sensor Readings<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-sim800l-publish-data-to-cloud\/\">ESP32 Publish Data to Cloud without Wi-Fi (TTGO T-Call ESP32 SIM800L)<\/a><\/li>\n<\/ul>\n\n\n\n<p>Learn more about the ESP32 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/firebase-esp32-esp8266-ebook\/\">Firebase Web App with ESP32 and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">Free ESP32 Projects and Tutorials<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n\n\n\n<p>  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this quick guide, you&#8217;ll learn how to get GPS data with the LILYGO T-SIM7000G ESP32 board using Arduino IDE. This tutorial is also compatible with a &#8220;regular&#8221; ESP32 connected &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"LILYGO T-SIM7000G ESP32: Get GPS Data (Latitude, Longitude, Altitude, and more)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/lilygo-t-sim7000g-esp32-gps-data\/#more-114218\" aria-label=\"Read more about LILYGO T-SIM7000G ESP32: Get GPS Data (Latitude, Longitude, Altitude, and more)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":114261,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[276,281,277,299,264],"tags":[],"class_list":["post-114218","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-esp32-project","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-T-SIM7000-ESP32-Get-GPS-Data.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/114218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=114218"}],"version-history":[{"count":14,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/114218\/revisions"}],"predecessor-version":[{"id":148670,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/114218\/revisions\/148670"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/114261"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=114218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=114218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=114218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}