Neo6mV2 + Nrf24l01 Gps data transmitting problem

Hi guys, I am trying to send some sensor data with a gps longtitude&latitude info. I can send the sensor’s data but when I try to add GPS data, It sends only “1” time then serial monitor and program freeze. I’m using 2 arduino nanos + 2 nrf24l01 here are the codes and the screenshot where it is freezes.(Sorry for bad English pls help)

Transmitter:

#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <DHT11.h>
#include <Wire.h>
#include <SFE_BMP180.h>
#include <HMC5983.h>
HMC5983 compass;
int pin = 5;
DHT11 dht11(pin);
SFE_BMP180 pressure;
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);


#define ALTITUDE 33.5 // Altitude of SparkFun's HQ in Boulder, CO. in meters

char hata[1];

RF24 radio(7,8);
byte addresses[][6] = {"1Node", "2Node"};

unsigned long simdiki_zaman;
boolean sureasimi;
unsigned long cevap_beklemeye_basla;

struct dataStruct {
  unsigned long zaman; 
  int humi;          
  int basinc;
  int sicak ;    
  int yuksek;      
  int yon;
  float enlem;
  float boylam;
  int uydu;
  int kalite;
  int hiz;
  
} telemetri;                


void setup(void){
 Serial.begin(9600);
  compass.begin();
  pressure.begin();
  ss.begin(GPSBaud);
 radio.begin();
 radio.setChannel(107); //cogu wifi frenkansinin ustunde 2.508GHz
 radio.setDataRate(RF24_250KBPS); 
 radio.openWritingPipe(addresses[0]);
 radio.openReadingPipe(1, addresses[1]);
 radio.setPALevel(RF24_PA_MIN);
 radio.startListening();
 
 }

void loop(void){

 
radio.stopListening();

   // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
}

void displayInfo()

{

  Serial.print(F("Location: ")); 
  if (gps.location.isValid())
  {

    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
 
    float gpslat = gps.location.lat();
    float gpslong = gps.location.lng();

    
int    uydu = gps.satellites.value();
int    kalite =gps.hdop.value();
int    hiz = gps.speed.kmph();

delay(200); //DELAAAAAY

float c = -999;
  c = compass.read();

 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   char status;
  double T,P,p0,a;



  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);



    status = pressure.getTemperature(T);
    if (status != 0)
    {

      status = pressure.startPressure(3);
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);



        status = pressure.getPressure(P,T);
        if (status != 0)
        {


          p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)


          a = pressure.altitude(P,p0);

        }
        else Serial.println("error retrieving pressure measurement\n");
      }
      else Serial.println("error starting pressure measurement\n");
    }
    else Serial.println("error retrieving temperature measurement\n");
  }
  else Serial.println("error starting temperature measurement\n");

  delay(100);  // Pause for 5 seconds.

  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 float sicaklik, nem, yon;

 
 
//dht11.read(nem, sicaklik);
       
    
 telemetri.sicak = T;
 telemetri.humi = nem;
 telemetri.basinc = P;
 telemetri.yuksek = a;
 telemetri.yon = c;
 telemetri.enlem =gpslat;
 telemetri.boylam = gpslong;
 telemetri.uydu = uydu;
 telemetri.kalite = kalite;
 telemetri.hiz = hiz;
 
delay(200); //DELAAAAAY
 
 telemetri.zaman = micros();
 Serial.print(F("Simdi Gonderliyor - "));


 
 if (!radio.write( &telemetri , sizeof(telemetri))){
 Serial.println(F("Gonderi Basarisiz."));
  
 }
 
 radio.startListening();
 cevap_beklemeye_basla = micros();               
 sureasimi = false;                            
radio.available();
//  while ( ! radio.available() ) {                            
//    if (micros() - cevap_beklemeye_basla > 200000 ) {           
//      sureasimi = true;
//      break;
//    }
//  }
//
//  if ( sureasimi )
//  { 
//    Serial.println(F("Cevap sure asimi"));
//
//    }
//  
//  else
//  {
    // Grab the response, compare, and send to Serial Monitor
    radio.read( &telemetri, sizeof(telemetri) ); // alicidan gelen veri okundu
    simdiki_zaman = micros();          // verinin okundugu an
    
    Serial.print(F("Cevap Gonderildi "));
    Serial.print(telemetri.zaman);          // verinin alicidan gonderilis zamani
    Serial.print(F(", Cevap alindi "));
    Serial.print(simdiki_zaman);       // verinin okundugu an     
    Serial.print(F(", Gidis-gelis Gecikmesi "));
    Serial.print(simdiki_zaman - telemetri.zaman);
    Serial.println(F(" mikrosaniye "));
