Getting GPS coordinations while sending data with nrf24l01

I'm having a problem getting GPS coordinations while sending them using nrf24l01 to another Arduino. The wireless communication works fine, but I can't get a GPS fix. When I don't send any data (I comment this part of code radio.write(&char_array, sizeof(char_array));) I can get the GPS coords in a few seconds, but not when using the nrf24l01 module.

This is my code:

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

//create an RF24 object
RF24 radio(9, 8);  // CE, CSN
//address through which two modules communicate.
const byte address[6] = "00001";
int gpsRXPin = 3;
int gpsTXPin = 2;
int GPSBaud = 9600;


float gps_lat = 0;
float gps_lng = 0;
float gps_sat = 0;
const int radiorepeat = 1000;
unsigned long startTime;


TinyGPSPlus gps;
SoftwareSerial gpsSerial(gpsRXPin, gpsTXPin);

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

  startTime = millis();

  //2,4GHz radio
  radio.begin();
  radio.openWritingPipe(address);
 // radio.setRetries(3,5); // delay, count
  radio.stopListening();   
}

//sent gps coords over 2.4GHz
void radiosent(String output_message){

  //convert string to char array
  int str_len = output_message.length() + 1; 
  char char_array[str_len];
  output_message.toCharArray(char_array, str_len);


  radio.write(&char_array, sizeof(char_array));
}

void consolelog(){
  Serial.println("--------------");
  Serial.print("GPS: ");
  Serial.print("Lat=");
  Serial.print(gps_lat);
  Serial.print(" lng=");
  Serial.print(gps_lng);
  Serial.print(" sat=");
  Serial.println(gps_sat);
}

void loop() {
   while (gpsSerial.available() > 0){
      gps.encode(gpsSerial.read());
      if (gps.location.isUpdated()){
        gps_lat = gps.location.lat();
        gps_lng = gps.location.lng();
        gps_sat = gps.satellites.value();
      }  
  }

  //prepare string to send over 2.4Ghz (SY1-gps_lat-gps_lng)
  String output_message = "SY1-";
  output_message = output_message + String(gps_lat, 6);
  output_message = output_message + "-";
  output_message = output_message + String(gps_lng, 6);

  //runs every second
  if(millis() > startTime + radiorepeat){
    consolelog();
    radiosent(output_message);
    startTime = millis();
  }
}

Is the problem in the communication between the Arduino and the GPS module or is the GPS reception bad while the nRF24 is active?

A nearby transmitter will overload the input of a receiver, even if the frequency bands are very different.

Collect GPS coordinates, then turn on the NRF24 and transmit.

Please post your receive code.

That is not the right way to use millis().
Any variables that are used for timing should be declared unsigned long.

Non-blocking timing tutorials:
Blink without delay().
Blink without delay detailed explanation
Beginner's guide to millis().
Several things at a time.

When the nRF24 is not active, the GPS module works great. The problem is while using both of them at the same time.

You can't.

That doesn't answer my question. Are the problems you see in the communication between the Arduino and the GPS or does the GPS send the data correctly to the Arduino but doesn't get valid data from the satellites?

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