Dragino LoRa GPS Tracker

40,926

139

17

We always appreciate your support and advice.

In this project,we'll show how to get GPS data from a remote Arduino via Wireless Lora Protocol and show the track on the GoogleEarth.The construction of this project is similar to my last one:

1) Client Side: Arduino + Lora/GPS Shield (868Mhz).

2) Server Side: Arduino + Lora Shield (868Mhz) + Yun Shield + USB flash.

Client side will get GPS data and keep sending out to the server via Lora wireless. Server side will listen on the Lora wireless frequency, once it get the data from Client side, it will turn on the LED and log the GPS data to a USB flash.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1:

The Dragino Lora/GPS Shield is an expension board for LoRa™/GPS for using with the arduino.This product is intended for those interested in developing LoRa™/GPS solutions.The Lora/GPS Shield is composed of Lora/GPS Shield mother board and Lora BEE.

In the Lora part,the Lora/GPS Shield is based on the SX1276/SX1278 transceiver.The transceiver of the Lora/GPS Shield feature the LoRa™ long range modem that provides ultra-long range spread spectrum communication and high interference immunity whilst minimising current consumption. LoRa™ also provides significant advantages in both blocking and selectivity over conventional modulation techniques, solving the traditional design compromise between range,interference immunity and energy consumption.

In th GPS part,the add on L80 GPS (base on MTK MT3339) is designed for applications that require location or timing info. It connected to the arduino via serial port .

If you want to get more info about the Lora/GPS shield, please click this link:http://wiki.dragino.com/index.php?title=Lora/GPS_Shield

Step 2: Introduction of Lora BEE

The Dragino Lora BEE is a Lora moudule allows the user to send data and provides ultra-long range spread spectrum communication and high interference immunity whilst minimising current consumption.

The Lora BEE is based on the SX1276/SX1278 transceiver.The Lora BEE targets professional wireless sensor network applications such as irrigation systems, smart metering, smart cities, smartphone detection,building automation, and so on.

Step 3: Construction

Step 4: Hardware Preparations:

The project requries below hardwares:

  • Arduino board x 2 (We use an UNO board and a MEGA 2560 here)
  • Dragino Lora/GPS Shield x 1 (We use 868MHZ here)
  • Dragino Lora Shield x 1 (We use 868MHZ here)
  • Yun Shield v1.1.6 x 1
  • USB flash x 1
  • TTL to USB adapter x 1
  • 868MHZ antenna x 2
  • Ethernet cable x 1
  • USB cable x 2
  • LED x 1
  • 12V Batteries x 2
  • Some jump wires

Note: About the Yun Shiled,we must use the Yun Shield v1.1.6/Yun Shield v2.4 or higher version.

Step 5: Other Preparations:

In addition, we have to make the following preparations:

In this project you will use the "SoftareSerial.h" and "Radiohead.h" in the sketch,therefore,put the two libraries into your IDE libraries.

As you can see from the "server sketch" at the next steps,we store the GPS data in the file "/data/datalog.csv" of the USB flash,so we need to create a directory named “data” in the USB flash root.

Step 6: Connections

Connect the client and the server as above pictures.
In the sketch we use the hardware serial to communicate with the GPS and use the software serial(RX /D3,TX/D4) to debug via Arduino serial monitor.So,we connect the client to computer by TTL to USB adapter,the wiring is:

TTL to USB adapter --------------- Arduino UNO

RX ----------------- D4

TX ------------------ D3

GND ------------------ GND

On the Lora/GPS Shield,put the RXD/TXD jumpers on the status as the 3rd picture.(Connect GPS to the hardware serial)

You can get the Lora/GPS Shield hardware resource from:here.

NOTE:

  • The LED is on the D4 (Server).
  • Put the antenna on the boards.
  • Check the wiring carefully.

Step 7: Upload Sketch

Power them by 12v batteries,and connect them to the computer via USB cable or Ethernet cable.

At this step,make sure you have put the "SoftwareSerial.h" and "RadioHead.h" into your IDE libraries folder.

Client:

We use UNO+Lora/GPS Shiled as the client here.The GPS was connected to the hardware serial,in order to upload the sketch successfully,we need to press the "RST" button to reset the GPS to release occupation of arduino hardware serial until upload done. Open the IDE(Version 1.6.8 here),choose the correct board and correct port for you arduino,copy the client sketch to IDE,upload it to the board.

Server:

Upload the server sketch to the arduino board.