//  }


 Serial.print(F("    Sicaklik(C) =  "));
 Serial.print(telemetri.sicak);
 delay(10);
 Serial.print(F("    Nem(%) =  "));
 Serial.print(telemetri.humi);
 delay(10);
 Serial.print(F("    Basinc(mb) =  "));
 Serial.println(telemetri.basinc);
 Serial.print(F("    Yukseklik =  "));
 Serial.println(telemetri.yuksek);
 Serial.print(F("    Magnetometre(YON) =  "));
 Serial.println(telemetri.yon);
 Serial.print(F("    ENLEM =  "));
 Serial.println(telemetri.enlem);
 Serial.print(F("    BOYLAM =  "));
 Serial.println(telemetri.boylam); 
  Serial.print(F("    Uydu Sayisi =  "));
 Serial.println(telemetri.uydu); 
  Serial.print(F("    HDOP =  "));
 Serial.println(telemetri.uydu); 
  Serial.print(F("    HIZ (KM/S) =  "));
 Serial.println(telemetri.hiz); 
 delay(100);
 
 Serial.end();
  Serial.begin(9600);
  
  }




  Serial.println();

 

 }

Receiver:

#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>



RF24 radio(7,8);


byte addresses[][6] = {"1Node", "2Node"};

int humi_gelen;
int humi_pozisyon;
int basinc_gelen;
int basinc_pozisyon;
int sicak_gelen;
int sicak_pozisyon;
int yuksek_gelen;
int yon_gelen;
float enlem_gelen;
float boylam_gelen;

struct dataStruct {
  unsigned long zaman; 
  int humi;          
  int basinc;
  int sicak;    
  int yuksek;      
  int yon;
  float enlem;
  float boylam;
} telemetri;                


void setup(void){
 Serial.begin(9600);
 
 
 radio.begin();
 radio.setChannel(107);  
 radio.setDataRate(RF24_250KBPS); 
 
 radio.openWritingPipe(addresses[1]);
 radio.openReadingPipe(1, addresses[0]);

 radio.startListening();
 
}
 
void loop(){
 if (radio.available())
 {
      while (radio.available())   
    {
      radio.read( &telemetri, sizeof(telemetri) );            
    }

    radio.stopListening();                               
    radio.write( &telemetri, sizeof(telemetri) );              
    radio.startListening();                              

    Serial.print(F("Veri alindi - Cevap gonderildi "));  
    Serial.println(telemetri.zaman);
     
 }
 
 
   humi_gelen = telemetri.humi;
   basinc_gelen = telemetri.basinc;
   sicak_gelen = telemetri.sicak;
   yuksek_gelen = telemetri.yuksek;
   yon_gelen = telemetri.yon;
   enlem_gelen = telemetri.enlem;
   boylam_gelen = telemetri.boylam;
   
 

 Serial.print(F("    Sicaklik(C) =  "));
 Serial.println(sicak_gelen);
 Serial.print(F("    Nem(%) =  "));
 Serial.println(humi_gelen);
 Serial.print(F("    Mutlak Basinc (mb, inHg) =  "));
 Serial.print(basinc_gelen);
 Serial.print(F(",  "));
 Serial.println(basinc_gelen*0.0295333727,2);
 Serial.print(F("    Yukseklik(m) =  "));
 Serial.println(yuksek_gelen); 
 Serial.print(F("    MagnetoMetre(YON) =  "));
 Serial.println(yon_gelen); 
  Serial.print(F("    ENLEM =  "));
 Serial.println(enlem_gelen, 6); 
  Serial.print(F("    BOYLAM  =  "));
 Serial.println(boylam_gelen, 6); 
 delay(400);
 
 }

Serial monitor:

Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 40.994754,28.868373Simdi Gonderliyor - Gonderi Basarisiz.
Cevap Gonderildi 0, Cevap alindi 23162812, Gidis-gelis Gecikmesi 23162812 mikrosaniye 
    Sicaklik(C) =  0    Nem(%) =  0    Basinc(mb) =  0
    Yukseklik =  0
    Magnetometre(YON) =  0
    ENLEM =  0.00
    BOYLAM =  0.00
    Uydu Sayisi =  0
    HDOP =  0
    HIZ (KM/S) =  0

Location: 40.994754,28.868373Simdi Gonderliyor -

You need to have identical structs for the sender and the receiver.

If that does not solve the problem go back to a very simple pair of programs that does nothing but transmit and receive data - leave out everything else. Get the simple program working and then add back the other stuff piece by piece testing at every stage.

...R
Simple nRF24L01+ Tutorial

* Indent your code. Press control-T in the IDE editor to auto-format your code.

* Don’t use delay. You will lose GPS data.

* Link to the libraries you are using. There are many versions of DHT11 and RF24.

* Don’t include <printf.h>.

* Don’t do this:

    float c = -999;
    c = compass.read();

Just do this:

    float c = compass.read();

* Put the GPS on pins 8 & 9 and use AltSoftSerial instead of SoftwareSerial, or use NeoSWSerial on any two pins.

