ESP32 TFT with LVGL: Display GPS Location, Date, and Time

In this guide, you’ll learn how to turn your ESP32 and a TFT display into a GPS reader that displays the current location, altitude, speed, date, and time using LVGL (Light Versatile Graphics Library). We’ll use the NEO-6M GPS Module to get the GPS data and the ESP32 chip will be programmed using Arduino IDE.

ESP32 TFT Display with LVGL Display GPS Location Date and Time Arduino IDE

Are you using a CYD board? Read this guide: ESP32 CYD with LVGL: Display GPS Location, Date, and Time

Project Overview

We’ll display the current GPS data (latitude and longitude), altitude, speed, time and date on a 2.8-inch ILI9341 TFT LCD Touchscreen (240×320). We’ll be using the NEO-6M GPS Module (read our NEO-6M getting started guide).

ESP32 TFT LVGL Display GPS Location Date Time Demonstration Screen

Prerequisites

Before proceeding, make sure you follow the next prerequisites. You must follow all steps, otherwise, your project will not work.

1) Parts Required

For this project, you need the following parts

ESP32 TFT LVGL Display GPS Location Date Time Parts Required

2) Install ESP32 Boards in Arduino IDE

Arduino IDE 2 Logo

We’ll program the ESP32 using Arduino IDE. Make sure you have the ESP32 boards installed. Follow the next tutorial:

3) Get familiar with the ILI9341 TFT LCD Touchscreen Display

The display we’re using in this guide is the 2.8. inch TFT LCD that also comes with a touchscreen. The display communicates via SPI communication protocol and uses the ILI9341 driver. The touchscreen also uses the SPI communication protocol.

The TFT LCD touchscreen also comes with an SD card interface if you need to load files for your specific project. This display is also available with different screen sizes, but we’ll use the one with 240 x 320 pixels).

ILI9341 TFT LCD Touchscreen Display

If this is your first time using this display, make sure to follow our getting started guide:

4) Wire the Display to the ESP32

Wire the TFT LCD and touchscreen pins to the ESP32 GPIOs according to the next table (you must use these exact pins, otherwise the project will not work).

Wiring TFT LCD Touchscreen display to ESP32
TFT LCD TouchscreenESP32
T_IRQGPIO 36
T_OUTGPIO 39
T_DINGPIO 32
T_CSGPIO 33
T_CLKGPIO 25
SDO(MISO)GPIO 12
LEDGPIO 21
SCKGPIO 14
SDI(MOSI)GPIO 13
D/CGPIO 2
RESETEN/RESET
CSGPIO 15
GNDGND
VCC5V (or 3.3V)*

* In the VCC pin, you can either use 5V or 3.3V depending if your J1 connection is open or closed (by default it’s usually open as you can see in the figure below).

VCC = 5V | J1=OPEN
VCC = 3.3V | J1=CLOSE
TFT LCD Touchscreen display J1 connection

5) Wiring the NEO-6M GPS Module

The NEO-6M GPS module is a GPS receiver compatible with most microcontroller boards. It can get data about location, speed, altitude, and time. We’ll connect the NEO-6M GPS Module to the ESP32 board.

You can use the following table as a reference.

NEO-6M GPS ModuleESP32
VCC3V3
RXGPIO 27
TXGPIO 22
GNDGND

You also need to connect an external antenna to the GPS module. The figure below shows two different options of antennas for GPS modules.

antennas for GPS modules

6) Install TFT and LVGL Libraries

LVGL (Light and Versatile Graphics Library) is a free and open-source graphics library that provides a wide range of easy-to-use graphical elements for your microcontroller projects that require a graphical user interface (GUI).

LVGL new logo

Follow the next tutorial to install and configure the required libraries to use LVGL with the 2.8 inch ILI9341 240×320 TFT LCD Touchscreen using Arduino IDE.

7) Install TinyGPSPlus Library

For this project, you need to install the TinyGPSPlus library to prepare the GPS data.

In the Arduino IDE, go to Sketch > Include Library > Manage Libraries. Search for TinyGPSPlus and install the library by Mikal Hart. We’re using version 1.0.3 and we recommend using the same version.

Installing TinyGPSPlus Library Arduino IDE

