{"id":114056,"date":"2022-09-09T13:15:08","date_gmt":"2022-09-09T13:15:08","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=114056"},"modified":"2024-02-20T11:38:36","modified_gmt":"2024-02-20T11:38:36","slug":"lilygo-t-sim7000g-esp32-lte-gprs-gps","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/lilygo-t-sim7000g-esp32-lte-gprs-gps\/","title":{"rendered":"Getting Started with LILYGO T-SIM7000G ESP32 (LTE, GPRS, and GPS)"},"content":{"rendered":"\n<p>Get started with the ESP32 and the SIM7000G LTE\/GPS\/GPRS module. Throughout this tutorial, we&#8217;ll use the LILYGO T-SIM7000G ESP32 board that combines the ESP32 chip, the SIM7000G module, microSD card slot, battery holder, and charger on the same board. Besides Wi-Fi and Bluetooth, you can communicate with this ESP32 board using SMS. You can also connect it to the internet using your SIM card data plan and get GPS location.<\/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\/Getting-Started-LILYGO-T-SIM7000G-ESP32.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Getting Started with LILYGO T-SIM7000G ESP32 LTE GPRS GPS\" class=\"wp-image-114188\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/Getting-Started-LILYGO-T-SIM7000G-ESP32.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/Getting-Started-LILYGO-T-SIM7000G-ESP32.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\/Getting-Started-LILYGO-T-SIM7000G-ESP32.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\/Getting-Started-LILYGO-T-SIM7000G-ESP32.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 LILYGO T-SIM7000G 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 an 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>Here&#8217;s a summary of the LILYGO T-SIM7000G ESP32 board features:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Supply voltage: 3.3V DC or 5V DC<\/li>\n\n\n\n<li>ESP32 chip (WROVER-B Module) (240MHz dual-core processor)<\/li>\n\n\n\n<li>Flash memory: 4MB<\/li>\n\n\n\n<li>PSRAM: 8MB<\/li>\n\n\n\n<li>SRAM: 520KB<\/li>\n\n\n\n<li>Built-in Wi-Fi<\/li>\n\n\n\n<li>Built-in Bluetooth<\/li>\n\n\n\n<li>USB to serial converter: CP2104 or CH9102 (drivers)<\/li>\n\n\n\n<li>Built-in SIM7000G module<\/li>\n\n\n\n<li>Built-in nano SIM card slot<\/li>\n\n\n\n<li>Built-in SIM antenna slot<\/li>\n\n\n\n<li>Built-in GPS antenna slot<\/li>\n\n\n\n<li>Built-in Li-ion\/Li-Po battery charging circuit:\n<ul class=\"wp-block-list\">\n<li>DW01A battery protection IC<\/li>\n\n\n\n<li>CN3065 solar energy charging interface for 4.4-6.8V solar panel<\/li>\n\n\n\n<li>Built-in 1x 18650 battery holder<\/li>\n\n\n\n<li>Built-in solar panel connector 2p JST-PH<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Built-in Micro SD card slot<\/li>\n\n\n\n<li>Built-in on\/off switch<\/li>\n<\/ul>\n\n\n\n<p>To use the capabilities of this board you need to have a nano SIM card with a data plan and a&nbsp;<a href=\"https:\/\/makeradvisor.com\/tools\/usb-c-data-charging-cable\/\" target=\"_blank\" rel=\"noreferrer noopener\">USB-C cable<\/a>&nbsp;to upload code to the board.<\/p>\n\n\n\n<p>The package includes an external antenna for LTE and another antenna for GPS.<\/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-SIM7000G-GPS-antenna-SIM-antenna.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 SIM7000G GPS antenna and SIM antenna\" class=\"wp-image-114190\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-SIM7000G-GPS-antenna-SIM-antenna.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-SIM-antenna.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>There are two versions of this board (Version 20191227 and Version 20200415). The picture below shows the two versions. Visually, they mainly differ on the position of the nano SIM card holder.<\/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=\"512\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-SIM700G-LILYGO-OLD-VS-NEW.jpg?resize=750%2C512&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LILYGO ESP32 SIM7000G OLD VS NEW MODEL\" class=\"wp-image-114181\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-SIM700G-LILYGO-OLD-VS-NEW.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-SIM700G-LILYGO-OLD-VS-NEW.jpg?resize=300%2C205&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The first version had some design issues, so it is recommended to get the latest version. Aditionally, the latest version comes with some improvements taking into account users&#8217; feedback. I got my board a long time ago, I&#8217;ve got the first version and that&#8217;s the one we&#8217;ll use throughout this tutorial. However, this is also compatible with the latest board. <\/p>\n\n\n\n<p>Here&#8217;s a list of the improvements on the latest version (<a href=\"https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G?spm=a2g0o.detail.1000023.1.35684571ByWwA0\" target=\"_blank\" rel=\"noreferrer noopener\">check the documentation<\/a>):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Added active GPS antenna power control, when the module GPIO 4 is not turned on, the antenna consumes only the static current of the LDO;<\/li>\n\n\n\n<li>Replaced TP4056 with CN3065 for solar charge input management;<\/li>\n\n\n\n<li>Added reverse battery protection;<\/li>\n\n\n\n<li>Added battery overcharge protection;<\/li>\n\n\n\n<li>Added battery over-discharge protection.<\/li>\n<\/ul>\n\n\n\n<p>You can check the schematic diagrams for each version on the following links:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G\/blob\/master\/schematic\/SIM7000G_20191227.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">LILYGO T-SIM7000G ESP32 <strong>Version 1.0<\/strong> schematic diagram<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G\/blob\/master\/schematic\/SIM7000G_20200415.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">LILYGO T-SIM7000G ESP32 <strong>Version 1.1<\/strong> schematic diagram<\/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\">LILYGO T-SIM7000G ESP32 Pinout<\/h2>\n\n\n\n<p>The following pictures show the pinout of the T-SIM7000G ESP32 board.<\/p>\n\n\n\n<p>This is the pinout for version V1.0.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-ESP32-V1_0_pinout.jpg?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"848\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-ESP32-V1_0_pinout.jpg?resize=1200%2C848&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LILYGO T-SIM7000G ESP32 pinout version 1.0\" class=\"wp-image-114183\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-ESP32-V1_0_pinout.jpg?w=1365&amp;quality=100&amp;strip=all&amp;ssl=1 1365w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-ESP32-V1_0_pinout.jpg?resize=300%2C212&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-ESP32-V1_0_pinout.jpg?resize=1024%2C724&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-ESP32-V1_0_pinout.jpg?resize=768%2C543&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><figcaption class=\"wp-element-caption\"><a href=\"https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G\/blob\/master\/Historical\/SIM7000G_20191227\/README.MD\" target=\"_blank\" rel=\"noreferrer noopener\">Image source<\/a><\/figcaption><\/figure><\/div>\n\n\n<p>And this is the pinout for the improved board V1.1.<\/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=\"1000\" height=\"707\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-V1_1-ESP32-pinout.jpg?resize=1000%2C707&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LILYGO T-SIM7000G ESP32 pinout version 1.1\" class=\"wp-image-114184\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-V1_1-ESP32-pinout.jpg?w=1000&amp;quality=100&amp;strip=all&amp;ssl=1 1000w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-V1_1-ESP32-pinout.jpg?resize=300%2C212&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-SIM7000G-V1_1-ESP32-pinout.jpg?resize=768%2C543&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\"><a href=\"https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G\/blob\/master\/Historical\/SIM7000G_20200415\/README.MD\" target=\"_blank\" rel=\"noreferrer noopener\">Image source<\/a><\/figcaption><\/figure><\/div>\n\n\n<p>The following table shows the connections between the ESP32 and the SIM7000G chip:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>SIM7000G<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td>TX<\/td><td><span class=\"rnthl rntcgray\">GPIO 26<\/span><\/td><\/tr><tr><td>RX<\/td><td><span class=\"rnthl rntcgray\">GPIO 27<\/span><\/td><\/tr><tr><td>POWER<\/td><td><span class=\"rnthl rntcred\">GPIO 4<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>To communicate with the microSD card, you need SPI communication protocol. These are the GPIOs used:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>MicroSD Card (TF card)<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td>MOSI<\/td><td><span class=\"rnthl rntcgray\">GPIO 15<\/span><\/td><\/tr><tr><td>SCLK<\/td><td><span class=\"rnthl rntcpurple\">GPIO 14<\/span><\/td><\/tr><tr><td>CS<\/td><td><span class=\"rnthl rntcgray\">GPIO 13<\/span><\/td><\/tr><tr><td>MISO<\/td><td><span class=\"rnthl rntcpurple\">GPIO 2<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">SIM Card<\/h2>\n\n\n\n<p>This board only supports nano SIM cards. You need a SIM card for LTE and GPRS. However, if you only want to use GPS data, you don&#8217;t need a SIM card.<\/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\/LILYGO-T-SIM7000G-ESP32-nano-SIM-card.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"LILYGO T-SIM7000G ESP32 nano SIM card\" class=\"wp-image-114210\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-T-SIM7000G-ESP32-nano-SIM-card.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/LILYGO-T-SIM7000G-ESP32-nano-SIM-card.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>To use LTE and GPRS you need\u00a0a SIM card with some data plan. This can be expensive in some countries, so it might be cost-prohibitive depending on how much you can get a data plan for in your country.<\/p>\n\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<p>Where we live (Portugal), we can get a SIM card with data plan, calls, and SMS (enough for ESP32 projects) for approximately $12. We recommend using a SIM card with a prepaid or monthly plan, so that you know exactly how much you\u2019ll spend. There are also companies specialized in SIM cards for IoT projects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">APN Details<\/h2>\n\n\n\n<p>To connect your SIM card to the internet, you need to have your phone plan provider&#8217;s <strong>APN details<\/strong>. You need the domain name, username, and password.<\/p>\n\n\n\n<p>In my case, I\u2019m using Vodafone Portugal. If you search for&nbsp;GPRS APN settings&nbsp;followed by your phone plan provider name, (in my case its: \u201cGPRS APN Vodafone<strong> Portugal<\/strong>\u201d), you can usually find in a forum or in their website all the information that you need.<\/p>\n\n\n\n<p>It might be a bit tricky to find the details if you don\u2019t use a well-known provider. So, you might need to contact them directly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">AT Commands<\/h2>\n\n\n\n<p>AT commands are used to control MODEMs, as is the case of the SIM7000G. In the case of the ESP32, you send the AT commands via serial communication protocol. Then, the modem responds back also via serial communication.<\/p>\n\n\n\n<p>There are four types of AT commands: test; read; set; execution. You can find the complete list of AT commands for the SIM7000G on the following link:<\/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<\/a><\/li>\n<\/ul>\n\n\n\n<p>Here are some of the most common AT commands:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>check communication with the module: <strong>AT<\/strong><\/li>\n\n\n\n<li>check if SIM card is ready: <strong>AT+CPIN?<\/strong><\/li>\n\n\n\n<li>check the registration status of the device: <strong>AT+CGREG?<\/strong><\/li>\n\n\n\n<li>send SMS to a number: <strong>AT+CMGS=<span style=\"color: #ff0000;\">PHONE_NUMBER<\/span><\/strong>(in international format)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Libraries<\/h2>\n\n\n\n<p>As we explained previously, 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. <\/p>\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\" loading=\"lazy\" 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>Before testing your board, you need to follow the next steps:<\/p>\n\n\n\n<p><strong>1)<\/strong> Insert a nano SIM card;<\/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\/nano-SIM-card-vodafone.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Nano SIM card vodafone\" class=\"wp-image-114211\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/nano-SIM-card-vodafone.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/nano-SIM-card-vodafone.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><strong>2) <\/strong>Connect the Full Band LTE antenna (SIM);<\/p>\n\n\n\n<p><strong>3)<\/strong> Connect the GPS antenna.<\/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-T-SIM7000G-antennas.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 T-SIM7000G antennas\" class=\"wp-image-114213\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-T-SIM7000G-antennas.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-T-SIM7000G-antennas.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 class=\"rntbox rntcred\">If you want to test the microSD card features, you should only connect a microSD card, after uploading the code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">LILYGO T-SIM7000G ESP32 Network Test<\/h2>\n\n\n\n<p>The first sketch you should run on your board is the Network Test. This will tell you the network selection settings you should use\u2014this depends on the SIM card, modem(SIM7000G), and the mobile network operator it uses.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Copy the following code to your Arduino IDE (the code was adapted <a href=\"https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G\/blob\/master\/examples\/Arduino_NetworkTest\/Arduino_NetworkTest.ino\" target=\"_blank\" rel=\"noreferrer noopener\">from this example<\/a>).<\/li>\n<\/ol>\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-lte-gprs-gps\/\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\/\/ Original code: https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G\/blob\/master\/examples\/Arduino_NetworkTest\/Arduino_NetworkTest.ino\n\n#define TINY_GSM_MODEM_SIM7000\n#define TINY_GSM_RX_BUFFER 1024 \/\/ Set RX buffer to 1Kb\n\n#define SerialAT Serial1\n\/\/ Set serial for debug console (to the Serial Monitor, default speed 115200)\n#define SerialMon Serial\n\n\/\/ See all AT commands, if wanted\n\/\/ #define DUMP_AT_COMMANDS\n\n\/\/ set GSM PIN, if any\n#define GSM_PIN &quot;&quot;\n\n\/\/ Your GPRS credentials, if any\nconst char apn[]  = &quot;&quot;;     \/\/SET TO YOUR APN\nconst char gprsUser[] = &quot;&quot;;\nconst char gprsPass[] = &quot;&quot;;\n\n#include &lt;TinyGsmClient.h&gt;\n#include &lt;SPI.h&gt;\n#include &lt;SD.h&gt;\n#include &lt;Ticker.h&gt;\n\n#ifdef DUMP_AT_COMMANDS\n  #include &lt;StreamDebugger.h&gt;\n  StreamDebugger debugger(SerialAT, SerialMon);\n  TinyGsm modem(debugger);\n#else\n  TinyGsm modem(SerialAT);\n#endif\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 SD_MISO             2\n#define SD_MOSI             15\n#define SD_SCLK             14\n#define SD_CS               13\n#define LED_PIN             12\n\n\nvoid modemPowerOn(){\n  pinMode(PWR_PIN, OUTPUT);\n  digitalWrite(PWR_PIN, LOW);\n  delay(1000);\n  digitalWrite(PWR_PIN, HIGH);\n}\n\nvoid modemPowerOff(){\n  pinMode(PWR_PIN, OUTPUT);\n  digitalWrite(PWR_PIN, LOW);\n  delay(1500);\n  digitalWrite(PWR_PIN, HIGH);\n}\n\n\nvoid modemRestart(){\n  modemPowerOff();\n  delay(1000);\n  modemPowerOn();\n}\n\nvoid setup(){\n  \/\/ Set console baud rate\n  SerialMon.begin(115200);\n\n  delay(10);\n\n  \/\/ Set LED OFF\n  pinMode(LED_PIN, OUTPUT);\n  digitalWrite(LED_PIN, HIGH);\n\n  modemPowerOn();\n\n  Serial.println(&quot;========SDCard Detect.======&quot;);\n  SPI.begin(SD_SCLK, SD_MISO, SD_MOSI);\n  if (!SD.begin(SD_CS)) {\n      Serial.println(&quot;SDCard MOUNT FAIL&quot;);\n  } else {\n    uint32_t cardSize = SD.cardSize() \/ (1024 * 1024);\n    String str = &quot;SDCard Size: &quot; + String(cardSize) + &quot;MB&quot;;\n    Serial.println(str);\n  }\n  Serial.println(&quot;===========================&quot;);\n\n  SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);\n\n\n  Serial.println(&quot;\/**********************************************************\/&quot;);\n  Serial.println(&quot;To initialize the network test, please make sure your LTE &quot;);\n  Serial.println(&quot;antenna has been connected to the SIM interface on the board.&quot;);\n  Serial.println(&quot;\/**********************************************************\/\\n\\n&quot;);\n\n  delay(10000);\n}\n\nvoid loop(){\n  String res;\n\n  Serial.println(&quot;========INIT========&quot;);\n\n  if (!modem.init()) {\n    modemRestart();\n    delay(2000);\n    Serial.println(&quot;Failed to restart modem, attempting to continue without restarting&quot;);\n    return;\n  }\n\n  Serial.println(&quot;========SIMCOMATI======&quot;);\n  modem.sendAT(&quot;+SIMCOMATI&quot;);\n  modem.waitResponse(1000L, res);\n  res.replace(GSM_NL &quot;OK&quot; GSM_NL, &quot;&quot;);\n  Serial.println(res);\n  res = &quot;&quot;;\n  Serial.println(&quot;=======================&quot;);\n\n  Serial.println(&quot;=====Preferred mode selection=====&quot;);\n  modem.sendAT(&quot;+CNMP?&quot;);\n  if (modem.waitResponse(1000L, res) == 1) {\n    res.replace(GSM_NL &quot;OK&quot; GSM_NL, &quot;&quot;);\n    Serial.println(res);\n  }\n  res = &quot;&quot;;\n  Serial.println(&quot;=======================&quot;);\n\n\n  Serial.println(&quot;=====Preferred selection between CAT-M and NB-IoT=====&quot;);\n  modem.sendAT(&quot;+CMNB?&quot;);\n  if (modem.waitResponse(1000L, res) == 1) {\n    res.replace(GSM_NL &quot;OK&quot; GSM_NL, &quot;&quot;);\n    Serial.println(res);\n  }\n  res = &quot;&quot;;\n  Serial.println(&quot;=======================&quot;);\n\n\n  String name = modem.getModemName();\n  Serial.println(&quot;Modem Name: &quot; + name);\n\n  String modemInfo = modem.getModemInfo();\n  Serial.println(&quot;Modem Info: &quot; + modemInfo);\n\n  \/\/ Unlock your SIM card with a PIN if needed\n  if ( GSM_PIN &amp;&amp; modem.getSimStatus() != 3 ) {\n    modem.simUnlock(GSM_PIN);\n  }\n\n  for (int i = 0; i &lt;= 4; i++) {\n    uint8_t network[] = {\n        2,  \/*Automatic*\/\n        13, \/*GSM only*\/\n        38, \/*LTE only*\/\n        51  \/*GSM and LTE only*\/\n    };\n    Serial.printf(&quot;Try %d method\\n&quot;, network[i]);\n    modem.setNetworkMode(network[i]);\n    delay(3000);\n    bool isConnected = false;\n    int tryCount = 60;\n    while (tryCount--) {\n      int16_t signal =  modem.getSignalQuality();\n      Serial.print(&quot;Signal: &quot;);\n      Serial.print(signal);\n      Serial.print(&quot; &quot;);\n      Serial.print(&quot;isNetworkConnected: &quot;);\n      isConnected = modem.isNetworkConnected();\n      Serial.println( isConnected ? &quot;CONNECT&quot; : &quot;NO CONNECT&quot;);\n      if (isConnected) {\n        break;\n      }\n      delay(1000);\n      digitalWrite(LED_PIN, !digitalRead(LED_PIN));\n    }\n    if (isConnected) {\n        break;\n    }\n  }\n  digitalWrite(LED_PIN, HIGH);\n\n  Serial.println();\n  Serial.println(&quot;Device is connected .&quot;);\n  Serial.println();\n\n  Serial.println(&quot;=====Inquiring UE system information=====&quot;);\n  modem.sendAT(&quot;+CPSI?&quot;);\n  if (modem.waitResponse(1000L, res) == 1) {\n    res.replace(GSM_NL &quot;OK&quot; GSM_NL, &quot;&quot;);\n    Serial.println(res);\n  }\n\n  Serial.println(&quot;\/**********************************************************\/&quot;);\n  Serial.println(&quot;After the network test is complete, please enter the  &quot;);\n  Serial.println(&quot;AT command in the serial terminal.&quot;);\n  Serial.println(&quot;\/**********************************************************\/\\n\\n&quot;);\n\n  while (1) {\n    while (SerialAT.available()) {\n      SerialMon.write(SerialAT.read());\n    }\n    while (SerialMon.available()) {\n      SerialAT.write(SerialMon.read());\n    }\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\/Network_Test.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<ol start=\"2\"><li>Insert your SIM card pin, if you have it. In my case, I disabled the pin. <\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define GSM_PIN \"\"<\/code><\/pre>\n\n\n\n<ol start=\"3\"><li>Insert your apn details on the following lines:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char apn&#091;]  = \"\";     \/\/SET TO YOUR APN\nconst char gprsUser&#091;] = \"\";\nconst char gprsPass&#091;] = \"\";<\/code><\/pre>\n\n\n\n<p>For example, in my case:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char apn&#091;]  = \"net2.vodafone.pt\";     \/\/SET TO YOUR APN\nconst char gprsUser&#091;] = \"vodafone\";\nconst char gprsPass&#091;] = \"vodafone\";<\/code><\/pre>\n\n\n\n<ol start=\"4\"><li>Go to <strong>Tools <\/strong>&gt; <strong>Board <\/strong>and select <strong>ESP32 Dev Module<\/strong>.<\/li><\/ol>\n\n\n\n<ol start=\"5\"><li>Finally, upload the code to your board.<\/li><\/ol>\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>Now, you can insert a microSD card, if you want to test the microSD card features.<\/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-T-SIM7000G-microSD-card.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 T-SIM7000G microSD card\" class=\"wp-image-114214\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/ESP32-T-SIM7000G-microSD-card.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-T-SIM7000G-microSD-card.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>Then, open the Serial Monitor at a baud rate of 115200. Press the on-board RST button to restart the board.<\/p>\n\n\n\n<p>Wait some time until the board connects to the network (in my case, it may take up to 2 minutes).<\/p>\n\n\n\n<p>You should get something similar in the 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=\"602\" height=\"980\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/SIM7000-network-test-ESP32-Serial-Monitor.png?resize=602%2C980&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 SIM7000G Network Test Serial Monitor\" class=\"wp-image-114114\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/SIM7000-network-test-ESP32-Serial-Monitor.png?w=602&amp;quality=100&amp;strip=all&amp;ssl=1 602w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/08\/SIM7000-network-test-ESP32-Serial-Monitor.png?resize=184%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 184w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure><\/div>\n\n\n<p>You can see that it identifies the microSD card and connects to the network successfully.<\/p>\n\n\n\n<p>Check the preferred mode selection and the preferred selection between CAT-M and NB-IoT. You&#8217;ll need those parameters later, and they differ depending on your SIM card and provider.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">LILYGO T-SIM7000G ESP32: Connect to the Internet, Send SMS, and Get GPS Data<\/h2>\n\n\n\n<p>If everything went as expected, now you&#8217;re ready to test other functions like connecting to the internet, sending SMS, and getting GPS data.<\/p>\n\n\n\n<p>Copy the following code to your Arduino IDE. This code was adapted <a href=\"https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G\/blob\/master\/examples\/Arduino_TinyGSM\/AllFunctions\/AllFunctions.ino\" target=\"_blank\" rel=\"noreferrer noopener\">from this example<\/a>.<\/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-lte-gprs-gps\/\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\/\/ Based on the following example: https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G\/blob\/master\/examples\/Arduino_TinyGSM\/AllFunctions\/AllFunctions.ino\n\n#define TINY_GSM_MODEM_SIM7000\n#define TINY_GSM_RX_BUFFER 1024 \/\/ Set RX buffer to 1Kb\n#define SerialAT Serial1\n\n\/\/ See all AT commands, if wanted\n#define DUMP_AT_COMMANDS\n\n\/\/ set GSM PIN, if any\n#define GSM_PIN &quot;&quot;\n\n\/\/ Your GPRS credentials, if any\nconst char apn[]  = &quot;&quot;;     \/\/SET TO YOUR APN\nconst char gprsUser[] = &quot;&quot;;\nconst char gprsPass[] = &quot;&quot;;\n\n\/\/ Set phone number, if you want to test SMS\n\/\/ Set a recipient phone number to test sending SMS (it must be in international format including the &quot;+&quot; sign)\n#define SMS_TARGET  &quot;&quot;\n\n#include &lt;TinyGsmClient.h&gt;\n#include &lt;SPI.h&gt;\n#include &lt;SD.h&gt;\n#include &lt;Ticker.h&gt;\n\n#ifdef DUMP_AT_COMMANDS  \/\/ if enabled it requires the streamDebugger lib\n  #include &lt;StreamDebugger.h&gt;\n  StreamDebugger debugger(SerialAT, Serial);\n  TinyGsm modem(debugger);\n#else\n  TinyGsm modem(SerialAT);\n#endif\n\n#define uS_TO_S_FACTOR 1000000ULL  \/\/ Conversion factor for micro seconds to seconds\n#define TIME_TO_SLEEP  60          \/\/ Time ESP32 will go to sleep (in seconds)\n\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 SD_MISO     2\n#define SD_MOSI     15\n#define SD_SCLK     14\n#define SD_CS       13\n#define LED_PIN     12\n\nint counter, lastIndex, numberOfPieces = 24;\nString pieces[24], input;\n\nvoid setup(){\n  \/\/ Set console baud rate\n  Serial.begin(115200);\n  delay(10);\n\n  \/\/ Set LED OFF\n  pinMode(LED_PIN, OUTPUT);\n  digitalWrite(LED_PIN, HIGH);\n\n  pinMode(PWR_PIN, OUTPUT);\n  digitalWrite(PWR_PIN, HIGH);\n  delay(300);\n  digitalWrite(PWR_PIN, LOW);\n\n  SPI.begin(SD_SCLK, SD_MISO, SD_MOSI, SD_CS);\n  if (!SD.begin(SD_CS)) {\n    Serial.println(&quot;SDCard MOUNT FAIL&quot;);\n  } else {\n    uint32_t cardSize = SD.cardSize() \/ (1024 * 1024);\n    String str = &quot;SDCard Size: &quot; + String(cardSize) + &quot;MB&quot;;\n    Serial.println(str);\n  }\n\n  Serial.println(&quot;\\nWait...&quot;);\n\n  delay(1000);\n\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  Serial.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\nvoid loop(){\n  \/\/ Restart takes quite some time\n  \/\/ To skip it, call init() instead of restart()\n  Serial.println(&quot;Initializing modem...&quot;);\n  if (!modem.init()) {\n    Serial.println(&quot;Failed to restart modem, attempting to continue without restarting&quot;);\n  }\n\n  String name = modem.getModemName();\n  delay(500);\n  Serial.println(&quot;Modem Name: &quot; + name);\n\n  String modemInfo = modem.getModemInfo();\n  delay(500);\n  Serial.println(&quot;Modem Info: &quot; + modemInfo);\n  \n\n  \/\/ Unlock your SIM card with a PIN if needed\n  if ( GSM_PIN &amp;&amp; modem.getSimStatus() != 3 ) {\n      modem.simUnlock(GSM_PIN);\n  }\n  modem.sendAT(&quot;+CFUN=0 &quot;);\n  if (modem.waitResponse(10000L) != 1) {\n    DBG(&quot; +CFUN=0  false &quot;);\n  }\n  delay(200);\n\n  \/*\n    2 Automatic\n    13 GSM only\n    38 LTE only\n    51 GSM and LTE only\n  * * * *\/\n  String res;\n  \/\/ CHANGE NETWORK MODE, IF NEEDED\n  res = modem.setNetworkMode(2);\n  if (res != &quot;1&quot;) {\n    DBG(&quot;setNetworkMode  false &quot;);\n    return ;\n  }\n  delay(200);\n\n  \/*\n    1 CAT-M\n    2 NB-Iot\n    3 CAT-M and NB-IoT\n  * * *\/\n  \/\/ CHANGE PREFERRED MODE, IF NEEDED\n  res = modem.setPreferredMode(1);\n  if (res != &quot;1&quot;) {\n    DBG(&quot;setPreferredMode  false &quot;);\n    return ;\n  }\n  delay(200);\n\n  \/*AT+CBANDCFG=&lt;mode&gt;,&lt;band&gt;[,&lt;band&gt;\u2026]\n   * &lt;mode&gt; &quot;CAT-M&quot;   &quot;NB-IOT&quot;\n   * &lt;band&gt;  The value of &lt;band&gt; must is in the band list of getting from  AT+CBANDCFG=?\n   * For example, my SIM card carrier &quot;NB-iot&quot; supports B8.  I will configure +CBANDCFG= &quot;Nb-iot &quot;,8\n   *\/\n  \/* modem.sendAT(&quot;+CBANDCFG=\\&quot;NB-IOT\\&quot;,8 &quot;);*\/\n  \n  \/* if (modem.waitResponse(10000L) != 1) {\n       DBG(&quot; +CBANDCFG=\\&quot;NB-IOT\\&quot; &quot;);\n   }*\/\n   delay(200);\n\n  modem.sendAT(&quot;+CFUN=1 &quot;);\n  if (modem.waitResponse(10000L) != 1) {\n    DBG(&quot; +CFUN=1  false &quot;);\n  }\n  delay(200);\n\n  SerialAT.println(&quot;AT+CGDCONT?&quot;);\n  delay(500);\n  if (SerialAT.available()) {\n    input = SerialAT.readString();\n    for (int i = 0; i &lt; input.length(); i++) {\n      if (input.substring(i, i + 1) == &quot;\\n&quot;) {\n        pieces[counter] = input.substring(lastIndex, i);\n        lastIndex = i + 1;\n        counter++;\n       }\n        if (i == input.length() - 1) {\n          pieces[counter] = input.substring(lastIndex, i);\n        }\n      }\n      \/\/ Reset for reuse\n      input = &quot;&quot;;\n      counter = 0;\n      lastIndex = 0;\n\n      for ( int y = 0; y &lt; numberOfPieces; y++) {\n        for ( int x = 0; x &lt; pieces[y].length(); x++) {\n          char c = pieces[y][x];  \/\/gets one byte from buffer\n          if (c == ',') {\n            if (input.indexOf(&quot;: &quot;) &gt;= 0) {\n              String data = input.substring((input.indexOf(&quot;: &quot;) + 1));\n              if ( data.toInt() &gt; 0 &amp;&amp; data.toInt() &lt; 25) {\n                modem.sendAT(&quot;+CGDCONT=&quot; + String(data.toInt()) + &quot;,\\&quot;IP\\&quot;,\\&quot;&quot; + String(apn) + &quot;\\&quot;,\\&quot;0.0.0.0\\&quot;,0,0,0,0&quot;);\n              }\n              input = &quot;&quot;;\n              break;\n            }\n          \/\/ Reset for reuse\n          input = &quot;&quot;;\n         } else {\n          input += c;\n         }\n      }\n    }\n  } else {\n    Serial.println(&quot;Failed to get PDP!&quot;);\n  }\n\n  Serial.println(&quot;\\n\\n\\nWaiting for network...&quot;);\n  if (!modem.waitForNetwork()) {\n    delay(10000);\n    return;\n  }\n\n  if (modem.isNetworkConnected()) {\n    Serial.println(&quot;Network connected&quot;);\n  }\n  \n  \/\/ --------TESTING GPRS--------\n  Serial.println(&quot;\\n---Starting GPRS TEST---\\n&quot;);\n  Serial.println(&quot;Connecting to: &quot; + String(apn));\n  if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {\n    delay(10000);\n    return;\n  }\n\n  Serial.print(&quot;GPRS status: &quot;);\n  if (modem.isGprsConnected()) {\n    Serial.println(&quot;connected&quot;);\n  } else {\n    Serial.println(&quot;not connected&quot;);\n  }\n\n  String ccid = modem.getSimCCID();\n  Serial.println(&quot;CCID: &quot; + ccid);\n\n  String imei = modem.getIMEI();\n  Serial.println(&quot;IMEI: &quot; + imei);\n\n  String cop = modem.getOperator();\n  Serial.println(&quot;Operator: &quot; + cop);\n\n  IPAddress local = modem.localIP();\n  Serial.println(&quot;Local IP: &quot; + String(local));\n\n  int csq = modem.getSignalQuality();\n  Serial.println(&quot;Signal quality: &quot; + String(csq));\n\n  SerialAT.println(&quot;AT+CPSI?&quot;);     \/\/Get connection type and band\n  delay(500);\n  if (SerialAT.available()) {\n    String r = SerialAT.readString();\n    Serial.println(r);\n  }\n\n  Serial.println(&quot;\\n---End of GPRS TEST---\\n&quot;);\n\n  modem.gprsDisconnect();\n  if (!modem.isGprsConnected()) {\n    Serial.println(&quot;GPRS disconnected&quot;);\n  } else {\n    Serial.println(&quot;GPRS disconnect: Failed.&quot;);\n  }\n\n  \/\/ --------TESTING GPS--------\n  \n  Serial.println(&quot;\\n---Starting GPS TEST---\\n&quot;);\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    DBG(&quot; SGPIO=0,4,1,1 false &quot;);\n  }\n  modem.enableGPS();\n  float lat,  lon;\n  while (1) {\n    if (modem.getGPS(&amp;lat, &amp;lon)) {\n      Serial.printf(&quot;lat:%f lon:%f\\n&quot;, lat, lon);\n      break;\n    } else {\n      Serial.print(&quot;getGPS &quot;);\n      Serial.println(millis());\n    }\n    delay(2000);\n  }\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    DBG(&quot; SGPIO=0,4,1,0 false &quot;);\n  }\n  Serial.println(&quot;\\n---End of GPRS TEST---\\n&quot;);\n\n\n  \/\/ --------TESTING SENDING SMS--------\n  res = modem.sendSMS(SMS_TARGET, String(&quot;Hello from &quot;) + imei);\n  DBG(&quot;SMS:&quot;, res ? &quot;OK&quot; : &quot;fail&quot;);\n\n\n  \/\/ --------TESTING POWER DONW--------\n\n  \/\/ Try to power-off (modem may decide to restart automatically)\n  \/\/ To turn off modem completely, please use Reset\/Enable pins\n  modem.sendAT(&quot;+CPOWD=1&quot;);\n  if (modem.waitResponse(10000L) != 1) {\n    DBG(&quot;+CPOWD=1&quot;);\n  }\n  \/\/ The following command does the same as the previous lines\n  modem.poweroff();\n  Serial.println(&quot;Poweroff.&quot;);\n\n  \/\/ GO TO SLEEP\n  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);\n  delay(200);\n  esp_deep_sleep_start();\n\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\/Full_Test.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Insert your SIM card pin on the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define GSM_PIN \"\"<\/code><\/pre>\n\n\n\n<p>Fill your APN details:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char apn&#091;]  = \"net2.vodafone.pt\";     \/\/SET TO YOUR APN\nconst char gprsUser&#091;] = \"vodafone\";\nconst char gprsPass&#091;] = \"vodafone\";<\/code><\/pre>\n\n\n\n<p>Set a recipient phone number to test sending SMS (it must be in international format including the &#8220;+&#8221; sign):<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set phone number, if you want to test SMS\n#define SMS_TARGET  \"+XXXXXXXXXXXXXXXX\"<\/code><\/pre>\n\n\n\n<p>Set the network mode with the value you got from the previous example.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/*\n  2 Automatic\n  13 GSM only\n  38 LTE only\n  51 GSM and LTE only\n* * * *\/\nString res;\n<strong>\/\/ CHANGE NETWORK MODE, IF NEEDED\n<\/strong>res = modem.setNetworkMode(<strong>2<\/strong>);\nif (res != \"1\") {\n  DBG(\"setNetworkMode  false \");\n  return ;\n}\ndelay(200);<\/code><\/pre>\n\n\n\n<p>Change the preferred mode with the value you got from the previous example.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/*\n  1 CAT-M\n  2 NB-Iot\n  3 CAT-M and NB-IoT\n* * *\/\n<strong>\/\/ CHANGE PREFERRED MODE, IF NEEDED\n<\/strong>res = modem.setPreferredMode(<strong>1<\/strong>);\nif (res != \"1\") {\n  DBG(\"setPreferredMode  false \");\n  return ;\n}\ndelay(200);<\/code><\/pre>\n\n\n\n<p>After that, you can upload the code to your board. Don&#8217;t forget to select<strong> ESP32 Dev Module<\/strong> in <strong>Tools <\/strong>&gt; <strong>Board<\/strong>. You also need to <strong>remove the microSD card every time you want to upload a new sketch<\/strong>.<\/p>\n\n\n\n<p>After uploading, you can insert the microSD card. Open the Serial Monitor at a baud rate of 115200, and press the on-board RST button to restart it.<\/p>\n\n\n\n<p>The board may take some time to get GPS data for the first time. Your <strong>board needs to be placed outside to be able to get a satellite signal<\/strong>. I placed mine next to the window and it was able to accurately get the GPS position.<\/p>\n\n\n\n<p>You should get something similar.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Wait...\nInitializing modem...\nATE0\nAT+CFUN=0\nFailed to restart modem, attempting to continue without restarting\nInitializing modem...\nAT\nAT\nAT\nOK\nATE0\nATE0\nOK\nAT+CMEE=0\n\nOK\nAT+CLTS=1\n\nOK\nAT+CBATCHK=1\n\nOK\nAT+CPIN?\n\n+CPIN: READY\n\nOK\nAT+GMM\n\nSIMCOM_SIM7000G\n\nOK\nModem Name: SIMCOM SIM7000G\nATI\n\nSIM7000G R1529\n\nOK\nModem Info: SIM7000G R1529\nAT+SGPIO=0,4,1,0\n\nOK\nAT+CPIN?\n\n+CPIN: READY\n\nOK\nAT+CFUN=0 \n\n+CPIN: NOT READY\n\nOK\nAT+CNMP=2\n\nOK\nAT+CMNB=1\n\nOK\nAT+CFUN=1 \n\nOK\nAT+CGDCONT=1,\"IP\",\"net2.vodafone.pt\",\"0.0.0.0\",0,0,0,0\nAT+CGDCONT=13,\"IP\",\"net2.vodafone.pt\",\"0.0.0.0\",0,0,0,0\n\n\n\nWaiting for network...\nAT+CEREG?\n\nOK\nAT+CGREG?\n\n+CGREG: 0,2\n\nOK\nAT+CEREG?\n\n+CEREG: 0,0\n\nOK\nAT+CGREG?\n\n+CGREG: 0,2\n\nOK\nAT+CEREG?\n\n+CEREG: 0,0\n\nOK\nAT+CGREG?\n\n+CGREG: 0,2\n\nOK\nAT+CEREG?\n\n+CEREG: 0,0\n\nOK\nAT+CGREG?\n\n+CGREG: 0,2\n\nOK\nAT+CEREG?\n\n+CEREG: 0,0\n\nOK\nAT+CGREG?\n\n+CGREG: 0,2\n\nOK\nAT+CEREG?\n\n+CEREG: 0,0\n\nOK\nAT+CGREG?\n\n+CGREG: 0,2\n\nOK\nAT+CEREG?\n\nDST: 1\n\n*PSUTTZ: 22\/08\/07,13:45:17\",\"+04\",1\n\n+CEREG: 0,0\n\nOK\nAT+CGREG?\n\n+CGREG: 0,1\n\nOK\nAT+CEREG?\n\n+CEREG: 0,0\n\nOK\nAT+CGREG?\n\n+CGREG: 0,1\n\nOK\nNetwork connected\n\n---Starting GPRS TEST---\n\nConnecting to: net2.vodafone.pt\nAT+CIPSHUT\n\nSHUT OK\nAT+CGATT=0\n\nOK\nAT+SAPBR=3,1,\"Contype\",\"GPRS\"\n\nOK\nAT+SAPBR=3,1,\"APN\",\"net2.vodafone.pt\"\n\nOK\nAT+SAPBR=3,1,\"USER\",\"vodafone\"\n\nOK\nAT+SAPBR=3,1,\"PWD\",\"vodafone\"\n\nOK\nAT+CGDCONT=1,\"IP\",\"net2.vodafone.pt\"\n\nOK\nAT+CGATT=1\n\nOK\nAT+CGACT=1,1\n\nDST: 1\n\n*PSUTTZ: 22\/08\/07,13:45:19\",\"+04\",1\n\nOK\nAT+SAPBR=1,1\n\nOK\nAT+SAPBR=2,1\n\n+SAPBR: 1,1,\"10.196.118.208\"\n\nOK\nAT+CIPMUX=1\n\nOK\nAT+CIPQSEND=1\n\nOK\nAT+CIPRXGET=1\n\nOK\nAT+CSTT=\"net2.vodafone.pt\",\"vodafone\",\"vodafone\"\n\nOK\nAT+CIICR\n\nOK\nAT+CIFSR;E0\n\n10.196.118.208\n\nOK\nGPRS status: AT+CGATT?\n\n+CGATT: 1\n\nOK\nAT+CIFSR;E0\n\n10.196.118.208\n\nOK\nconnected\nAT+CCID\n\n8935101211825295132f\n\nOK\nCCID: 8935101211825295132f\nAT+GSN\n\n869951031125929\n\nOK\nIMEI: 869951031125929\nAT+COPS?\n\n+COPS: 0,0,\"vodafone P\",3\n\nOK\nOperator: vodafone P\nAT+CIFSR;E0\n\n10.196.118.208\n\nOK\nLocal IP: 3497444362\nAT+CSQ\n\n+CSQ: 22,0\n\nOK\nSignal quality: 22\n\n+CPSI: GSM,Online,268-01,0x000e,63308,15 EGSM 900,-73,0,38-38\n\nOK\n\n\n---End of GPRS TEST---\n\nAT+CIPSHUT\n\nSHUT OK\nAT+CGATT=0\n\n+SAPBR 1: DEACT\n\nOK\nAT+CGATT?\n\n+CGATT: 0\n\nOK\nGPRS disconnected\n\n---Starting GPS TEST---\n\nAT+SGPIO=0,4,1,1\n\nOK\nAT+CGNSPWR=1\n\nOK\nAT+CGNSINF\n\n+CGNSINF: 0,,,,,,,,,,,,,,,,,,,,\n\nOK\ngetGPS 26839\nAT+CGNSINF\n\n+CGNSINF: 1,0,,,,,,,0,,,,,,12,,,,50,,\n\nOK\ngetGPS 28844\nAT+CGNSINF\n\n+CGNSINF: 1,0,,,,,,,0,,,,,,12,,,,51,,\n\nOK\ngetGPS 30850\nAT+CGNSINF\n\n+CGNSINF: 1,0,,,,,,,0,,,,,,13,,,,51,,\n\nOK\ngetGPS 32856\nAT+CGNSINF\n\n+CGNSINF: 1,0,,,,,,,0,,,,,,12,,,,51,,\n\nOK\ngetGPS 34862\nAT+CGNSINF\n\n+CGNSINF: 1,0,,,,,,,0,,,,,,12,,,,51,,\n\nOK\ngetGPS 36868\nAT+CGNSINF\n\n+CGNSINF: 1,1,20220807134533.000,41.12XXXX,-8.530XXXX,116.200,0.00,0.0,1,,4.2,,,,13,4,,,51,,\n\nOK\nlat:41.12XXXX lon:-8.530XXXX\nAT+CGNSPWR=0\n\nOK\nAT+SGPIO=0,4,1,0\n\nOK\n\n---End of GPRS TEST---\n\nAT+CMGF=1\n\nOK\nAT+CSCS=\"GSM\"\n\nOK\nAT+CMGS=\"+351916XXXXXXXX\"\n\n&gt;Hello from 86995103XXXXXXXXX \n+CMGS: 228\n\nOK\nAT+CPOWD=1\n\nNORMAL POWER DOWN\nAT+CPOWD=1\nPoweroff.<\/code><\/pre>\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 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>Insert the SIM card pin, APN details, and SMS recipient:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ set GSM PIN, if any\n#define GSM_PIN \"\"\n\n\/\/ Your GPRS credentials, if any\nconst char apn&#091;]  = \"net2.vodafone.pt\";     \/\/SET TO YOUR APN\nconst char gprsUser&#091;] = \"vodafone\";\nconst char gprsPass&#091;] = \"vodafone\";\n\n\/\/ Set phone numbers, if you want to test SMS\n#define SMS_TARGET  \"+351------------\"<\/code><\/pre>\n\n\n\n<p>Include the <span class=\"rnthl rntliteral\">TinyGSM<\/span> and <span class=\"rnthl rntliteral\">SPI<\/span> libraries. You also need to include the <span class=\"rnthl rntliteral\">SD<\/span> library if you want to use the microSD card.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;TinyGsmClient.h&gt;\n#include &lt;SPI.h&gt;\n#include &lt;SD.h&gt;\n#include &lt;Ticker.h&gt;<\/code><\/pre>\n\n\n\n<p>Create a <span class=\"rnthl rntliteral\">TinyGsmClient<\/span> instance:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#ifdef DUMP_AT_COMMANDS  \/\/ if enabled it requires the streamDebugger lib\n  #include &lt;StreamDebugger.h&gt;\n  StreamDebugger debugger(SerialAT, Serial);\n  TinyGsm modem(debugger);\n#else\n  TinyGsm modem(SerialAT);\n#endif<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">SIM7000G pinout<\/h3>\n\n\n\n<p>The following lines set the module baud rate and pinout:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#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 SD_MISO     2\n#define SD_MOSI     15\n#define SD_SCLK     14\n#define SD_CS       13\n#define LED_PIN     12<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Power the modem<\/h3>\n\n\n\n<p>In the  <span class=\"rnthl rntliteral\">setup()<\/span>, you always need to include the following instructions to turn on the modem:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(PWR_PIN, OUTPUT);\ndigitalWrite(PWR_PIN, HIGH);\ndelay(300);\ndigitalWrite(PWR_PIN, LOW);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Initialize microSD Card<\/h3>\n\n\n\n<p>The following lines initialize the microSD card on the pins we defined earlier.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>SPI.begin(SD_SCLK, SD_MISO, SD_MOSI, SD_CS);\nif (!SD.begin(SD_CS)) {\n  Serial.println(\"SDCard MOUNT FAIL\");\n} else {\n  uint32_t cardSize = SD.cardSize() \/ (1024 * 1024);\n  String str = \"SDCard Size: \" + String(cardSize) + \"MB\";\n  Serial.println(str);\n}<\/code><\/pre>\n\n\n\n<p>To learn more about using the microSD card with the ESP32, you can read the following guide: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-microsd-card-arduino\/\">ESP32: Guide for MicroSD Card Module using Arduino IDE<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Start Serial Communication<\/h3>\n\n\n\n<p>Start a serial communication with the modem:<\/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<h3 class=\"wp-block-heading\">Restart and Initialize the Modem<\/h3>\n\n\n\n<p>Call the following lines to restart 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()\nSerial.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>Or the following lines to initialize:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ To skip it, call init() instead of restart()\nSerial.println(\"Initializing modem...\");\nif (!modem.init()) {\n  Serial.println(\"Failed to restart modem, attempting to continue without restarting\");\n}<\/code><\/pre>\n\n\n\n<p>Difference between <span class=\"rnthl rntliteral\">restart()<\/span> and <span class=\"rnthl rntliteral\">init()<\/span> according to documentation: &#8221; <span class=\"rnthl rntliteral\">restart()<\/span> generally takes longer than <span class=\"rnthl rntliteral\">init()<\/span> but ensures the module doesn&#8217;t have lingering connections&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Get Modem Name and Info<\/h3>\n\n\n\n<p>You can use the <span class=\"rnthl rntliteral\">getModemName()<\/span> and <span class=\"rnthl rntliteral\">getModemInfo()<\/span> to get information about the modem.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>String name = modem.getModemName();\ndelay(500);\nSerial.println(\"Modem Name: \" + name);\n\nString modemInfo = modem.getModemInfo();\ndelay(500);\nSerial.println(\"Modem Info: \" + modemInfo);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Connect GPRS<\/h3>\n\n\n\n<p>To connect GPRS using the APN details:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {\n  delay(10000);\n  return;\n}<\/code><\/pre>\n\n\n\n<p>To check if it is connected, you can use the  <span class=\"rnthl rntliteral\">isGprsConnected()<\/span> method:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (modem.isGprsConnected()) {\n  Serial.println(\"connected\");\n} else {\n  Serial.println(\"not connected\");\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Start GPS and Get Location<\/h3>\n\n\n\n<p>As mentioned previously, 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  DBG(\" SGPIO=0,4,1,1 false \");\n}<\/code><\/pre>\n\n\n\n<p>If you have the oldest version, you don&#8217;t need those lines of code.<\/p>\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>Get latitude and longitude using the <span class=\"rnthl rntliteral\">getGPS()<\/span> method.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float lat,  lon;\nwhile (1) {\n  if (modem.getGPS(&amp;lat, &amp;lon)) {\n    Serial.printf(\"lat:%f lon:%f\\n\", lat, lon);\n    break;\n  } else {\n    Serial.print(\"getGPS \");\n    Serial.println(millis());\n  }\n  delay(2000);\n}<\/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  DBG(\" SGPIO=0,4,1,0 false \");\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Sending SMS<\/h3>\n\n\n\n<p>To send an SMS, you can simply use the <span class=\"rnthl rntliteral\">sendSMS()<\/span> method and pass as arguments the recipient number and the message.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>res = modem.sendSMS(SMS_TARGET, String(\"Hello from \") + imei);\nDBG(\"SMS:\", res ? \"OK\" : \"fail\");<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Powering Down the Module<\/h3>\n\n\n\n<p>The LILYGO is supposed to work on a 18650 battery and solar panel, so we must cut power whenever it&#8217;s not needed. So, it&#8217;s useful to have a function to turn off the modem completely. You can use the <span class=\"rnthl rntliteral\">poweroff()<\/span> method or send the <span class=\"rnthl rntliteral\">+CPOWD=1<\/span> AT command.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>modem.sendAT(\"+CPOWD=1\");\nif (modem.waitResponse(10000L) != 1) {\n  DBG(\"+CPOWD=1\");\n}\n\/\/ The following command does the same as the previous lines\nmodem.poweroff();\nSerial.println(\"Poweroff.\");<\/code><\/pre>\n\n\n\n<p>And that&#8217;s it for the most relevant parts of code.<\/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. This tutorial can also be applied if you&#8217;re using a &#8220;regular&#8221; ESP32 connected to an external SIM7000G module. This module supports GPS, GPRS, LTE CAT-M1, and NB-IoT protocols, which can be very useful for IoT and Home Automation projects.<\/p>\n\n\n\n<p>You learned how to connect GPRS, how to send SMS messages and how to get GPS data. The idea is to include the snippets of code you need in your own projects.<\/p>\n\n\n\n<p>The LILYGO T-SIM7000G ESP32 board also comes with a microSD card slot that can be useful for datalogging projects or to save configuration settings. Furthermore, it comes with a battery holder and a battery charging circuit to use with solar panels. So, it&#8217;s suitable to use in remote locations. However, I haven&#8217;t experimented with the battery circuit yet.<\/p>\n\n\n\n<p>For more examples, you can explore the <a href=\"https:\/\/github.com\/vshymanskyy\/TinyGSM\" target=\"_blank\" rel=\"noreferrer noopener\">TinyGSM library repository<\/a> or the official <a href=\"https:\/\/github.com\/Xinyuan-LilyGO\/LilyGO-T-SIM7000G\" target=\"_blank\" rel=\"noreferrer noopener\">LILYGO T-SIM7000G Github page<\/a>.<\/p>\n\n\n\n<p>Do you have one of these boards? What do you think? Let us know in the comments 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","protected":false},"excerpt":{"rendered":"<p>Get started with the ESP32 and the SIM7000G LTE\/GPS\/GPRS module. Throughout this tutorial, we&#8217;ll use the LILYGO T-SIM7000G ESP32 board that combines the ESP32 chip, the SIM7000G module, microSD card &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Getting Started with LILYGO T-SIM7000G ESP32 (LTE, GPRS, and GPS)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/lilygo-t-sim7000g-esp32-lte-gprs-gps\/#more-114056\" aria-label=\"Read more about Getting Started with LILYGO T-SIM7000G ESP32 (LTE, GPRS, and GPS)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":114188,"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":[281,276,277,299,264],"tags":[],"class_list":["post-114056","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","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\/Getting-Started-LILYGO-T-SIM7000G-ESP32.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\/114056","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=114056"}],"version-history":[{"count":40,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/114056\/revisions"}],"predecessor-version":[{"id":148664,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/114056\/revisions\/148664"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/114188"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=114056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=114056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=114056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}