About how to use the Dragino YUN to upload the sketch,click:http://wiki.dragino.com/index.php?title=Yun_Shield

About the "RST" button

The GPS module can be restarted by driving the RESET to a low level voltage for a certain time and then
releasing it. Press the "RST" button will reset the digital part of the GPS receiver.

If you connect the GPS to the arduino by hardware serial,you need to press the "RST" button to release occupation of arduino hardware serial until the upload is complete.

Step 8: Test

We take an outdoor test today.At the beginning of this test,make sure the 3D_FIX(The blue LED) is flashing on the Lora/GPS Shield,it means the GPS get fixed.

As shown in the code: Lora send data after the GPS get fixed.Theoretically, it requires that GPS module has to track at least three satellites for positioning.

Step 9: Running Result

When the GPS get no fixed,the running result of the clients is as the first picture.(We get the running result from the client via software serial here.)
After the GPS module fixed,if the server an client are in the transmission range,you can see the LED flashing on D4 on server,and you can also get the running result as the 2nd picture(Client) and the 3rd picture(Server).

Then you can find a "datalog.csv" file in the data folder of the USB flash,open the csv file and you will see the longitude and latitude data collected by GPS receiver.(4th picture)

You can also edit the code to get more data from the GPS.

Step 10: Data Processing

We need to convert the csv file into kml file ,so we can import the datalog to the GoogleEarth.We use the "KMLCSV Converter" here,complete the following operation:

  1. Open the KMLCSV Converter,click File->Configration
  2. Click 'File Management- Browser' to choose the folder for storing datalog.csv
  3. As the 3rd picture,choose the "datalog.csv" and click the "Create File " button to create a kml file in the same folder.("datalog.kml")

Then you can find "datalog.kml" file in the folder where stores the "datalog.csv".(Picture 4)

Step 11: Import Map

Open "the datalog.kml" by the GoogleEarth,we get above pictures.We can see the GPS track there.

Step 12: Conclusion and Notices

In this project,we get the GPS track successfully.You can get more GPS data that you need from the Lora/GPS Shield,you can also build you own sensor transceiver by the board.It's a good idea if you want to use the Lora/GPS Shield in your LoRaWan construction.

Usage Notice

Make sure what serial you want to use,hardware serial or software serial?
Make sure the serial you use in Sketch reflect the exactly connection, we are using two serial here and easy to get confuse between them.

You have to be aware that Radio link quality and performances are highly dependent of environment. Better performances can be reached with:

  • Outdoor environment.
  • No obstacles.
  • No high level radio interferer in the ISM 868MHz band.
  • At least 1 meter above the ground.

Radio performances are degraded with:

  • Obstacles: buildings, trees...
  • Inner buildings environments.
  • High ISM 868MHz band usage by other technologies.

Radio communication are usually killed with bad topographic conditions. It is usually not possible to communicate through a hill, even very small.

Step 13: Reference