ESP32 TFT GPS Data – gps_image.h file

To load custom images using LVGL, you need to create an extra file called gps_image.h that must be placed inside the sketch folder. We already prepared that file for you. To load the custom image for this GPS reader, you need to download the next file.

Important: the gps_image.h file should be placed next to the .ino file in the sketch folder of your project.

LVGL Load Image Arduino Code example folder GPS image file

Your Arduino IDE should have two tabs:

Arduino IDE tabs LVGL Load Image Arduino Code example folder GPS image file

If you want to learn more about loading images using LVGL, we recommend reading our Guide ESP32 with TFT: Display Image using LVGL – 2.8 inch ILI9341 240×320 (Arduino)

ESP32 TFT GPS Data – Arduino Code

The following code will create some text labels with the GPS data, altitude, speed, time, and date. It will also load an image to illustrate the project application.

/*  Rui Santos & Sara Santos - Random Nerd Tutorials - https://RandomNerdTutorials.com/esp32-cyd-lvgl-gps-location/  |  https://RandomNerdTutorials.com/esp32-tft-lvgl-gps-data/
    THIS EXAMPLE WAS TESTED WITH THE FOLLOWING HARDWARE:
    1) ESP32-2432S028R 2.8 inch 240×320 also known as the Cheap Yellow Display (CYD): https://makeradvisor.com/tools/cyd-cheap-yellow-display-esp32-2432s028r/
      SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/cyd-lvgl/
    2) REGULAR ESP32 Dev Board + 2.8 inch 240x320 TFT Display: https://makeradvisor.com/tools/2-8-inch-ili9341-tft-240x320/ and https://makeradvisor.com/tools/esp32-dev-board-wi-fi-bluetooth/
      SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/esp32-tft-lvgl/
    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.
*/

/*  Install the "lvgl" library version 9.X by kisvegabor to interface with the TFT Display - https://lvgl.io/
    *** IMPORTANT: lv_conf.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials ***
    *** YOU MUST USE THE lv_conf.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS ***
    FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/   */
#include <lvgl.h>

/*  Install the "TFT_eSPI" library by Bodmer to interface with the TFT Display - https://github.com/Bodmer/TFT_eSPI
    *** IMPORTANT: User_Setup.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials ***
    *** YOU MUST USE THE User_Setup.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS ***
    FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/   */
#include <TFT_eSPI.h>

#include <TinyGPS++.h>

#include "gps_image.h"

// Define the RX and TX pins for Serial 2
#define RXD2 22
#define TXD2 27

#define GPS_BAUD 9600

// The TinyGPS++ object
TinyGPSPlus gps;

// Create an instance of the HardwareSerial class for Serial 2
HardwareSerial gpsSerial(2);

#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320

#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];

String current_date;
String utc_time;
String latitude;
String longitude;
String altitude;
String speed;
String hdop;
String satellites;

// If logging is enabled, it will inform the user about what is happening in the library
void log_print(lv_log_level_t level, const char * buf) {
  LV_UNUSED(level);
  Serial.println(buf);
  Serial.flush();
}

String format_time(int time) {
  return (time < 10) ? "0" + String(time) : String(time);
}

static lv_obj_t * text_label_date;
static lv_obj_t * text_label_latitude;
static lv_obj_t * text_label_longitude;
static lv_obj_t * text_label_altitude;
static lv_obj_t * text_label_speed;
static lv_obj_t * text_label_utc_time;
static lv_obj_t * text_label_hdop_satellites;
static lv_obj_t * text_label_gps_data;

static void timer_cb(lv_timer_t * timer){
  LV_UNUSED(timer);
  lv_label_set_text(text_label_date, current_date.c_str());
  lv_label_set_text(text_label_hdop_satellites, String("HDOP " + hdop + "  SAT. " + satellites).c_str());
  lv_label_set_text(text_label_gps_data, String("LAT   " + latitude + "\nLON   " + longitude + "\nALT   " 
                                                + altitude + "m" + "\nSPEED   " + speed + "km/h").c_str());
  lv_label_set_text(text_label_utc_time, String("UTC TIME - " + utc_time).c_str());
}