* Look at the NeoGPS Troubleshooting page to understand why you shouldn’t use delay or print too much.

I have attached a version of your sketch, modified to use NeoGPS and NeoSWSerial. If you want to try it, NeoGPS and NeoSWSerial are available from the Arduino IDE Library Manager, under the menu Sketch → Include Library → Manage Libraries. It saves about 150 bytes of RAM.

Cheers,
/dev

ugurbocu.ino (5.62 KB)

As I said before, code works perfectly until I add gps data, all the other sensors were fine and communication was established. Now, I listen both of you guys and simplified the code, now I am just trying to send GPS data but still problem in the very same! place.
here it is:

transmitter:

#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <DHT11.h>
#include <Wire.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);


char hata[1];

RF24 radio(7, 8);
byte addresses[][6] = {"1Node", "2Node"};

unsigned long simdiki_zaman;
boolean sureasimi;
unsigned long cevap_beklemeye_basla;

struct dataStruct {
  unsigned long zaman;
 int enlem;
 int boylam;


} telemetri;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);


  ss.begin(GPSBaud);
  radio.begin();
  radio.setChannel(107); //cogu wifi frenkansinin ustunde 2.508GHz
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(addresses[0]);
  radio.openReadingPipe(1, addresses[1]);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}

void loop() {

  radio.stopListening();

  int gpslat = gps.location.lat();
  int gpslong = gps.location.lng();

  telemetri.enlem = gpslat;
  telemetri.boylam = gpslong;


  telemetri.zaman = micros();
  Serial.print(F("Simdi Gonderliyor - "));



  if (!radio.write( &telemetri , sizeof(telemetri))) {
    Serial.println(F("Gonderi Basarisiz."));

  }

  radio.startListening();
  cevap_beklemeye_basla = micros();
  sureasimi = false;
  radio.available();

  while ( ! radio.available() ) {
    if (micros() - cevap_beklemeye_basla > 200000 ) {
      sureasimi = true;
      break;
    }
  }

  if ( sureasimi )
  {
    Serial.println(F("Cevap sure asimi"));

  }

  else
  {
    // Grab the response, compare, and send to Serial Monitor
    radio.read( &telemetri, sizeof(telemetri) ); // alicidan gelen veri okundu
    simdiki_zaman = micros();          // verinin okundugu an

    Serial.print(F("Cevap Gonderildi "));
    Serial.print(telemetri.zaman);          // verinin alicidan gonderilis zamani
    Serial.print(F(", Cevap alindi "));
    Serial.print(simdiki_zaman);       // verinin okundugu an
    Serial.print(F(", Gidis-gelis Gecikmesi "));
    Serial.print(simdiki_zaman - telemetri.zaman);
    Serial.println(F(" mikrosaniye "));
  }


 
  Serial.print(F("    ENLEM =  "));
  Serial.println(telemetri.enlem);
  Serial.print(F("    BOYLAM =  "));
  Serial.println(telemetri.boylam);
  delay(100);



}

reciver:

#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>



RF24 radio(7,8);


byte addresses[][6] = {"1Node", "2Node"};


int enlem_gelen;
int boylam_gelen;

struct dataStruct {
  unsigned long zaman; 

  int enlem;
  int boylam;
} telemetri;                



void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
 
 
 radio.begin();
 radio.setChannel(107);  
 radio.setDataRate(RF24_250KBPS); 
 
 radio.openWritingPipe(addresses[1]);
 radio.openReadingPipe(1, addresses[0]);

 radio.startListening();
}

void loop() {
  // put your main code here, to run repeatedly:
 if (radio.available())
 {
      while (radio.available())   
    {
      radio.read( &telemetri, sizeof(telemetri) );            
    }

    radio.stopListening();                               
    radio.write( &telemetri, sizeof(telemetri) );              
    radio.startListening();                              

    Serial.print(F("Veri alindi - Cevap gonderildi "));  
    Serial.println(telemetri.zaman);
     
 }
 
 

   enlem_gelen = telemetri.enlem;
   boylam_gelen = telemetri.boylam;
   
 

  Serial.print(F("    ENLEM =  "));
 Serial.println(enlem_gelen); 
  Serial.print(F("    BOYLAM  =  "));
 Serial.println(boylam_gelen); 
 delay(400);
}

and Serial of the transmitter:

Simdi Gonderliyor - Cevap sure asimi
    ENLEM =  0
    BOYLAM =  0
Simdi Gonderliyor - Cevap Gonderildi 30716, Cevap alindi 341584, Gidis-gelis Gecikmesi 310868 mikrosaniye 
    ENLEM =  0
    BOYLAM =  0
Simdi Gonderliyor - Cevap Gonderildi 518380, Cevap alindi 678224, Gidis-gelis Gecikmesi 159844 mikrosaniye 
    ENLEM =  0
    BOYLAM =  0
