Using GPS (NeoGPS) on hardware serial (RX0 / TX0) on UNO

Hi everybody,

I'm working on a GPS + RF24 radio project. There will be 2 separate units transmitting data, one will be sending information (tag) and the other receiving (base). In the end, the base will receive the GPS coordinates from the tag, calculate the bearing and rotate a servo towards the tag.

The setup of the base unit is made by a generic (wavgat) arduino mega, RF2401 radio, NEO-7m gps and a sg90 servo all powered via usb cable.

The setup to the tag unit is (wavgat) arduino uno r3, RF2401 radio, NEO-7m gps all powered by usb or 9v battery (used to test disconnecting usb from pc).

The problem I'm facing is using the hardware serial (RX0 / TX0) on the uno. The code works well when using neoGPS and AltSofSerial, however, I'd like to use the code on hardware serial because it is faster (supposedly?!) and because the tag will be constantly moving and I'd like the base to follow with less lag.

Also, the tag unit needs to remain small as it will be carried around on my arm, hence the necessity to avoid using another mega board rather than the uno.

From the many many posts I read, it should be possible connect the gps unit to these pins (0/1).
Information supported by @-dev here

TESTS: I have tried the code below (using hardware serial) in many different ways:

  1. with Uno board powered by usb.
  2. with Uno board powered by 9v battery.
  3. switching the gps TX pin to connect on RX 0 or TX 1; in case the were mislabelled.

On all these tests above no GPS information was received by the base unit. I setup a constant value to test that the radios on both units were working and this value was successfully transmitted in all the tests.

Please, help me figure out what is wrong as I have already spent many many hours troubleshooting it and can't find what is wrong.

TAG unit code.

#include <SPI.h>
#include <Wire.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "Arduino.h"
#include "nRF24.h"
#include "GPS.h"

// Topology
byte addresses[][6] = {"1Node", "2Node"}; // Radio pipe addresses for the 2 nodes to communicate.

struct MyData {
  long lon ;
  long lat;
  int32_t altitude = 321; // to test that the radio is sending information.
};

MyData data;

RF24 radio(6, 7);


//#include <GPSport.h> // only using it to test gps on AltSoftSerial port
//#include <AltSoftSerial.h> // only using it to test gps on AltSoftSerial port
#include <NMEAGPS.h>


NMEAGPS  gps; // This parses the GPS characters
gps_fix  fix; // This holds on to the latest values

#define gpsPort Serial


void setup() {

  Serial.begin(9600);

  // Setup and configure radio
  radio.begin();
  radio.setAutoAck(false);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(addresses[1]);        // used for TX, different on RX
  radio.startListening();                       // Start listening
  radio.stopListening();
  radio.powerUp();
  radio.stopListening();

}
//===============================

void loop() {

  while (gps.available( gpsPort )) {
    fix = gps.read();

    data.lon = fix.longitudeL(); // transmitting only longtitude to test it.
    radio.write(&data, sizeof(MyData));
  }
  delay(20);
}
//===============================================

BASE unit code below:

#include <SPI.h>
#include <Wire.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>



// Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(8, 53); // CE, CSN

// Topology
byte addresses[][6] = {"1Node", "2Node"}; // Radio pipe addresses for the 2 nodes to communicate.


struct MyData {
  long lon;
  long lat;
  int32_t altitude;
};

MyData data;


/**************************************************/

void setup()
{

  Serial.begin(9600);

  // Setup and configure radio
  radio.begin();
  radio.setAutoAck(false);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(1, addresses[1]); // used for RX
  radio.startListening();                       // Start listening
  radio.powerUp();

}

/**************************************************/

void recvData()
{

  while ( radio.available() ) {
    radio.read(&data, sizeof(MyData));
    

    Serial.print( F("longitude: ") );
    Serial.println( data.lon );

    Serial.print( F("altitude:     ") );
    Serial.println( data.altitude );


  }
}

/**************************************************/

void loop()
{

  recvData();

}

Again, the hardcoded altitude data gets transferred but, the GPS does NOT.

Thanks for the help!

I'd like to use the code on hardware serial because it is faster (supposedly?!)

How frequently is the GPS data updated ?
In my experience it is every second, so does the Serial speed make any meaningful difference ?

If you're running the GPS at 9600 baud, I can't see any advantage to using the hardware serial port.

What is your test, to know that GPS data is received? It should be something much simpler than transmitting it over the radio. That is introducing too many factors.

UKHeliBob:
How frequently is the GPS data updated ?
In my experience it is every second, so does the Serial speed make any meaningful difference ?

That's the default configuration 1hz update, but I'm configuring the GPS to 10hz (10x second). So, it is quite a difference and it is important because I will be constantly moving and the base needs to track the tag quickly to avoid lag.

wildbill:
If you're running the GPS at 9600 baud, I can't see any advantage to using the hardware serial port.

Right. I will configure it to run at 115200 (not included in the code above).

aarg:
What is your test, to know that GPS data is received? It should be something much simpler than transmitting it over the radio. That is introducing too many factors.

To test that the GPS is working I used AltSoft Serial configuration and printed in to the IDE monitor.
When using this setup, the code is perfectly transmitted over the radio.

The GPS on the TAG unit is working when using other ports than the hardware serial.

I'm not sure I understand your question. How else would I test the GPS on the hardware serial?

Thanks

I'm a little confused as to why you seem to be including TWO RF24 libraries in the base station and THREE in the tag.

jonkis:
Also, the tag unit needs to remain small as it will be carried around on my arm, hence the necessity to avoid using another mega board rather than the uno.

There are plenty processor boards that are smaller than an Uno AND have extra hardware serial port(s) available for connection to the GPS. Here are two of them:
https://www.pjrc.com/store/teensy32.html