GPS positioning

Prepare

Hardware

Required hardware as below:

  • Duinopeak SIM808 GPRS/GSM+GPS+Bluetooth all in one Shield
  • Active GPS Antenna 
  • An Peakduino UNO or Arduino UNO
  • USB cable for your Peakduino UNO or Arduino UNO
  • 12V/9V/1.5A Power supply

Software

  • Arduino IDE(recommended version 1.56r2 or above)
  • Libraries for Duinopeak SIM808 Shield (For Duinopeak_Arduino_SIMCom libarary please download here, or on github)

Make sure your got everyting, let's get started.

First of all we need hook up the hardware as below.

Note:

  • Make sure your external antenna has a good sight to receive the GPS signal, put the antenna outside the window of your room is need for this step.
  • The sketch use Software Serial PIN_TX 2,PIN_RX 3, so make sure you set the Serial jumper in correct postion.
  • Remember to plug the external power supply to your Arduino/Peakduino UNO, if you use Peakduino the VIN led should be light up.

Now setup the programming environment. You need install the Duinopeak_Arduino_SIMCOM libarary files first, then load the test sketch and upload to your Peakduino/Arduino UNO.

Here’s a quick example, which uses the Duinopeak_Arduino_SIMCom library to parse NMEA strings for position, altitude, time, and date.

#include "SIM900.h"
#include <SoftwareSerial.h>
//#include "inetGSM.h"
//#include "sms.h"
//#include "call.h"
#include "gps.h"

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.duinopeak.com
//this code is based on the example of Arduino Labs.

//Simple sketch to start a connection as client.

//InetGSM inet;
//CallGSM call;
//SMSGSM sms;
GPSGSM gps;

char lon[15];
char lat[15];
char alt[15];
char time[20];
char vel[15];
char msg1[5];
char msg2[5];

char stat;
char inSerial[20];
int i = 0;
boolean started = false;
#define BAUDRATE  9600

void setup()
{
  //Serial connection.
  Serial.begin(BAUDRATE);
  Serial.println("SIM808 Shield GPS testing.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  if (gsm.begin(BAUDRATE)) {
    Serial.println("\nstatus=READY");
    gsm.forceON();    //To ensure that SIM908 is not only in charge mode
    started = true;
  } else Serial.println("\nstatus=IDLE");

  if (started) {
    if (gps.attachGPS()) //GPS attach
      Serial.println("status=GPSREADY");
    else Serial.println("status=ERROR");
    stat = gps.getStat();
    while (stat != 3 && stat != 2) {
      stat = gps.getStat();
      if (stat == 1)
        Serial.println("NOT FIXED");
      else if (stat == 0)
        Serial.println("GPS OFF");
      else if (stat == 2)
        Serial.println("2D FIXED");
      else if (stat == 3)
        Serial.println("3D FIXED");
      delay(3000);
    }
    delay(3000);
    //Get data from GPS
    gps.getPar(lon, lat, alt, time, vel);
    Serial.println(lon);
    Serial.println(lat);
    Serial.println(alt);
    Serial.println(time);
    Serial.println(vel);
  }
};

void loop()
{
  //Read for new byte on serial hardware,
  //and write them on NewSoftSerial.
  serialhwread();
  //Read for new byte on NewSoftSerial.
  serialswread();
};

void serialhwread()
{
  i = 0;
  if (Serial.available() > 0) {
    while (Serial.available() > 0) {
      inSerial[i] = (Serial.read());
      delay(10);
      i++;
    }

    inSerial[i] = '\0';
    if (!strcmp(inSerial, "/END")) {
      Serial.println("_");
      inSerial[0] = 0x1a;
      inSerial[1] = '\0';
      gsm.SimpleWriteln(inSerial);
    }
    //Send a saved AT command using serial port.
    if (!strcmp(inSerial, "TEST")) {
      //      Serial.println("BATTERY TEST 1");
      //      gps.getBattInf(msg1,msg2);
      //      Serial.println(msg1);
      //      Serial.println(msg2);
      //      Serial.println("BATTERY TEST 2");
      //      gps.getBattTVol(msg1);
      //      Serial.println(msg1);
      stat = gps.getStat();
      if (stat == 1)
        Serial.println("NOT FIXED");
      else if (stat == 0)
        Serial.println("GPS OFF");
      else if (stat == 2)
        Serial.println("2D FIXED");
      else if (stat == 3)
        Serial.println("3D FIXED");
    }
    //Read last message saved.
    if (!strcmp(inSerial, "MSG")) {
      Serial.println(msg1);
    } else {
      Serial.println(inSerial);
      gsm.SimpleWriteln(inSerial);
    }
    inSerial[0] = '\0';
  }
}

void serialswread()
{
  gsm.SimpleRead();
}

Open Arduino IDE and load the KZB_0030_SIM808_GPS sketch and upload to your Peakduino/Arduino.

 

Open the serial monitor when upload done, you will see the SIM808 shield automatic powering on and the status LED(important) light up, as below image.

If not check the pwr jumper location on the shield back side. 

Then the program wait for 2D/3D fixing signal, this will taken 20 seconds-5 mins depending on your GPS signal strength. A successful fixed GPS postioning will look something like this:

 

 

Book type: