Can't transmit a GPS data to another module

Hello everyone,

Last week I tried to get data from GPS module to my Arduino UNO, it works, then I’ve sought to transmit it to another receiver module, but this time it didn’t work.
I thought the problem come from my transmitter code then I checked my code (tried to send constant value) it still work well, the receiver alway display a value

Can you guys please help me to fix this problem, I searched and tried many ways, but it couldn’t help ( mostly not relate to my issue)

GPS
Vcc - 5v
Gnd - Gnd
Rx - 0
Tx - 10

nRF24L01p
Vcc- 3.3V
Gnd - Gnd
CSN - 7
CE - 8
MOSI - 11
SCK - 13
MISO - 12

This is my code

#include <TinyGPS++.h>
#include "SoftwareSerial.h"
#include <SPI.h>
#include <nRF24L01p.h>

SoftwareSerial GPSModule( 10, 0); // TX, RX
TinyGPSPlus gps;
nRF24L01p transmitter(7, 8); //CSN,CE

int updates;
int failedUpdates;
int pos;
int stringplace = 0;
String nmea[15];
String labels[15] {"Time: ", "Latitude: ", "N/S: ", "Longitude: ", "E/W : ", "GPS quality indicator : ", "# of sat. : ", "Horizontal dilution : ", "altitude  : ", "", "WGS84 :", "", "", "diff. ref station ID: "};

String timeUp;

void setup() {

  Serial.begin(9600);
  GPSModule.begin(9600);

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  transmitter.channel(90);
  transmitter.TXaddress("ALL"); 
  transmitter.init();

}

void loop() {
  Serial.flush();
  GPSModule.flush();
  while (GPSModule.available() > 0) {
    GPSModule.read();
  }
  if (GPSModule.find("GPGGA,")) {
    String tempMsg = GPSModule.readStringUntil('\n');
    for (int i = 0; i < tempMsg.length(); i++) {
      if (tempMsg.substring(i, i + 1) == ",") {
        nmea[pos] = tempMsg.substring(stringplace, i);
        stringplace = i + 1;
        pos++;
      }
      if (i == tempMsg.length() - 1) {
        nmea[pos] = tempMsg.substring(stringplace, i);
      }
    }
    updates++;

    nmea[1] = ConvertLat();
    nmea[3] = ConvertLng();
    
    Serial.print(nmea[1]);
    Serial.print(",");
    Serial.print(nmea[3]);
    Serial.print(",");
    Serial.print(nmea[8]);
    Serial.println("");

    transmitter.txPL(nmea[1]+", "+nmea[3]+", "+nmea[8]); 
    transmitter.send(FAST); 
    
  }
  else {
    failedUpdates++;
  }
  stringplace = 0;
  pos = 0;

}



/////////////////////////////////////////////////////////
//                                                               //
//                                                               //
//                                                               //
// method to convert Latitude/Longitude value    //
//                                                               //
//                                                               //  
//                                                               //
/////////////////////////////////////////////////////////

String ConvertLat() {
  String posneg = "";
  if (nmea[1] == "S") {
    posneg = "-";
  }
  String latfirst;
  float latsecond;
  for (int i = 0; i < nmea[1].length(); i++) {
    if (nmea[1].substring(i, i + 1) == ".") {
      latfirst = nmea[1].substring(0, i - 2);
      latsecond = nmea[1].substring(i - 2).toFloat();
    }
  }
  latsecond = latsecond / 60;
  String CalcLat = "";

  char charVal[9];
  dtostrf(latsecond, 4, 6, charVal);
  for (int i = 0; i < sizeof(charVal); i++)
  {
    CalcLat += charVal[i];
  }
  latfirst += CalcLat.substring(1);
  latfirst = posneg += latfirst;
  return latfirst;
}

String ConvertLng() {
  String posneg = "";
  if (nmea[3] == "W") {
    posneg = "-";
  }

  String lngfirst;
  float lngsecond;
  for (int i = 0; i < nmea[3].length(); i++) {
    if (nmea[3].substring(i, i + 1) == ".") {
      lngfirst = nmea[3].substring(0, i - 2);
      //Serial.println(lngfirst);
      lngsecond = nmea[3].substring(i - 2).toFloat();
      //Serial.println(lngsecond);

    }
  }
  lngsecond = lngsecond / 60;
  String CalcLng = "";
  char charVal[9];
  dtostrf(lngsecond, 4, 6, charVal);
  for (int i = 0; i < sizeof(charVal); i++)
  {
    CalcLng += charVal[i];
  }
  lngfirst += CalcLng.substring(1);
  lngfirst = posneg += lngfirst;
  return lngfirst;
}

Once I tried to move this from void setup() to the top of transmitter.txPL and end if-condition with SPI.end()

 SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  transmitter.channel(90); // ตั้งช่องความถี่ให้ตรงกัน
  transmitter.TXaddress("ALL"); // ตั้งชื่อตำแหน่งให้ตรงกัน ชื่อตั้งได้สูงสุด 5 ตัวอักษร
  transmitter.init();

It performed a value only one time then nothing happen.

This is my first Arduino project. I hope someone can help me fix this issue.
I apologize if my English is not well.

Thank you.

I don't know what nRF24 library you are using - it is not the TMRh20 version that I use. Have a look at this Simple nRF24L01+ Tutorial

...R

I don’t know what nRF24 library you are using

Me either. The library might be really old, because the new versions include support for the P variant.

You’re not getting GPS data properly. Here’s a NeoGPS version of your sketch:

#include <NMEAGPS.h>
#include <SPI.h>
#include <nRF24L01p.h>

NMEAGPS gps;
nRF24L01p transmitter(7, 8); //CSN,CE


void setup()
{
  Serial.begin(9600);

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);

  transmitter.channel(90);
  transmitter.TXaddress("ALL"); 
  transmitter.init();
}

void loop()
{
  if (gps.available( Serial )) { // parse received characters

    gps_fix fix = gps.read();    // get the new fix structure

    //  Format some of the fix pieces into a char array

    char  message[ 32 ];         // storage for formatted text message
    char *ptr = &message[0];     // start putting chars at the beginning

    dtostrf( fix.latitude(), 1, 6, ptr );   // write the floating-point latitude into the array
    ptr += strlen(ptr);          // step to end of latitude characters
    
    *ptr++ += ',';               // append a comma
    
    dtostrf( fix.longitude(), 1, 6, ptr );
    ptr += strlen(ptr);
    
    *ptr++ += ',';

    itoa( fix.satellites, ptr, 10 ); // append the satellite count

    //  Message is ready
    Serial.println( message );  // see what we are sending

    transmitter.txPL( message ); // send the message
    transmitter.send(FAST); 
  }
}

If you really have the GPS TX connected to Arduino pin 0 (RX), you shouldn’t start a software serial port on that pin. You can just read characters from Serial. And you will have to disconnect the GPS if you want to upload a new sketch over USB.

If you need to send any configuration commands to the GPS device (you aren’t so far), you could hook the GPS RX pin to the Arduino TX pin (1). Make sure this is a 5V GPS device, though… you might need to level-shift the 5V Arduino TX pin to a 3.3V GPS RX pin. You could damage the GPS device with a direct connection. (You don’t need a software serial port for this, either.)

Notice that the NeoGPS sketch does not use the String class, it just uses a character array for the message. Using the String class can cause memory problems, and it uses more program space.

If you want to try it, NeoGPS is available from the Arduino IDE Library Manager, under the menu Sketch → Include Library → Manage Libraries.

Cheers,
/dev

Hi Robin2 and /dev Thank you for your reply,

I've tried to connect GPS's TX to pin 0 and RX to pin 1 and now it works.

However, I still got these errors every time I uploaded it but it doesn't matter because the program still performed an output properly.

aavrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
An error occurred while uploading the sketch

Anyway, These errors disappeared when I uploaded without connecting TX and RX to Arduino board (still work if I reconnect)

Philip_L: Anyway, These errors disappeared when I uploaded without connecting TX and RX to Arduino board (still work if I reconnect)

That is because the Pins 0 and 1 are used when uploading a program - they are part of the system for talking to the PC over the USB cable.

If you want to use the GPS without needing to disconnect it then use SoftwareSerial to allow you to connect the GPS to a pair of different pins.

...R

Philip_L: These errors disappeared when I uploaded without connecting TX and RX to Arduino board (still work if I reconnect)

Yes, that's why I said

/dev Reply #2: And you will have to disconnect the GPS if you want to upload a new sketch over USB.

Using Serial is the most efficient and reliable way to get the GPS data. It is inconvenient to disconnect the GPS TX pin from the Arduino RX pin, though. If you want to move the GPS device to two other pins and use a software serial port, there are a few choices: AltSoftSerial, NeoSWSerial and SoftwareSerial.

I would not recommend using SoftwareSerial. It is very inefficient, because it disables interrupts for long periods of time. This can interfere with other parts of your sketch.

The absolute best alternative to using Serial is the AltSoftSerial library. You must connect the GPS TX to Arduino pin 8 and the GPS RX to Arduino pin 9 (on an UNO).

Because the GPS device is running at 9600, you could also use my NeoSWSerial on any two pins. It is almost as efficient as AltSoftSerial, and much, much better than SoftwareSerial.

Cheers, /dev