Arduino to Arduino Communication of GPS Data

Hi! I am trying to create a system where a motor(with an encoder) points to an external object using both of their live gps data together.

Basically, I need to wirelessly receive the positions of two different gps modules on two different arduinos, and then I will use that information to accomplish a task.

However, although it seems relatively easy to extract the gps data from one module, how would I go about communicating between the arduinos / getting the two sets of data together?

If this is not viable, is there another way I can accomplish this task?

Thanks!! :slight_smile:

I've been able to accomplish communicating GPS data from one Arduino to another in one of my projects using the library SerialTransfer.h. The library is installable through the Arduino IDE's Libraries Manager.

I suggest putting all of your GPS data into a struct and sending the struct via SerialTransfer.h.

Example TX Code:

#include "SerialTransfer.h"
#include <SoftwareSerial.h>


SoftwareSerial mySerial(2, 3); // RX, TX
SerialTransfer myTransfer;


struct STRUCT {
  char z;
  float y;
} testStruct;


void setup()
{
  Serial.begin(115200);
  mySerial.begin(9600);
  myTransfer.begin(mySerial);

  testStruct.z = '|';
  testStruct.y = 4.5;
}


void loop()
{
  myTransfer.txObj(testStruct, sizeof(testStruct));
  myTransfer.sendData(sizeof(testStruct));
  delay(100);
}

Example RX Code:

#include "SerialTransfer.h"
#include <SoftwareSerial.h>


SoftwareSerial mySerial(2, 3); // RX, TX
SerialTransfer myTransfer;


struct STRUCT {
  char z;
  float y;
} testStruct;


void setup()
{
  Serial.begin(115200);
  mySerial.begin(9600);
  myTransfer.begin(mySerial);
}


void loop()
{
  if(myTransfer.available())
  {
    myTransfer.rxObj(testStruct, sizeof(testStruct));
    Serial.print(testStruct.z);
    Serial.print(' ');
    Serial.print(testStruct.y);
  }
  else if(myTransfer.status < 0)
  {
    Serial.print("ERROR: ");
    Serial.println(myTransfer.status);
  }
}

Awesome! So this is wireless and it wouldn't require any other modules or anything like that besides the arduinos themselves? How does that work?

Thanks for the response!

Hi,
Welcome to the forum.

How far apart will the two gps be?
How much precision of the gps position do you need?

Tom..... :slight_smile:

chickenriot:
Awesome! So this is wireless and it wouldn't require any other modules or anything like that besides the arduinos themselves? How does that work?

You can use the library to transfer data with the Arduino serial ports hardwired together, or you can use wireless UART radios (i.e. XBees) to wireless connect the Arduinos without having to change the software.

Basically, the software is agnostic to whether the data is being transmitted wired or wireless. That being said, if you want to go wireless - you'll need external UART radios for connection...

Oh, I see. Well, I need it to be wireless, and as for their distance apart, not too far, maybe a couple dozen meters at most. The more distance possible the better though for sure. And for accuracy, once again, the more the better, but being a couple feet off probably wouldn't be the end of the world.

I was considering maybe using bluetooth? Would that be better than a radio?

chickenriot:
I was considering maybe using bluetooth? Would that be better than a radio?

That should be perfect. Also, bluetooth uses radios.

About precision - you can transmit GPS data with no loss of precision using the library I linked if used propperly.

Bluetooth is not very long range. I might consider the rf24 2.4GHz radios. Robin2's simple rf24 demo tutorial can get you started with those radios.

Ok, I'll look into that, and post more on here if i run into any problems. Thanks so much for the help!

chickenriot:
and as for their distance apart, not too far, maybe a couple dozen meters at most. The more distance possible the better though for sure. And for accuracy, once again, the more the better, but being a couple feet off probably wouldn't be the end of the world.

So from that the two GPSs are maybe 20M apart and you want sub 1M accuracy ?

Very unlikley to happen, if the GPSs are outdoors with a clear view of the sky you might get an accuracy 5M or so but dont depend on it.

Oh wow ok ... so how do I get more accuracy? I saw something called GPS RTK which is supposed to way more accurate but it's a couple hundred dollars for just one module... any ideas?

chickenriot:
Oh wow ok ... so how do I get more accuracy?

There is GPS RTK and GPS differential. Neither are cheap.

There is, as far as I know, no cunning wheeze way of getting sub 1M accuracy from GPSs on the cheap. If there was then you would expect it to be easy to find and everyone would be doing it.

What about other types of sensors? Maybe lidar? Ultrasonic? lasers?

Or even just a long range motion sensor? the object I'm trying to track will be moving.

What are the differences between the suggested: SerialTransfer.h

And normal software (or even hardware serial) approach?

What does this 'transfer' stuff do differently?

Buffer and delimiting characters for packets? (if this just for ease of use or something? as all this can be done in your code? packets/protocols/start or packet-end of packet delimiting characters)

xl97:
What are the differences between the suggested: SerialTransfer.h

And normal software (or even hardware serial) approach?

What does this 'transfer' stuff do differently?

I'm not sure I understand the question, but I'll try to answer as best I can. The basic gist of the library is that it provides a simple and robust interface to packetize and parse data packets. It can work with hardware and software serial ports alike.

If you're curious about the library's features, you can see a list in the readme file:

This library:

  • can be downloaded via the Arduino IDE's Libraries Manager (search "SerialTransfer.h")
  • works with "software-serial" libraries
  • is non blocking
  • uses packet delimiters
  • uses consistent overhead byte stuffing
  • uses CRC-8 (Polynomial 0x9B with lookup table)
  • allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 255 bytes)
  • can transfer bytes, ints, floats, and even structs!!