In this quick overview, you’ll find out how to obtain GPS information with the LILYGO T-SIM7000G ESP32 board using Arduino IDE. This tutorial is likewise compatible with a “routine” ESP32 linked to a SIM7000G component.
Introducing the LILYGO T-SIM7000G ESP32
The is an ESP32 development board with a SIM7000G chip. This includes LTE (4G), GPS, as well as GPRS to your board. This means that with this board you can send SMS, obtain place and time utilizing GPS, as well as connect it to the web making use of a SIM card data strategy. This board does not support telephone call.
Besides the SIM7000G module, the board additionally comes with some interesting attributes like a battery holder for a 18650 battery, a battery charging circuit where you can connect solar panels to reenergize the battery, and also a microSD card slot that can be helpful for information logging jobs or to save configuration setups.
For a more extensive introduction, we advise following the beginning guide:
Where to purchase LILYGO T-SIM7000G ESP32?
Check the adhering to link:
All stores in the previous web link should offer the most recent variation, but confirm the item web page, simply in instance the seller modifications something.
You can utilize the preceding web links or go straight to discover all the parts for your jobs at the ideal rate!
Libraries
The ESP32 communicates with the SIM7000G chip by sending out AT commands via serial interaction. You do not need a library, you can merely develop a serial communication with the module as well as begin sending AT commands. There’s a manual with all the SIM7000G AT commands:
However, it may be more sensible to make use of a collection. The collection knows which commands to send, and also exactly how to manage AT reactions, and also wraps that into the standard Arduino Client interface– that’s the collection we’ll make use of in this tutorial.
Installing the TinyGSM Library
Open your Arduino IDE and go to Sketch > > Include Library > > Manage Libraries. The Library Manager should open up. Search for TinyGSM. Select the TinyGSM collection by Volodymyr Shymanskyy.
You likewise require to mount the StreamDebugger collection. Go to Sketch > > Include Library > > Manage Libraries, look for StreamDebugger, as well as install it.
Preparing the LILYGO T-SIM7000G ESP32 Board
To obtain GPS information with your board, you don’t require to attach a SIM card. You only require to link the GPS antenna to the board.
LILYGO T-SIM7000G ESP32 Board—Get GPS Data
Copy the adhering to code to your Arduino IDE.
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/lilygo-t-sim7000g-esp32-gps-data/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#define TINY_GSM_MODEM_SIM7000
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb
#include <TinyGsmClient.h>
// LilyGO T-SIM7000G Pinout
#define UART_BAUD 115200
#define PIN_DTR 25
#define PIN_TX 27
#define PIN_RX 26
#define PWR_PIN 4
#define LED_PIN 12
// Set serial for debug console (to Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands
#define SerialAT Serial1
TinyGsm modem(SerialAT);
void setup(){
SerialMon.begin(115200);
SerialMon.println("Place your board outside to catch satelite signal");
// Set LED OFF
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
//Turn on the modem
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, HIGH);
delay(300);
digitalWrite(PWR_PIN, LOW);
delay(1000);
// Set module baud rate and UART pins
SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);
// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
if (!modem.restart()) {
Serial.println("Failed to restart modem, attempting to continue without restarting");
}
// Print modem info
String modemName = modem.getModemName();
delay(500);
SerialMon.println("Modem Name: " + modemName);
String modemInfo = modem.getModemInfo();
delay(500);
SerialMon.println("Modem Info: " + modemInfo);
}
void loop(){
// Set SIM7000G GPIO4 HIGH ,turn on GPS power
// CMD:AT+SGPIO=0,4,1,1
// Only in version 20200415 is there a function to control GPS power
modem.sendAT("+SGPIO=0,4,1,1");
if (modem.waitResponse(10000L) != 1) {
SerialMon.println(" SGPIO=0,4,1,1 false ");
}
modem.enableGPS();
delay(15000);
float lat = 0;
float lon = 0;
float speed = 0;
float alt = 0;
int vsat = 0;
int usat = 0;
float accuracy = 0;
int year = 0;
int month = 0;
int day = 0;
int hour = 0;
int min = 0;
int sec = 0;
for (int8_t i = 15; i; i--) {
SerialMon.println("Requesting current GPS/GNSS/GLONASS location");
if (modem.getGPS(&lat, &lon, &speed, &alt, &vsat, &usat, &accuracy,
&year, &month, &day, &hour, &min, &sec)) {
SerialMon.println("Latitude: " + String(lat, 8) + "/tLongitude: " + String(lon, 8));
SerialMon.println("Speed: " + String(speed) + "/tAltitude: " + String(alt));
SerialMon.println("Visible Satellites: " + String(vsat) + "/tUsed Satellites: " + String(usat));
SerialMon.println("Accuracy: " + String(accuracy));
SerialMon.println("Year: " + String(year) + "/tMonth: " + String(month) + "/tDay: " + String(day));
SerialMon.println("Hour: " + String(hour) + "/tMinute: " + String(min) + "/tSecond: " + String(sec));
break;
}
else {
SerialMon.println("Couldn't get GPS/GNSS/GLONASS location, retrying in 15s.");
delay(15000L);
}
}
SerialMon.println("Retrieving GPS/GNSS/GLONASS location again as a string");
String gps_raw = modem.getGPSraw();
SerialMon.println("GPS/GNSS Based Location String: " + gps_raw);
SerialMon.println("Disabling GPS");
modem.disableGPS();
// Set SIM7000G GPIO4 LOW ,turn off GPS power
// CMD:AT+SGPIO=0,4,1,0
// Only in version 20200415 is there a function to control GPS power
modem.sendAT("+SGPIO=0,4,1,0");
if (modem.waitResponse(10000L) != 1) {
SerialMon.println(" SGPIO=0,4,1,0 false ");
}
delay(200);
// Do nothing forevermore
while (true) {
modem.maintain();
}
}
How the Code Works
Let’s take a glimpse at the relevant parts of the code.
First, you need to specify the component you’re making use of. The library works with lots of various modules. To utilize the SIM7000G, include the following line:
#define TINY_GSM_MODEM_SIM7000
Include the TinyGSM library.
#include <TinyGsmClient.h>
The following lines established the board pins to regulate the modem:
// LilyGO T-SIM7000G Pinout
#define UART_BAUD 115200
#define PIN_DTR 25
#define PIN_TX 27
#define PIN_RX 26
#define PWR_PIN 4
#define LED_PIN 12
You require to develop 2 Serial instances. One for the Serial Monitor that we’ll call SerialMon, and another to communicate with the modem using AT commands, that we call SerialAT.
// Set serial for debug console (to Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands
#define SerialAT Serial1
Create a TinyGSM instance called modem on the SerialAT.
TinyGsm modem(SerialAT);
Initialize the Serial Monitor at a baud rate of 115200.
SerialMon.begin(115200);
Turn on the modem by setting the power pin to HIGH and also LOW at a specific period.
//Turn on the modem
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, HIGH);
delay(300);
digitalWrite(PWR_PIN, LOW);
Initialize a Serial communication with the modem on the RX and TX pins we specified previously.
SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);
Init the modem or restart:
// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
if (!modem.restart()) {
Serial.println("Failed to restart modem, attempting to continue without restarting");
}
Get some modem details making use of the getModemName() as well as getModemInfo() methods. These lines are optional as well as you do not actually require them to get GPS data.
// Print modem info
String modemName = modem.getModemName();
delay(500);
SerialMon.println("Modem Name: " + modemName);
String modemInfo = modem.getModemInfo();
delay(500);
SerialMon.println("Modem Info: " + modemInfo);
There are 2 versions of the LILYGO SIM7000G ESP32 board. The most recent features active GPS antenna power control– when the module GPIO 4 is not turned on the antenna consumes only the static current of the LDO. This implies we need to transform GPIO 4 on before getting GPS data to power the antenna. That’s what the following lines do:
// Set SIM7000G GPIO4 HIGH ,turn on GPS power
// CMD:AT+SGPIO=0,4,1,1
// Only in version 20200415 is there a function to control GPS power
modem.sendAT("+SGPIO=0,4,1,1");
if (modem.waitResponse(10000L) != 1) {
SerialMon.println(" SGPIO=0,4,1,1 false ");
}
You can begin GPS utilizing the enableGPS() approach.
modem.enableGPS();
Then, we develop variables where we’ll save the GPS information. We’ll get latitude, longitude, speed, elevation, noticeable satellites, utilized satellites, precision, as well as date and also time.
delay(15000);
float lat = 0;
float lon = 0;
float speed = 0;
float alt = 0;
int vsat = 0;
int usat = 0;
float accuracy = 0;
int year = 0;
int month = 0;
int day = 0;
int hour = 0;
int min = 0;
int sec = 0;
The adhering to line obtains GPS information making use of the getGPS() method and also conserves the values on the best variables.
if (modem.getGPS(&lat, &lon, &speed, &alt, &vsat, &usat, &accuracy,
&year, &month, &day, &hour, &min, &sec))
Then, we just print the values on the Serial Monitor. Since you have the pertinent info conserved on variables, it’s very easy to change this task for your very own demands. A GPS tracker, GPS data logger, and so on.
SerialMon.println("Latitude: " + String(lat, 8) + "/tLongitude: " + String(lon, 8));
SerialMon.println("Speed: " + String(speed) + "/tAltitude: " + String(alt));
SerialMon.println("Visible Satellites: " + String(vsat) + "/tUsed Satellites: " + String(usat));
SerialMon.println("Accuracy: " + String(accuracy));
SerialMon.println("Year: " + String(year) + "/tMonth: " + String(month) + "/tDay: " + String(day));
SerialMon.println("Hour: " + String(hour) + "/tMinute: " + String(min) + "/tSecond: " + String(sec));
You can also obtain all raw information returned by the GPS using the getGPRSraw() approach.
String gps_raw = modem.getGPSraw();
SerialMon.println("GPS/GNSS Based Location String: " + gps_raw);
When you’re done making use of GPS, you can turn it off utilizing the disableGPS() method:
modem.disableGPS();
And finally, turn off the power to the antenna by turning GPIO 4 off:
// Set SIM7000G GPIO4 LOW ,turn off GPS power
// CMD:AT+SGPIO=0,4,1,0
// Only in version 20200415 is there a function to control GPS power
modem.sendAT("+SGPIO=0,4,1,0");
if (modem.waitResponse(10000L) != 1) {
SerialMon.println(" SGPIO=0,4,1,0 false ");
}
Demonstration
In your Arduino IDE, most likely to Tools > > Boards as well as choose the ESP32 Dev Module. Select the COM port in Tools > > Port.
Then, submit the code to your board.
Open the Serial Monitor at a baud price of 115200 as well as push the on-board RST button to restart the board. Put your board outside or beside a home window or door to ensure that it can catch satellite signals.
It may take some time till it has the ability to get some GPS data, as you can see in the screenshot of my Serial Monitor.
As you can see, it gets latitude, longitude, speed, elevation, visible satellites, variety of made use of satellites to obtain position, accuracy, as well as UTC day as well as time. The longitude as well as latitude I got were very accurate. In my situation, it was working quite well to get the location. Since the Serial Monitor window is too small), pendtag
It also outputs the complete GNSS navigating details parsed from NMEA sentences (that you can’t see above. NMEA means National Marine Electronics Association, as well as on the planet of GPS, it is a basic information format supported by GPS producers. The outcome is as complies with. The commas separate various values.
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,,
Here’s what each worth suggests, in order:
- GNSS run status
- Fix status
- UTC date and time
- Latitude
- Longitude
- MSL altitude
- Speed over ground
- Course over ground
- Fix mode
- Reserver1
- HDOP
- PDOP
- VDOP
- Reserved2
- GNSS Satellites in View
- GPS Satellites used
- GLONASS Satellites used
- Reserver3
- C/N0 max
- HPA
- VPA
You can find out more regarding these criteria and feasible values by examining the AT+CGNSINF AT command on the SIM7000G AT commands handbook.
Wrapping Up
In this tutorial, you learned exactly how to make use of the LILYGO T-SIM7000G ESP32 board to get GPS information. We showed you an easy instance that publishes the GPS information in the Serial Monitor. The concept is to customize the instance and also apply it to your very own projects. It needs to also be compatible with a “normal” ESP32 board connected to an apart SIM7000G component.
The ESP32 T-SIM7000G board features will certainly permit you to build a vast selection of tasks taking right into account that it can connect to the web in remote locations using a SIM card information strategy and send SMS. The reality that it can utilize a battery as well as solar panels for charging is also wonderful, and the microSD card can also be really useful for datalogging or to conserve arrangement settings.
We hope you located this tutorial useful. Have you created any kind of projects with this board? Allow us know in the remarks area below.
You might additionally like the complying with tutorials (that with small modifications can be made use of with the SIM7000G board):
Learn more concerning the ESP32 with our resources:
Thanks for reading.