GPS coordinates not updating during transmission

Hello,

I am trying to connect one Arduino uno to transmit GPS coordinates through nRF24L01 modules. As of right now, i have a steady communication between them but it is sending only one coordinate. I am receiving the first coordinate but after the first, it will not update when GPS is moved. I am using the BN-220 GPS module.

These are the current codes.

Transmitter code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>


TinyGPSPlus gps;
SoftwareSerial ss(4, 3);
RF24 radio(7,8); // CE, CSN
byte addresses[][6] = {"1Node", "2Node"};

struct dataStruct{
  double latitude;
  double longitude;
}gpsData;


void setup() {
  Serial.begin(115200);
  ss.begin(9600);
  Serial.println("Setting up radio");
  //  Setup transmitter radio
  radio.begin();
  radio.openWritingPipe(0xF0F0F0F0E1LL);
  radio.setChannel(0x76);
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate(RF24_2MBPS);
  radio.stopListening();
  radio.enableDynamicPayloads();
  radio.powerUp();
  Serial.println("Starting to send");
}
void loop() {
  while (ss.available() > 0){
    if (gps.encode(ss.read())){
      if (gps.location.isValid()){
    gpsData.longitude = gps.location.lng();
    gpsData.latitude = gps.location.lat(); }
  else{
    gpsData.longitude = 0.0;
    gpsData.latitude = 0.0;  }
     radio.write(&gpsData, sizeof(gpsData));
    }
  }
}

Receiver Code:


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8); // CE, CSN
byte addresses[][6] = {"1Node","2Node"};
struct dataStruct{
  double latitude;
  double longitude;
}gpsData;
/*double fixedlat = 45.536968;
double fixedlong = -73.770729;

double lat1 = radians(fixedlat);
double long1 = radians(fixedlong);
*/
void setup() {
  Serial.begin(115200);
  //  Setup receiver radio
  radio.begin();
  radio.openReadingPipe(1, 0xF0F0F0F0E1LL);
  radio.setChannel(0x76);
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate(RF24_2MBPS);
  radio.startListening();
  radio.enableDynamicPayloads();
  radio.powerUp();
}
void loop() {
  if (radio.available()) {
    radio.read(&gpsData, sizeof(gpsData));
    Serial.print("Location: ");
    Serial.print(radians(gpsData.latitude), 6);
    Serial.print(", ");
    Serial.print(radians(gpsData.longitude), 6);
    Serial.println();
   
 // Serial.println(lat1,6);
 // Serial.println(long1,6);   
    }
}

No idea … but I think by placing few print instructions you can check on what is actually being sent and what’s is received .
Either that or drop the gps part and just send a few numbers and then just look at what the gps is sending

Why send GPS data when you don't have valid GPS data?

It would make more sense to send data only when a valid sentence is decoded.

Hint: fix your indenting before posting, by pressing ^T in the Arduino editor, so that it looks like this:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>


TinyGPSPlus gps;
SoftwareSerial ss(4, 3);
RF24 radio(7, 8); // CE, CSN
byte addresses[][6] = {"1Node", "2Node"};

struct dataStruct {
  double latitude;
  double longitude;
} gpsData;


void setup() {
  Serial.begin(115200);
  ss.begin(9600);
  Serial.println("Setting up radio");
  //  Setup transmitter radio
  radio.begin();
  radio.openWritingPipe(0xF0F0F0F0E1LL);
  radio.setChannel(0x76);
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate(RF24_2MBPS);
  radio.stopListening();
  radio.enableDynamicPayloads();
  radio.powerUp();
  Serial.println("Starting to send");
}
void loop() {
  while (ss.available() > 0) {
    if (gps.encode(ss.read())) {
      if (gps.location.isValid()) {
        gpsData.longitude = gps.location.lng();
        gpsData.latitude = gps.location.lat();
      }
      else {
        gpsData.longitude = 0.0;
        gpsData.latitude = 0.0;
      }
      radio.write(&gpsData, sizeof(gpsData));
    }
  }
}

Send the struct...

Felix, lowpowerlab.com : I added struct examples in the RFM69 repository, so here are sender and receiver examples that are ready to go (just edit your frequency, nodeid, network id etc):
.
https://github.com/LowPowerLab/RFM69/blob/master/Examples/Struct_send/Struct_send.ino
https://github.com/LowPowerLab/RFM69/blob/master/Examples/Struct_receive/Struct_receive.ino
My payloads are (const void*) so you have to cast them back and forth a little different:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.