Simdi Gonderliyor - Cevap sure asimi
    ENLEM =  0
    BOYLAM =  0
Simdi Gonderliyor - Cevap Gonderildi 841896, Cevap alindi 1159596, Gidis-gelis Gecikmesi 317700 mikrosaniye 
    ENLEM =  0
    BOYLAM =  0
Simdi Gonderliyor - Cevap Gonderildi 0, Cevap alindi 1464988, Gidis-gelis Gecikmesi 1464988 mikrosaniye 
    ENLEM =  0
    BOYLAM =  0
Simdi Gonderliyor - Cevap Gonderildi 1338476, Cevap alindi 1624144, Gidis-gelis Gecikmesi 285668 mikrosaniye 
    ENLEM =  0
    BOYLAM =  0
Simdi Gonderliyor -

-dev:
* Indent your code. Press control-T in the IDE editor to auto-format your code.

* Don’t use delay. You will lose GPS data.

* Link to the libraries you are using. There are many versions of DHT11 and RF24.

* Don’t include <printf.h>.

* Don’t do this:

    float c = -999;

c = compass.read();



Just do this:



float c = compass.read();



__*__ Put the GPS on pins 8 & 9 and use AltSoftSerial instead of SoftwareSerial, or use [NeoSWSerial](https://github.com/SlashDevin/NeoSWSerial) on any two pins.

__*__ Look at the [NeoGPS](https://github.com/SlashDevin/NeoGPS) Troubleshooting page to understand why you shouldn't use `delay` or print too much.

I have attached a version of your sketch, modified to use NeoGPS and NeoSWSerial. If you want to try it, NeoGPS and NeoSWSerial are available from the Arduino IDE Library Manager, under the menu **Sketch -> Include Library -> Manage Libraries**. It saves about 150 bytes of RAM.

Cheers,
/dev

-dev, first of all I want to thank you for your concern, and for the first time it sent 2 or 3 times data, I thought it was done but again, it got stucked at the same place:

Location: 
Location: 
Location: 
Location: 
Location: 
Location: 
Location: 40.994422,28.868230,,,0.40
Simdi Gonderliyor - Cevap Gonderildi 0, Cevap alindi 54501792, Gidis-gelis Gecikmesi 54501792 mikrosaniye 
    Sicaklik(C) =  0    Nem(%) =  0    Basinc(mb) =  0
    Yukseklik =  0
    Magnetometre(YON) =  0
    ENLEM =  0.00
    BOYLAM =  0.00
    Uydu Sayisi =  0
    HDOP =  0
    HIZ (KM/S) =  0

Location: 40.994422,28.868225,,,0.80
Simdi Gonderliyor - Cevap Gonderildi 0, Cevap alindi 55504968, Gidis-gelis Gecikmesi 55504968 mikrosaniye 
    Sicaklik(C) =  0    Nem(%) =  0    Basinc(mb) =  0
    Yukseklik =  0
    Magnetometre(YON) =  0
    ENLEM =  0.00
    BOYLAM =  0.00
    Uydu Sayisi =  0
    HDOP =  0
    HIZ (KM/S) =  0

Location: 40.994422,28.868217,,,0.44
Simdi Gonderliyor -

ugurbocu:
it got stucked at the same place

Based on information in your other thread, this is almost certainly a power problem.

You should try NMEAorder.ino to make sure your LAST_SENTENCE is configured correctly. This would not cause it to freeze, though. I'm glad you figured out how to enable HDOP... I'm sorry I forgot to mention that. :confused:

-dev, I think this is a completely different problem because in this one there is a problem with no-antenna NRF but the other thread you mentioned, I deleted my gps code, only sensor data is transmitting and with little NRF there is no problem at all. So short story I don't think it is connected but very respect to your interest man thank you.

The last print before it freezes is "Simdi Gonderliyor - ". This is just before the radio.write. If adding code makes it freeze, it could be a memory corruption issue. Please provide links to the libraries you are using. I could not get your code to compile with the RF24 and DHT11 libraries I have.

The freeze can also be caused by poor I2C wiring. The I2C Wire library can freeze if it misses one of the bytes sent by a sensor. It could be the wrong resistor value or noise caused by the wires (too long?). Transmitting may cause enough noise to affect the I2C wires, either from interference or power supply issues.

Please show a schematic and picture of your modules. Many problems have been found quickly by looking at these two important items.

For example, did you level-shift the 5V Arduino signals to/from the 3.3V ublox device? Read more about it here.

Did you try NMEAorder.ino to check the config?

Try commenting out the radio code (setup, write and read). If the sensors and GPS work ok, then you know it has something to do with the radio.

Next try just doing radio setup and read (no transmit). If that works ok, then you know it has something to do with radio transmitting.