void lv_create_main_gui(void) {
  LV_IMAGE_DECLARE(image_gpsmap);

  lv_obj_t * img_gpsmap = lv_image_create(lv_screen_active());
  lv_obj_align(img_gpsmap, LV_ALIGN_LEFT_MID, 10, -20);
  lv_image_set_src(img_gpsmap, &image_gpsmap);

  text_label_hdop_satellites = lv_label_create(lv_screen_active());
  lv_label_set_text(text_label_hdop_satellites, String("HDOP " + hdop + "  SAT. " + satellites).c_str());
  lv_obj_align(text_label_hdop_satellites, LV_ALIGN_BOTTOM_LEFT, 30, -50);
  lv_obj_set_style_text_font((lv_obj_t*) text_label_hdop_satellites, &lv_font_montserrat_12, 0);
  lv_obj_set_style_text_color((lv_obj_t*) text_label_hdop_satellites, lv_palette_main(LV_PALETTE_GREY), 0);

  text_label_date = lv_label_create(lv_screen_active());
  lv_label_set_text(text_label_date, current_date.c_str());
  lv_obj_align(text_label_date, LV_ALIGN_CENTER, 60, -80);
  lv_obj_set_style_text_font((lv_obj_t*) text_label_date, &lv_font_montserrat_26, 0);
  lv_obj_set_style_text_color((lv_obj_t*) text_label_date, lv_palette_main(LV_PALETTE_TEAL), 0);

  lv_obj_t * text_label_location = lv_label_create(lv_screen_active());
  lv_label_set_text(text_label_location, "LOCATION");
  lv_obj_align(text_label_location, LV_ALIGN_CENTER, 50, -40);
  lv_obj_set_style_text_font((lv_obj_t*) text_label_location, &lv_font_montserrat_20, 0);
  
  text_label_gps_data = lv_label_create(lv_screen_active());
  lv_label_set_text(text_label_gps_data, String("LAT   " + latitude + "\nLON   " + longitude + "\nALT   " 
                                                 + altitude + "m" + "\nSPEED   " + speed + "km/h").c_str());
  lv_obj_align(text_label_gps_data, LV_ALIGN_CENTER, 60, 20);
  lv_obj_set_style_text_font((lv_obj_t*) text_label_gps_data, &lv_font_montserrat_14, 0);

  text_label_utc_time = lv_label_create(lv_screen_active());
  lv_label_set_text(text_label_utc_time, String("UTC TIME - " + utc_time).c_str());
  lv_obj_align(text_label_utc_time, LV_ALIGN_BOTTOM_MID, 0, -10);
  lv_obj_set_style_text_font((lv_obj_t*) text_label_utc_time, &lv_font_montserrat_20, 0);
  lv_obj_set_style_text_color((lv_obj_t*) text_label_utc_time, lv_palette_main(LV_PALETTE_TEAL), 0);
 
  lv_timer_t * timer = lv_timer_create(timer_cb, 1, NULL);
  lv_timer_ready(timer);
}

void setup() {
  String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
  Serial.begin(115200);
  Serial.println(LVGL_Arduino);

  // Start Serial 2 with the defined RX and TX pins and a baud rate of 9600
  gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RXD2, TXD2);
  Serial.println("Serial 2 started at 9600 baud rate");

  // Start LVGL
  lv_init();
  // Register print function for debugging
  lv_log_register_print_cb(log_print);

  // Create a display object
  lv_display_t * disp;
  // Initialize the TFT display using the TFT_eSPI library
  disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
  lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
  
  // Function to draw the GUI
  lv_create_main_gui();
}

