pdf-icon

Arduino Guide

Module GPS v2.0 Arduino Tutorial

1. Preparation

TinyGPSPlus Library Installation: Since the version of TinyGPSPlus in the Arduino library manager is outdated and not fully compatible, you need to visit the TinyGPSPlus - M5Stack GitHub and manually download it. Then, install it by placing it in the Arduino library folder.
Library Management Path:
Windows: C:\Users\{username}\Documents\Arduino
macOS: /Users/{username}/Documents/Arduino
Linux: /home/{username}/Arduino

2. Example Program

  • 1.Modify the actual IO pins used in the program based on the devices you have connected. In this tutorial, the main controller used is the CoreS3, and after stacking the Module GPS v2.0, the corresponding MBus bus IO pins are G18(RX) and G17(TX). The Module GPS v2.0 also supports switching pin connections via the DIP switch at the bottom, which can be adjusted according to actual needs.

  • 2.Refer to the UnitGPSExample example program from TinyGPSPlus , and modify the corresponding UART initialization pins. The example program uses M5Unified and M5GFX to add basic coordinate display functionality.
/*
 *SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 *
 *SPDX-License-Identifier: MIT
 */

#include "M5Unified.h"
#include "M5GFX.h"
#include "MultipleSatellite.h"

static const int RXPin = 18, TXPin = 17;
static const uint32_t GPSBaud = 115200;
MultipleSatellite gps(Serial1, GPSBaud, SERIAL_8N1, RXPin, TXPin);

void displayInfo();

void setup()
{
    M5.begin();
    Serial.begin(115200);
    gps.begin();
    gps.setSystemBootMode(BOOT_FACTORY_START);
    Serial.println(F("DeviceExample.ino"));
    Serial.println(F("A simple demonstration of TinyGPSPlus with an attached GPS module"));
    Serial.print(F("Testing TinyGPSPlus library v. "));
    Serial.println(TinyGPSPlus::libraryVersion());
    Serial.println(F("by Mikal Hart"));
    Serial.println();
    String version = gps.getGNSSVersion();
    Serial.printf("GNSS SW=%s\r\n", version.c_str());
    delay(1000);
    // Set satellite mode
    gps.setSatelliteMode(SATELLITE_MODE_GPS);
    M5.Display.setFont(&fonts::FreeMonoBold12pt7b);
}
void loop()
{
    // Update data
    gps.updateGPS();
    displayInfo();
    delay(10);
}

void displayInfo()
{
    Serial.print(F("Location: "));
    Serial.printf("satellites:%d\n", gps.satellites.value());
    if (gps.location.isUpdated()) {
        Serial.print(gps.location.lat(), 6);
        Serial.print(F(","));
        Serial.print(gps.location.lng(), 6);
        Serial.print(F("\n"));

        M5.Display.fillRect(0, 0, 320, 60, BLACK);
        M5.Display.setCursor(0, 0);
        M5.Display.printf("Location: \nLat: %f\nlng: %f\n", gps.location.lat(), gps.location.lng());

    } else {
        M5.Display.fillRect(0, 0, 320, 60, BLACK);
        M5.Display.setCursor(0, 0);
        M5.Display.print("Location: \n");
        M5.Display.print("Lat: ---------\n");
        M5.Display.print("lng: ---------\n");
        Serial.print(F("INVALID\n"));
    }

    Serial.print(F("  Date/Time: "));
    if (gps.date.isUpdated()) {
        Serial.print(gps.date.month());
        Serial.print(F("/"));
        Serial.print(gps.date.day());
        Serial.print(F("/"));
        Serial.print(gps.date.year());

        M5.Display.fillRect(0, 100, 320, 60, BLACK);
        M5.Display.setCursor(0, 100);
        M5.Display.printf("Date/Time: %d/%d/%d\n", gps.date.month(), gps.date.day(), gps.date.year());

    } else {
        Serial.print(F("INVALID"));
    }

    Serial.print(F(" "));
    if (gps.time.isUpdated()) {
        if (gps.time.hour() < 10) Serial.print(F("0"));
        Serial.print(gps.time.hour());
        Serial.print(F(":"));
        if (gps.time.minute() < 10) Serial.print(F("0"));
        Serial.print(gps.time.minute());
        Serial.print(F(":"));
        if (gps.time.second() < 10) Serial.print(F("0"));
        Serial.print(gps.time.second());
        Serial.print(F("."));
        if (gps.time.centisecond() < 10) Serial.print(F("0"));
        Serial.print(gps.time.centisecond());

        M5.Display.fillRect(0, 160, 320, 60, BLACK);
        M5.Display.setCursor(0, 160);
        M5.Display.printf("Time: %d:%d:%d.%d\n", gps.time.hour(), gps.time.minute(), gps.time.second(),
                          gps.time.centisecond());

    } else {
        Serial.print(F("INVALID"));
    }

    Serial.println();
    delay(1000);
}

3. Compile and Upload

  • 1.Download Mode: Before flashing the program, the device must be in download mode. This step may vary depending on the main controller used. For detailed steps, refer to the Arduino IDE Getting Started Guide , which lists specific operations for different devices.

  • To enter download mode on the CoreS3, press and hold the reset button for about 2 seconds until the internal green LED lights up. Then release the button. The device is now in download mode, waiting for the program to be uploaded.

  • 2.Select the device port and click the compile and upload button at the top left of the Arduino IDE. Wait for the program to compile and upload to the device.

4. Satellite Positioning

Connect the included external antenna, place it by a window or in an open outdoor area, and wait for the device to successfully search for satellites and obtain coordinates.

On This Page