GPS and XBee in API mode

Hi this is my first time to use Arduino and have trouble using gps and xbee in api mode at the same time.

I have 4 Arduino UNO, 4 gps modules, 5 Xbees.

Arduino is connected a gps module and xbee. Each arduino will send an array to pc using Xbee. Xbees are in API mode to make star network.

Also, for gps modul and xee, I am using two SoftwareSerials.

I was trying to read and parse gps data then send an array to pc. The sketch to parse gps data works fine and so does the sketch to send an array to pc. But if I put the sketches all together(reading and parsing gps, sending data to pc), I cannot get gps values from the module. I couldn’t find the reason why gps module stop working. Here is my code

#include <TinyGPS.h>
#include <TinyGPSPlus.h>

#include <Printers.h>
#include <XBee.h>

#include <SoftwareSerial.h>

/////////////////gps
int RXPin_gps = 4;
int TXPin_gps = 5;

////////////////xbee
int RXPin_xbee = 2;
int TXPin_xbee = 3;

TinyGPSPlus gps;

SoftwareSerial gpsSerial(RXPin_gps, TXPin_gps);

XBee xbee = XBee();
SoftwareSerial xbeeSerial(RXPin_xbee,TXPin_xbee);

double Lat ;
double Lng ;

uint8_t payload[3] = { 0,0};

Tx16Request tx = Tx16Request(0x1000, payload, sizeof(payload));

void setup() {
 
  Serial.begin(9600);
  gpsSerial.begin(9600);
  xbeeSerial.begin(9600);
  xbee.setSerial(xbeeSerial);

  }

void loop() {

   gpsSerial.listen();
   
   while (gpsSerial.available() > 0)
    if (gps.encode(gpsSerial.read())){
      Lat = gps.location.lat();
      Lng = gps.location.lng();
      Serial.println(Lat,6);
      Serial.println(Lng,6);
    }

    xbee.send(tx);
  
}

What do you think is the problem? Any solution? Please help me!

If I had to bet money, I'd say that the multiple packets sent to the PC are arriving at the same time and are causing the RF signals at the coordinator to become jarbled.

In other words, I think each XBee is trying to talk at the same time and the listening XBee can't make out any of the signals.

To fix this, you will need to be very careful in how you configure and time your messages. You might possibly use an RTC (Real Time Clock) to help time transmissions.

Hope this helps!

You include both TinyGPS and TinyGPSPlus? You declare an instance of TinyGPSPlus, so don't include TinyGPS.

If you get one character from the GPS, you send a packet? I would suggest you read this Troubleshooting section from a GPS library I wrote, NeoGPS. You don't have to switch to NeoGPS, but it may help you understand how the stream of characters from the GPS device affects your sketch. Hint: 2 SoftwareSerials are not going to work the way you are trying to use them. Are pins 8 & 9 available, because that would help a lot.

If you don't have a valid lat/lon yet, you send a packet? I would suggest you read the NeoGPS Data Model description, near the middle of the page:

However, there are two things to know before accessing the fix data:

(1) You must wait for the sentence to be completely decoded...
(2) You must check that the fix piece is valid.

You should take look at the example program NMEAloc.ino for a loop structure that has a better chance of working.

And, to limit the number of packets you send, you might want to select one NMEA sentence to provide the lat/lon. Here are the common ones. As you have written it, at least two packets will be sent by each node, every second (depends on your device and configuration).

Cheers,
/dev

i tried to send gps location to arduino via xbee and receive it.

I have 2 Arduino nano, 2 gps modules and 2 Xbees.

i need to send and receive another arduino location , full dublix code can you help me ?

There is a problem using two software serials at the same time. They are processor intensive and timing sensitive so you will usually get junk data. It’s best to keep software serial to a single instance. You may get around that using NewSoftSerial as long as you don’t use the software serial ports at the same time. More explanation here:

http://arduiniana.org/libraries/newsoftserial/

freaklabs:
There is a problem using two software serials at the same time. They are processor intensive and timing sensitive so you will usually get junk data. It's best to keep software serial to a single instance. You may get around that using NewSoftSerial as long as you don't use the software serial ports at the same time. More explanation here:

NewSoftSerial | Arduiniana

The Arduino's used to have a crappy SoftwareSerial class. The NewSoftSerial class was a big improvement over the old SoftwareSerial class. With the 1.0+ versions of the IDE, the NewSoftSerial class became the SoftwareSerial class.

Using NewSoftSerial in place of SoftwareSerial will produce no benefit.

freaklabs:
There is a problem...

Your information is really out of date.

NeoGPS has a section on choosing serial ports. Although it only mentions GPS, it applies to connecting multiple serial devices, like GSM and GPS.

If you're careful, you can have two software serial ports in addition to Serial (a HardwareSerial port). There is additional information on each of the alternatives' pages (see NeoSWSerial and AltSoftSerial links).