void loop() {
  lv_task_handler();  // let the GUI do its work
  lv_tick_inc(5);     // tell LVGL how much time has passed
  delay(5);           // let this time pass
  
  // This sketch displays information every time a new sentence is correctly encoded.
  unsigned long start = millis();

  while (millis() - start < 1000) {
    while (gpsSerial.available() > 0) {
      gps.encode(gpsSerial.read());
    }
    if (gps.location.isUpdated()) {
      Serial.print("LAT: ");
      latitude = String(gps.location.lat(), 6);
      Serial.println(latitude);
      Serial.print("LONG: "); 
      longitude = String(gps.location.lng(), 6);
      Serial.println(longitude);
      Serial.print("SPEED (km/h) = "); 
      speed = String(gps.speed.kmph(), 2);
      Serial.println(speed);
      Serial.print("ALT (min)= "); 
      altitude = String(gps.altitude.meters(), 2);
      Serial.println(altitude);
      Serial.print("HDOP = "); 
      hdop = String(gps.hdop.value() / 100.0, 2);
      Serial.println(hdop);
      Serial.print("Satellites = "); 
      satellites = String(gps.satellites.value());
      Serial.println(satellites);
      Serial.print("Time in UTC: ");
      Serial.println(String(gps.date.year()) + "-" + String(gps.date.month()) + "-" + String(gps.date.day()) + "," + String(gps.time.hour()) + ":" + String(gps.time.minute()) + ":" + String(gps.time.second()));
      current_date = String(gps.date.year()) + "-" + String(gps.date.month()) + "-" + String(gps.date.day());
      Serial.println(current_date);
      utc_time = String(format_time(gps.time.hour())) + ":" + String(format_time(gps.time.minute())) + ":" + String(format_time(gps.time.second()));
      Serial.println(utc_time);
      Serial.println("");
    }
  }
}

View raw code

How Does the Code Work?

Let’s take a look at how to get GPS location and update the screen with the current values. Alternatively, you can skip to the Demonstration section.

Including Libraries and Images

You need to include the lvgl.h and the TFT_eSPI.h libraries to draw the GUI on the screen.

#include <lvgl.h>
#include <TFT_eSPI.h>

You need to include the TinyGPS++.h library to handle the GPS data.

#include <TinyGPS++.h>

Include the gps_image.h file that contains all the data to draw the map image.

#include "gps_image.h"

GPS Serial

This sketch uses GPIO 22 and GPIO 27 as RX and TX serial pins to establish serial communication with the GPS module.

// Define the RX and TX pins for Serial 2
#define RXD2   22
#define TXD2    27

Also, if your module uses a different default baud rate than 9600 bps, you should modify the code on the following line:

#define GPS_BAUD 9600

Then, we create an instance of the HardwareSerial to use UART 2 called gpsSerial.

// Create an instance of the HardwareSerial class for Serial 2
HardwareSerial gpsSerial(2);

Declaring Other Variables

Create some auxiliary variables to hold the GPS data and other values.

String current_date;
String utc_time;
String latitude;
String longitude;
String altitude;
String speed;
String hdop;
String satellites;

Global LVGL Objects

We create some global LVGL objects, so that we can access them inside all functions later on.

static lv_obj_t * text_label_date;
static lv_obj_t * text_label_latitude;
static lv_obj_t * text_label_longitude;
static lv_obj_t * text_label_altitude;
static lv_obj_t * text_label_speed;
static lv_obj_t * text_label_utc_time;
static lv_obj_t * text_label_hdop_satellites;
static lv_obj_t * text_label_gps_data;

setup()

In the setup(), include the following lines for debugging. These will print the version of LVGL that you’re using. You must be using version 9.

String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
Serial.begin(115200);
Serial.println(LVGL_Arduino);

Start GPS Serial

To connect the ESP32 board to the GPS module via serial, we use the following code.

gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RXD2, TXD2);
Serial.println("Serial 2 started at 9600 baud rate");

Initialize the LVGL Library

Initialize the LVGL Library by calling the lv_init() function in the setup().

// Start LVGL
lv_init();

Register Debugging Function

Register your log_print() function declared previously as a function associated with debugging LVGL.

// Register print function for debugging
lv_log_register_print_cb(log_print);

Create a Display Object

To write to the display, you must create a display object first. You need to do this in all your LVGL sketches. The following lines will create an LVGL display object called disp with the screen width, screen height, and drawing buffer defined earlier.

// Create a display object
lv_display_t * disp;
// Initialize the TFT display using the TFT_eSPI library
disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);

Drawing the GUI

The LVGL library works asynchronously. You must call the function to draw on the display in the setup(). Then, everything works with events and callbacks. The code will always be listening for events in the background. When something happens, it will run the callback function associated with the event. You don’t need to check for any events in the loop().

Throughout most of our examples, the function that will draw to the screen will be called lv_create_main_gui(). Then, inside that function, we’ll add the instructions to build the interface.

