Example Code for Arduino-GNSS Positioning

Last revision 2025/12/09

This example shows how to use the SIM7070G expansion board for GNSS positioning. Users can learn how to initialize the positioning function and retrieve latitude and longitude data.

Hardware Preparation

  • DFR0216 DFRduino UNO R3 - Arduino Compatible x1
  • SIM7070G Arduino NB-IoT/LTE/GPRS Expansion Shield x1
  • USB Wire x1
  • 7V~12V DC Power Supply x1
  • GPS Antenna (for GNSS positioning)

Software Preparation

Wiring Diagram

Plug the SIM7070G Arduino NB-IoT/LTE/GPRS Expansion Shield to DFRduino UNO R3 directly.

The module SIM7070G requires a 7-12V external power supply. And please switch the hardware and software serial control switch to TX-D8, RX-D7.

Wiring Diagram

Other Preparation Work

  • When using GNSS positioning, first plug in the GPS antenna and place the expansion board outdoors.
  • Since Arduino UNO only has one hardware serial port, it is recommended to use software serial communication when using it. The SIM7000 library file uses software serial by default. Please switch the software/hardware serial control switch to TX>D8, RX>D7.

Sample Code

#include <DFRobot_SIM7070G.h>

#define PIN_TX     7
#define PIN_RX     8
SoftwareSerial     mySerial(PIN_RX, PIN_TX);
DFRobot_SIM7070G    sim7070g(&mySerial);

void setup()
{
  delay(1500);   
  Serial.begin(115200);
  mySerial.begin(19200);

  Serial.println("Turn ON SIM7070G......");
  if (sim7070g.turnON()) {                                          
    Serial.println("Turn ON !");
  }

  Serial.println("Set baud rate......");
  while (1) {
    if (sim7070g.setBaudRate(19200)) {                            
      Serial.println("Set baud rate:19200");
      break;
    } else {
      Serial.println("Faile to set baud rate");
      delay(1000);
    }
  }

  Serial.println("Check SIM card......");
  if (sim7070g.checkSIMStatus()) {                                  
    Serial.println("SIM card READY");
  } else {
    Serial.println("SIM card ERROR, Check if you have insert SIM card and restart SIM7070G");
    while (1);
  }

  Serial.println("Init positioning function......");
  while (1) {
    if (sim7070g.initPos()) {
      Serial.println("Positioning function initialized");
      break;
    } else {
      Serial.println("Fail to init positioning function");
      delay(1000);
    }
  }
}

void loop()
{
  Serial.println("Enter anything end with CRLF to get positioning ");
  char loge[10];
  readSerial(loge);
  Serial.println("Getting position......");
  if (sim7070g.getPosition()) {                                     
    Serial.print(" Longitude : ");
    Serial.println(sim7070g.getLongitude());                    
    Serial.print(" Latitude : ");
    Serial.println(sim7070g.getLatitude());                    
  } else {
    Serial.println("Wrong data try again");
  }
}

int readSerial(char result[])
{
  int i = 0;
  while (1) {
    while (Serial.available() > 0) {
      char inChar = Serial.read();
      if (inChar == '\n') {
        result[i] = '\0';
        Serial.flush();
        return 0;
      }
      if (inChar != '\r') {
        result[i] = inChar;
        i++;
      }
    }
  }
}

Result

The serial monitor will print some successful initialization information, followed by latitude and longitude information.

Was this article helpful?

TOP