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:
- with Uno board powered by usb.
- with Uno board powered by 9v battery.
- 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!