Usage Example for Arduino-Read Data via UART
Hardware Preparation
- DFRduino UNO R3 + Gravity: IO Expansion Shield (or similar) x 1
- Gravity: GNSS Positioning Module x 1
Software Preparation
- Arduino IDE
- Download and install the DFRobot GNSS Library. (About how to install the .zip library?)
- Or search and install "DFRobot_GNSS" library in the library manager
Wiring Diagram

Operation Steps
- Connect the module to Arduino according to the connection diagram above. It can also be used with Gravity I/O expansion board to prototype ideas faster.
- Change the select switch on the sensor to UART.
- Download and install the DFRobot_GNSS library. (About how to install the library?)
- Open Arduino IDE and upload the following code to Arduino UNO.
- Open the serial monitor of Arduino IDE, set the baud rate to 115200, and observe the printed result.
Sample Code
/*!
* @file getGNSS.ino
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author ZhixinLiu([email protected])
* @version V0.1
* @date 2022-08-15
* @url https://github.com/dfrobot/DFRobot_GNSS
*/
#include "DFRobot_GNSS.h"
//DFRobot_GNSS_I2C gnss(&Wire ,GNSS_DEVICE_ADDR);
#ifdef ESP_PLATFORM
// ESP32 user hardware uart
// RX io16
// TX io17
DFRobot_GNSS_UART gnss(&Serial2 ,9600);
#else
// Arduino user software uart
// RX io10
// TX io11
SoftwareSerial mySerial(10 ,11);
DFRobot_GNSS_UART gnss(&mySerial ,9600);
#endif
void setup()
{
Serial.begin(115200);
while(!gnss.begin()){
Serial.println("NO Deivces !");
delay(1000);
}
gnss.enablePower();
/** Set the galaxy to be used
* eGPS USE gps
* eBeiDou USE beidou
* eGPS_BeiDou USE gps + beidou
* eGLONASS USE glonass
* eGPS_GLONASS USE gps + glonass
* eBeiDou_GLONASS USE beidou +glonass
* eGPS_BeiDou_GLONASS USE gps + beidou + glonass
*/
gnss.setGnss(eGPS_BeiDou_GLONASS);
// gnss.setRgbOff();
gnss.setRgbOn();
// gnss.disablePower();
}
void loop()
{
sTim_t utc = gnss.getUTC();
sTim_t date = gnss.getDate();
sLonLat_t lat = gnss.getLat();
sLonLat_t lon = gnss.getLon();
double high = gnss.getAlt();
uint8_t starUserd = gnss.getNumSatUsed();
double sog = gnss.getSog();
double cog = gnss.getCog();
Serial.println("");
Serial.print(date.year);
Serial.print("/");
Serial.print(date.month);
Serial.print("/");
Serial.print(date.date);
Serial.print("/");
Serial.print(utc.hour);
Serial.print(":");
Serial.print(utc.minute);
Serial.print(":");
Serial.print(utc.second);
Serial.println();
Serial.println((char)lat.latDirection);
Serial.println((char)lon.lonDirection);
// Serial.print("lat DDMM.MMMMM = ");
// Serial.println(lat.latitude, 5);
// Serial.print(" lon DDDMM.MMMMM = ");
// Serial.println(lon.lonitude, 5);
Serial.print("lat degree = ");
Serial.println(lat.latitudeDegree,6);
Serial.print("lon degree = ");
Serial.println(lon.lonitudeDegree,6);
Serial.print("star userd = ");
Serial.println(starUserd);
Serial.print("alt high = ");
Serial.println(high);
Serial.print("sog = ");
Serial.println(sog);
Serial.print("cog = ");
Serial.println(cog);
Serial.print("gnss mode = ");
Serial.println(gnss.getGnssMode());
delay(1000);
}
Running Results
Open serial monitor to see the result.

Was this article helpful?
