Radio module messing with GPS module? Stuck and can't get data

Hey folks, so I have a GPS module (NEO-6M) and a radio module (NRF24L01) on an Arduino Nano to send GPS coordinates to another Nano with another radio module. If I run a basic program that output the Latitude and Longitude I get that data quickly (at least locally to that first Arduino using the Serial monitor). I can also run a program just using the radio and it works at sending. Both tests were with having both modules wired up at the same time, but not initializing the one not being used.

However when I run a program that uses both, the program gets stuck at

if (gps.location.isUpdated()){

either for a VERY long time, or indefinitely. If I then upload the simple GPS program it immediately gives me accurate GPS data. Can anyone tell me what I am doing wrong with my code, or if these modules just don't play nice together? I admit I stapled 2 codes together and just hoped they would play nice.

I am using these 2 tutorials, where their programs worked standalone:

https://www.circuitbasics.com/wireless-communication-between-two-arduinos/

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Adafruit_BMP280.h>
RF24 nrf(9, 8);  // CE, CSN
Adafruit_BMP280 bmp; 

static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
const byte linkAddress[6] = "link1";
const int BMP_address = 0x76;

TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);

float data[2];
float Lat; //current coordinates
float Lng;
float Alt;

void setup(){
  Serial.begin(9600);
  ss.begin(GPSBaud);
  nrf.begin();   
  bmp.begin(BMP_address); 
  nrf.openWritingPipe(linkAddress);  //set the address 
  nrf.setPALevel(RF24_PA_HIGH); 
  nrf.stopListening();  //act as a transmitter
  Serial.println("Starting......");
}

void loop(){
  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
      Serial.println("Got it!");   //Serial monitor check
      data[0]=(gps.location.lat()*1000000); //this is for math on the other side
      data[1]=(gps.location.lng()*1000000); 
      
      Serial.print("Lat: ");Serial.println(data[0]);
      Serial.print("Lng: ");Serial.println(data[1]);
      Serial.println("-----------------------");
      nrf.write(data, sizeof(data)); //spit out the data array
    }
  }
}
1 Like

Hello

Post a schematic of your project.

2 Likes

Well done testing, verifying one device at the time! Hat off!
Know that all kinds of transmitters use lots of current transmitting. In general, be prepared for some 3 Amps at least.
As @paulpaulson requests, schematics showing the entire powering.

3 Likes

If you set the Serial port to 115200 baud you can print the characters read from the GPS and passed to encode, with minimal impact this might give you a clue as to what is going on;

Try this change to your code;

void loop(){
char GPSchar;
  while (ss.available() > 0){
  GPSchar = ss.read();
  gps.encode(GPSchar);
  Serial.write(GPSchar);
  if (gps.location.isUpdated()){

A nearby radio transmitter can easily overwhelm the input of a radio receiver, even if the transmit and receive frequency bands are quite different.

Don't transmit while trying to receive GPS data, and see if that improves the situation.

1 Like

I will experiment, but do you know what code I need to toggle around to turn on/off the radio transmit? My clunky initial thought is to turn it into a receiver and then back to a transmitter when passing data out. hoping for a couple line solution.

For others asking for schematic; I will do that when I have the chance, it is a lot of wires going to the arduino so need to draw in a non-confusing way. I didn't change the wiring at although from the linked guides I was following. Tried using both Vin and 5V pins, no change.

I will try that next chance I get! I might not have any clue what it all means but I will take a look.

My former electronic assembly service had a similar problem with the marine GPS receivers we built. The customer reported the GPS receiver on a batch of boards we built were not working properly. They finally traced the problem to a spurious signal coming from a crystal oscillator in the receiver. Only devices from a single batch of crystals had the problem.
We returned all of that batch to the distributor and they sent another batch number which worked fine.
I am writing this to show you how sensitive GPS receivers are to stray signals! Add shielding to your GPS receiver, except for the antenna and see if that solves your problem.

Did you try just commenting out the actual transmitting, leaving everything else cooking?

//      nrf.write(data, sizeof(data)); //spit out the data array

a7

Seems my issues were more so due to my location. I had been getting good GPS data with an obstructed sky view, but once I had the radio transmitter running it was causing enough interference that the GPS unit was unable to get a solid signal. Once I went out from my normal build/test area, and kept the two modules as far from each other as possible, it worked! The GPS unit still takes about 30 seconds to establish a link, but that just seems to be the nature of this product.

Now to work on longer range transmit/receive, as I am making a "go find it" box.

Thats close to normal for a GPS cold fix that is outside with a good view of the sky.

Use LoRa.

My initial looks at LoRa made it seem really involved, with registration and a bunch of other stuff. Am I just not understanding it and it's plug-and-play like the nRF24L01 module I am using now? This is a standalone, battery powered device where I don't want to have to plug into a computer or the like during operation.

It is if you use (for example) an Adafruit Feather LoRa module with their libraries.

2 Likes

Look again.

LoRa devices are easy to configure, lower power and have many many times the range of NRF24L01.

There is no 'registration' with point to point LoRa devices, maybe your getting confused with LoRaWAN, which is quite a bit more difficult to setup.

Yup, that's what I was seeing, thanks.

Hi, @magic_smoke1

Google;

lora arduino peer to peer

Tom... :grinning: :+1: :coffee: :australia:

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