Share

    Recommendations

    • Indoor Lighting Contest

      Indoor Lighting Contest
    • Make It Fly Challenge

      Make It Fly Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    17 Discussions

    0
    None
    AllenS64

    2 years ago

    Can anyone advise what to use for a GPS implementation for cat/otter tracking? Gotta be low power, small and light, and I need to be able to see where these cute little creatures are from my secret lair. (The scenario is analogous, but thats the general idea of course)


    2 replies
    0
    None
    DavidGuoAllenS64

    Reply 2 years ago

    Yeah,it seems very interesting,we need to choose the smaller MCU,wireless communication module and GPS module,and these components will be integrated into a PCB,I think it also depend on the cats' scope of activity,will you make it?

    0
    None
    oyekaDavidGuo

    Reply 5 days ago

    Please, how far av you gone about this cat tracker, I urgently need it.

    1
    None
    AndrewT209

    3 months ago

    GPS to google maps live track. Using 2 or more Lora GPS ESP32. and one of them connected over seriaI USB debug cable. It sends a reconstructed valid NMEA string and streams it to google maps that is received from any other T-Beam that has a valid GPS lock. used these module https://www.banggood.com/Wemos-TTGO-T-Beam-ESP32-433868915Mhz-WiFi-Wireless-Bluetooth-Module-p-1320390.html?currency=GBP&utm_source=bing_pa&utm_medium=cpc_bgs&utm_content=zouzou&utm_campaign=pa-gb-all-pc-zouzou&ID=510803&cur_warehouse=UK
    fitted a display https://www.ebay.co.uk/itm/Yellow-Blue-0-96-I2C-IIC-Serial-128X64-OLED-LCD-LED-Display-Module-Arduino/141676861754?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

    Below program
    to program as many T-beam lora GPS ESp32 using arduino IDE
    The received data is displayed on the OLED along with signal strength of any other near by module that transmits it's position every 10 seconds. Goal is to have all modules also repeat other modules data to create a mesh. Looking to see if Lora Wan is a direction i should investigate to create repeaters or build my own mesh network, that can also implement Lorawan. Find tall building or landscape to create solar powered base station repeaters.

    The WiFi is un-implemented at the moment.

    //#include <MyHardwareSerial.h>
    #include <SPI.h>
    #include <LoRa.h>
    #include <Wire.h>
    #include <TinyGPS++.h>
    #include "SSD1306.h"
    #include <WiFi.h>
    //extern HardwareSerial Serial(0);
    //extern HardwareSerial Serial1(1);
    HardwareSerial MySerial2(2);
    TinyGPSPlus gps;
    #define SCK 5 // GPIO5 -- SX1278's SCK
    #define MISO 19 // GPIO19 -- SX1278's MISnO
    #define MOSI 27 // GPIO27 -- SX1278's MOSI
    #define SS 18 // GPIO18 -- SX1278's CS
    #define RST 14 // GPIO14 -- SX1278's RESET
    #define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request)
    #define BAND 868E6
    SSD1306 display(0x3c, 21, 22);
    //String Reconstruct;
    const byte buff_len = 90;
    char CRCbuffer[buff_len];
    String msg="";
    String rssi = "RSSI --";
    String packSize = "--";
    String packet ;
    String TimeNow;
    String NS;
    String EW;
    uint64_t chipid;
    int sats;
    int hrs;
    int mins;
    int secs;
    float Longt;
    float Langt;
    unsigned int counter = 0;
    char ssid[]= "**Your Wifi name "; // your network SSID (name)
    char pass[] = "**Your wifi password"; // your network password (use for WPA, or use as key for WEP)
    int status = WL_IDLE_STATUS; // the Wifi radio's status
    void loraData(){
    display.clear();
    display.drawString(0 , 16, packet);
    display.drawString(50, 0, rssi);
    display.display();
    //Serial.println(packet);
    //Serial.println("Recieved" + packSize + " bytes");
    //Serial.println(rssi);
    /// send dummy check Google earth can pick data out
    if (packet.substring(0,1)=="A"){
    String sats = (getValue(packet,',',0));
    String hrs = ( getValue(packet,',',1));
    String mins = (getValue(packet,',',2));
    String secs = (getValue(packet,',',3));
    String latitude = (getValue(packet,',',4));
    String longitude = (getValue(packet,',',5));
    String height = getValue(packet,',',6);
    //Serial.println("SATS:" + sats);
    //Serial.println(hrs + ":" + mins + ":" + secs);
    //Serial.println("Lng: " + longitude);
    //Serial.println("Lat: " + latitude);
    float Longt= atof(longitude.c_str());
    float Langt = atof(latitude.c_str());
    //Serial.println(Longt);
    //Serial.println (Langt);
    if ((Longt)>0) {
    EW="W";
    }
    else {
    EW="E";
    Longt=(-Longt);
    }
    if ((Langt)>0 ){
    NS="S";
    }
    else {
    NS="N";
    Langt=(-Langt);
    }
    long Longtm=(int(Longt));
    long Langtm=(int(Langt));
    //Serial.println(Longtm);
    //Serial.println (Langtm);
    Longt=(Longt-Longtm)*60+(Longtm*100);
    Langt=(Langt-Langtm)*60+(Langtm*100);
    //Serial.println(Longt);
    //Serial.println(Langt);
    //msg =("$GPRMC,002454,A,3553.5295,N,13938.6570,E,0.0,43.1,180700,7.1,W,A*");// valid fake NMEA 3F is checksum
    //outputMsg(msg); // ouput a valid test NMEA string
    msg = ("$GPRMC,002454,A," + String(Longt) + "," + NS +","+ String (Langt) + "," + EW + ",0.0,43.1,180700,7.1,W,A*");
    outputMsg(msg); // print the entire message string, and append the CRC
    }
    else {
    Serial.println("No Valid Fix");
    }
    }
    String getValue(String data, char separator, int index)
    {
    int found = 0;
    int strIndex[] = {0, -1};
    int maxIndex = data.length()-1;
    for(int i=0; i<=maxIndex && found<=index; i++){
    if(data.charAt(i)==separator || i==maxIndex){
    found++;
    strIndex[0] = strIndex[1]+1;
    strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
    }
    return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
    }
    void cbk(int packetSize) {
    packet ="";
    packSize = String(packetSize,DEC);
    for (int i = 0; i < packetSize; i++) { packet += (char) LoRa.read(); }
    rssi = "RSSI " + String(LoRa.packetRssi(), DEC) ;
    loraData();
    }
    void setup() {
    pinMode(16,OUTPUT);
    pinMode(2,OUTPUT);
    digitalWrite(16, LOW); // set GPIO16 low to reset OLED
    delay(50);
    digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high
    Serial.begin(4800);
    Serial1.begin(9600, SERIAL_8N1, 12, 15); //12-TX 15-RX >NEO GPS
    MySerial2.begin(9600, SERIAL_8N1, 13, 25); //13-TX 25-RX >Fake NMEA string for google earth
    while (!Serial);
    Serial.println();
    chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
    Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes
    Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes.
    SPI.begin(SCK,MISO,MOSI,SS);
    LoRa.setPins(SS,RST,DI0);
    if (!LoRa.begin(868E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
    }
    Serial.println("LoRa init ok");
    display.init();
    display.flipScreenVertically();
    display.setFont(ArialMT_Plain_10);
    LoRa.receive();
    // LoRa.onReceive(cbk);// Callback not working No Interupt on pin;
    }
    void loop() {
    smartDelay(10110);
    display.drawString(104,0, "TX");
    display.display();
    TimeNow=("Time "+String(gps.time.hour())+":"+String(gps.time.minute())+":"+ String(gps.time.second()));
    //Serial.println(String(TimeNow));
    //Serial.println(String(counter));
    counter++;
    // send packet
    LoRa.beginPacket();
    if (gps.satellites.value()>3) {
    LoRa.print("A");
    }
    else {
    LoRa.print("V");
    }
    //LoRa.print("Sats: ");
    LoRa.print(gps.satellites.value());
    LoRa.print(",");
    LoRa.print(gps.time.hour());
    LoRa.print(",");
    LoRa.print(gps.time.minute());
    LoRa.print(",");
    LoRa.print(gps.time.second());
    if (gps.satellites.value()>3){
    LoRa.print(",");
    LoRa.print(gps.location.lng(), 5);
    LoRa.print(",");
    LoRa.print(gps.location.lat(), 5);
    LoRa.print(",");
    LoRa.print(gps.altitude.feet() / 3.2808);
    }
    LoRa.endPacket();
    MySerial2.println("Hello world");
    }
    void WiFiConnect()
    {
    // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
    }
    // you're connected now, so print out the data:
    Serial.print("You're connected to the network");
    // print your WiFi shield's IP address:
    IPAddress ip = WiFi.localIP();
    Serial.print("IP Address: ");
    Serial.println(ip);
    Serial.println(ip);
    // print your MAC address:
    byte mac[6];
    WiFi.macAddress(mac);
    Serial.print("MAC address: ");
    Serial.print(mac[5], HEX);
    Serial.print(":");
    Serial.print(mac[4], HEX);
    Serial.print(":");
    Serial.print(mac[3], HEX);
    Serial.print(":");
    Serial.print(mac[2], HEX);
    Serial.print(":");
    Serial.print(mac[1], HEX);
    Serial.print(":");
    Serial.println(mac[0], HEX);
    }
    // -----------------------------------------------------------------------
    void outputMsg(String msg) {
    msg.toCharArray(CRCbuffer,sizeof(CRCbuffer)); // put complete string into CRCbuffer
    byte crc = convertToCRC(CRCbuffer);
    Serial.print(msg); // repeat for UART output
    if (crc < 16) Serial.print("0"); // add leading 0 if needed
    Serial.println(crc,HEX);
    }
    //-------------------------------------------------------------------------
    byte convertToCRC(char *buff) {
    // NMEA CRC: XOR each byte with previous for all chars between '$' and '*'
    char c;
    byte i;
    byte start_with = 0;
    byte end_with = 0;
    byte crc = 0;
    for (i = 0; i < buff_len; i++) {
    c = buff[i];
    if(c == '$'){
    start_with = i;
    }
    if(c == '*'){
    end_with = i;
    }
    }
    if (end_with > start_with){
    for (i = start_with+1; i < end_with; i++){ // XOR every character between '$' and '*'
    crc = crc ^ buff[i] ; // compute CRC
    }
    }
    else { // else if error, print a msg (to both ports)
    Serial.println("CRC ERROR");
    }
    return crc;
    //based on code by Elimeléc López - July-19th-2013
    }
    static void smartDelay(unsigned long ms)
    {
    unsigned long start = millis();
    do
    {
    while (Serial1.available())
    gps.encode(Serial1.read());
    int packetSize = LoRa.parsePacket();
    if (packetSize) { cbk(packetSize); }
    } while (millis() - start < ms);
    }
    static void LoRaRxSmartWait(unsigned long ms)
    {
    unsigned long start = millis();
    while (LoRa.parsePacket()==0)
    while (millis() - start < ms);
    }
    static void MillDelay(unsigned long ms)
    {
    unsigned long start = millis();
    while (millis() - start < ms);
    }

    0
    None
    StevenTsengGU

    5 months ago

    I have tried today and it
    seems firmware 4.1.2 is not working and it works in my case using 4.1.0. But why I need to re-upload every time I turn on server? Is that because I remove sd card and re-plug in?

    0
    None
    zencuke

    3 years ago

    This is really cool. I really appreciate the Google Maps integration. That could be useful for lots of things. But could you gives us a hint about how "long" long range is. "long" is sort of vague. Order of magnitude is close enough. I followed the "Scarlet Knight" which did the first trans Atlantic crossing by an untended underwater glider and they did daily tracking maps with google maps and I always wondered how they did it. I know they used a satellite phone modem for communications but never understood the Google Maps part. Thanks.

    The following are all long range to someone.

    a) > 100 ft

    b) > 1000 ft

    c) > 1 mile

    d) > 100 miles

    e) > 1,000 miles

    f) > 10,000 miles

    g) > 10 light years gets you out of the local group.

    a) Lo111

    3 replies
    0
    None
    DavidGuozencuke

    Reply 3 years ago

    Open area max transmission distance ~15km,about 3km in the community.

    0
    None
    AmrithmmhDavidGuo

    Reply 7 months ago

    suppose its a city (medium scale) will i get 2-3km range?
    is there a way to get data from multiple lora transmitters and know all of their locations(they all have an id for transmission or something to identify?)
    ?

    0
    None
    Warholmzencuke

    Reply 3 years ago

    The Local group is 10 MILLION Light years across, so you would probably need >5 MILLION light years to give a chance of leaving it ... ;-)
    (Wikipedia: "The Local Group has a diameter of approximately 10 million light-years")

    0
    None
    nesaaa

    Question 10 months ago

    Hi, had tried uploading sketch for client unfortunately its failed. Could someone help me and show how the wiring of client

    0
    None
    ChristopherG200

    1 year ago

    Awesome tutorial! I am working on a similar build and I need some guidance with the server sketch. I do not want to log the data on board the server but would rather serial stream it to my pc where I will capture and log to excel or something like it. If anyone can point me in the right direction I would greatly appreciate it!

    0
    None
    AdamK238

    2 years ago

    Ok, so I've been trying to get this to work with exactly the same hardware set up as outlined here (bought the dragino shields) but cannot get the client to transmit anything using the sketches supplied. I can see the GPS sentences but the software serial just keeps reporting "sending to server" but never getting a response, the server just sits idle. I've tested the boards and shields with other examples and everything works as it should, including sending messages to and from client/server over the LoRa (915mhz). Any time I try the GPS Tracker sketches I get nothing.

    Has anyone else replicated this project?

    0
    None
    AdamK238

    2 years ago

    I'm trying to set up this same project but have the data stored in a google drive folder, via the dragino lora gateway. I'm having difficulty with the code and how to set up the gateway to do this - can anyone assist?

    Cheers,

    Adam

    0
    None
    darioabadie

    2 years ago

    Hello David. You have done a great job, congratulations! I have a doubt, if the Client is connected to PC via TTL/USB adapter, why in the first picture of step 7 does the Arduino Board seem to be connected too by USB? Thanks in advance!

    Dario

    0
    None
    mcghanjou

    2 years ago

    Can the client send the gps Position directly to the computer? Or we always need a server? How can the position of the server be known in the google earth file if the server doesn't have a gps module ? thank you !