// Function to draw the GUI
lv_create_main_gui();

Preparing the GUI

Before drawing the main GUI, we start by declaring an image that will be displayed in the TFT screen.

void lv_create_main_gui(void) {
  LV_IMAGE_DECLARE(image_gpsmap);
(...)

Load the GPS image

We create an image and set it to the left side of the display.

lv_obj_t * img_gpsmap = lv_image_create(lv_screen_active());
lv_obj_align(img_gpsmap, LV_ALIGN_LEFT_MID, 10, -20);
lv_image_set_src(img_gpsmap, &image_gpsmap);

Text Labels

To create a text label, we can call the LVGL function lv_label_create() and pass as argument where we want to display the text. We want to add it to the current screen (lv_screen_active()). The following line is creating a text label to display the HDOP and the number of satellites.

text_label_hdop_satellites = lv_label_create(lv_screen_active());

After creating the text label, we can set its text by using the lv_label_set_text() function that accepts as arguments the text label we’re referring to and the text we want to add to that label. In our case, we’re setting this label to the current HDOP and visible satellites.

lv_label_set_text(text_label_hdop_satellites, String("HDOP " + hdop + "  SAT. " + satellites).c_str());

The following lines align the text label. You can use the lv_obj_align() function. Pass as arguments, the LVGL object, the alignment and x and y offsets in pixels.

lv_obj_align(text_label_hdop_satellites, LV_ALIGN_BOTTOM_LEFT, 30, -50);

Then, we can set the font type and size using the lv_style_set_text_font() function. We pass as argument the object we’re referring to and the font type.

lv_obj_set_style_text_font((lv_obj_t*) text_label_hdop_satellites, &lv_font_montserrat_12, 0);

For the text_label_date we’re also setting a custom text grey color:

lv_obj_set_style_text_color((lv_obj_t*) text_label_hdop_satellites, lv_palette_main(LV_PALETTE_GREY), 0);

A similar procedure is applied to all other labels (date, location, GPS data, and UTC time), but we put them on different places and set different font sizes and colors

text_label_date = lv_label_create(lv_screen_active());
lv_label_set_text(text_label_date, current_date.c_str());
lv_obj_align(text_label_date, LV_ALIGN_CENTER, 60, -80);
lv_obj_set_style_text_font((lv_obj_t*) text_label_date, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_color((lv_obj_t*) text_label_date, lv_palette_main(LV_PALETTE_TEAL), 0);

lv_obj_t * text_label_location = lv_label_create(lv_screen_active());
lv_label_set_text(text_label_location, "LOCATION");
lv_obj_align(text_label_location, LV_ALIGN_CENTER, 50, -40);
lv_obj_set_style_text_font((lv_obj_t*) text_label_location, &lv_font_montserrat_20, 0);
  
text_label_gps_data = lv_label_create(lv_screen_active());
lv_label_set_text(text_label_gps_data, String("LAT   " + latitude + "\nLON   " + longitude + "\nALT   " + altitude + "m" + "\nSPEED   " + speed + "km/h").c_str());
lv_obj_align(text_label_gps_data, LV_ALIGN_CENTER, 60, 20);
lv_obj_set_style_text_font((lv_obj_t*) text_label_gps_data, &lv_font_montserrat_14, 0);

text_label_utc_time = lv_label_create(lv_screen_active());
lv_label_set_text(text_label_utc_time, String("UTC TIME - " + utc_time).c_str());
lv_obj_align(text_label_utc_time, LV_ALIGN_BOTTOM_MID, 0, -10);
lv_obj_set_style_text_font((lv_obj_t*) text_label_utc_time, &lv_font_montserrat_20, 0);
lv_obj_set_style_text_color((lv_obj_t*) text_label_utc_time, lv_palette_main(LV_PALETTE_TEAL), 0);

Timer

To update the data on the screen, we can create an LVGL timer that will run a specific function periodically. In this case, we’ll update it every second. Create an LVGL timer called timer and assign the timer_cb callback function.

lv_timer_t * timer = lv_timer_create(timer_cb, 1, NULL);
lv_timer_ready(timer);

Timer Callback Function

The timer_cb function runs every second. Each time the callback function runs, we get the latest GPS data from the NEO-6M module and update the GUI.

static void timer_cb(lv_timer_t * timer){
  LV_UNUSED(timer);
  
(...)

Finally, we set all the text labels to the current data returned from the GPS module:

lv_label_set_text(text_label_date, current_date.c_str());
lv_label_set_text(text_label_hdop_satellites, String("HDOP " + hdop + "  SAT. " + satellites).c_str());
lv_label_set_text(text_label_gps_data, String("LAT   " + latitude + "\nLON   " + longitude + "\nALT   "  + altitude + "m" + "\nSPEED   " + speed + "km/h").c_str());
lv_label_set_text(text_label_utc_time, String("UTC TIME - " + utc_time).c_str());

loop()

In the loop(), you can add any other tasks that you need your ESP32 to do like in any regular Arduino sketch. In our case, we’ll be requesting the latest GPS data from the NEO-6M module every second and update the auxiliary variables.

void loop() {
  lv_task_handler();   // let the GUI do its work
  lv_tick_inc(5);         // tell LVGL how much time has passed
  delay(5);                 // let this time pass
(...)

The next code listens to the GPS serial port, and when data is received from the module, it is printed in the serial monitor and stored in the auxiliary variables.

// This sketch displays information every time a new sentence is correctly encoded.
unsigned long start = millis();

while (millis() - start < 1000) {
  while (gpsSerial.available() > 0) {
    gps.encode(gpsSerial.read());
  }
  if (gps.location.isUpdated()) {
    Serial.print("LAT: ");
    latitude = String(gps.location.lat(), 6);
    Serial.println(latitude);
    Serial.print("LONG: "); 
    longitude = String(gps.location.lng(), 6);
    Serial.println(longitude);
    Serial.print("SPEED (km/h) = "); 
    speed = String(gps.speed.kmph(), 2);
    Serial.println(speed);
    Serial.print("ALT (min)= "); 
    altitude = String(gps.altitude.meters(), 2);
    Serial.println(altitude);
    Serial.print("HDOP = "); 
    hdop = String(gps.hdop.value() / 100.0, 2);
    Serial.println(hdop);
    Serial.print("Satellites = "); 
    satellites = String(gps.satellites.value());
    Serial.println(satellites);
    Serial.print("Time in UTC: ");
    Serial.println(String(gps.date.year()) + "-" + String(gps.date.month()) + "-" + String(gps.date.day()) + "," + String(gps.time.hour()) + ":" + String(gps.time.minute()) + ":" + String(gps.time.second()));
    current_date = String(gps.date.year()) + "-" + String(gps.date.month()) + "-" + String(gps.date.day());
    Serial.println(current_date);
    utc_time = String(format_time(gps.time.hour())) + ":" + String(format_time(gps.time.minute())) + ":" + String(format_time(gps.time.second()));
    Serial.println(utc_time);
    Serial.println("");
  }
}

Demonstration

Upload the code to your board. Go to Tools > Board and select ESP32 > ESP32 Dev Module. Then, select the right COM port in Tools > Port.

Finally, click the upload button.

Arduino IDE 2 Upload Button

Open the Serial Monitor at a baud rate of 115200. Make sure your GPS module is placed outside or next to a window to get data from satellites. It may take some time. When the GPS module’s blue LED starts blinking, it means it’s ready.

You’ll get GPS data on the Serial Monitor about your current location, speed, altitude, number of visible satellites HDOP, date, and time.

ESP32 Display GPS Data Arduino IDE Serial Monitor Demonstration

You might need to wait a couple of minutes for the GPS module to establish a connection with enough satellites to get the GPS data. The info will be displayed on the screen as shown in the picture below.

ESP32 TFT LVGL Display GPS Location Date Time Demonstration

Wrapping Up

In this project, you’ve learned how to build a simple GPS reader with a TFT LCD Touchscreen with the ESP32 using the LVGL library. It displays the current location, altitude, speed, date, and time.

We hope you found this tutorial useful. We’re preparing more guides about this board, so stay tuned. If you would like to learn more about creating graphical user interfaces using the LVGL library with the ESP32, check out our latest eBook:

Other guides you might like reading:

To learn more about the ESP32, make sure to take a look at our resources:



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.